forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
38 lines (33 loc) · 1.18 KB
/
Copy pathmodel.py
File metadata and controls
38 lines (33 loc) · 1.18 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
"""
This module provides a function to get a model based on the configuration.
"""
import os
from typing import cast, Any
from langchain_core.language_models.chat_models import BaseChatModel
from copilotkit.demos.research_canvas.state import AgentState
def get_model(state: AgentState) -> BaseChatModel:
"""
Get a model based on the environment variable.
"""
state_model = state.get("model")
model = os.getenv("MODEL", state_model)
print(f"Using model: {model}")
if model == "openai":
from langchain_openai import ChatOpenAI
return ChatOpenAI(temperature=0, model="gpt-4o-mini")
if model == "anthropic":
from langchain_anthropic import ChatAnthropic
return ChatAnthropic(
temperature=0,
model_name="claude-3-5-sonnet-20240620",
timeout=None,
stop=None
)
if model == "google_genai":
from langchain_google_genai import ChatGoogleGenerativeAI
return ChatGoogleGenerativeAI(
temperature=0,
model="gemini-1.5-pro",
api_key=cast(Any, os.getenv("GOOGLE_API_KEY")) or None
)
raise ValueError("Invalid model specified")