Skip to content

Commit

Permalink
Merge pull request #55 from dwhiffing/feature/ollama
Browse files Browse the repository at this point in the history
Feature/ollama
  • Loading branch information
mafzal91 authored Sep 13, 2024
2 parents ef0e4aa + 4fe170a commit cd57412
Show file tree
Hide file tree
Showing 9 changed files with 299 additions and 196 deletions.
17 changes: 6 additions & 11 deletions app/api/chat/route.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { NextRequest, NextResponse } from "next/server";
import { ChatOpenAI } from "@langchain/openai";

import { getToolsFromContracts } from "@/utils/generateToolFromABI";
import { CustomParser } from "@/utils/CustomParser";
import { contractCollection } from "@/utils/collections";
import { reasoningPrompt } from "@/utils/reasoningPrompt";
import { getStructuredPrompt } from "@/utils/prompts";
import { timestampLambda } from "@/utils/timestampLambda";
import { getTimestampLambda } from "@/utils/timestampLambda";
import { RunnableSequence } from "@langchain/core/runnables";
import { MODELS } from "@/constants";
import { getModel } from "@/utils/getModel";

export const runtime = "nodejs";

Expand Down Expand Up @@ -56,17 +55,13 @@ export async function POST(req: NextRequest) {
});

const tools = getToolsFromContracts(filteredContracts);

const model = new ChatOpenAI({
model: modelName,
temperature: 0,
streaming: true,
}).bindTools(tools);
const model = getModel(modelName);
const modelWithTool = model.bindTools(tools);

const stream = await RunnableSequence.from([
timestampLambda,
getTimestampLambda(modelName),
prompt,
model,
modelWithTool,
new CustomParser(),
]).stream({
contractAddresses: contractAddresses,
Expand Down
4 changes: 2 additions & 2 deletions components/ChatSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "@/components/ui/select";
import { Checkbox } from "./ui/checkbox";
import { MODELS } from "@/constants";
import { findModelKey } from "@/utils/utils";
import { findInferenceByModelName } from "@/utils/utils";

type IChatSettingProps = {
clearOnChange: boolean;
Expand All @@ -24,7 +24,7 @@ export function ChatSettings(props: IChatSettingProps) {
const { modelName, onModelNameChange, clearOnChange, onClearOnChange } =
props;
const [inferenceProvider, setInferenceProvider] = useState(() => {
return findModelKey(modelName);
return findInferenceByModelName(modelName);
});

const handleInferenceProviderChange = (value: keyof typeof MODELS) => {
Expand Down
Loading

0 comments on commit cd57412

Please sign in to comment.