forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.ts
More file actions
39 lines (34 loc) · 1.09 KB
/
Copy pathmodel.ts
File metadata and controls
39 lines (34 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* This module provides a function to get a model based on the configuration.
*/
import { BaseChatModel } from "@langchain/core/language_models/chat_models";
import { AgentState } from "./state";
import { ChatOpenAI } from "@langchain/openai";
import { ChatAnthropic } from "@langchain/anthropic";
import { ChatGoogleGenerativeAI } from "@langchain/google-genai";
function getModel(state: AgentState): BaseChatModel {
/**
* Get a model based on the environment variable.
*/
const stateModel = state.model;
const model = process.env.MODEL || stateModel;
console.log(`Using model: ${model}`);
if (model === "openai") {
return new ChatOpenAI({ temperature: 0, model: "gpt-4o" });
}
if (model === "anthropic") {
return new ChatAnthropic({
temperature: 0,
modelName: "claude-3-5-sonnet-20240620",
});
}
if (model === "google_genai") {
return new ChatGoogleGenerativeAI({
temperature: 0,
model: "gemini-1.5-pro",
apiKey: process.env.GOOGLE_API_KEY || undefined,
});
}
throw new Error("Invalid model specified");
}
export { getModel };