File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change 6
6
from datetime import datetime , timezone
7
7
from typing import Dict , List , Literal , cast
8
8
9
- from langchain .chat_models import init_chat_model
10
9
from langchain_core .messages import AIMessage
11
10
from langchain_core .prompts import ChatPromptTemplate
12
11
from langchain_core .runnables import RunnableConfig
16
15
from react_agent .configuration import Configuration
17
16
from react_agent .state import InputState , State
18
17
from react_agent .tools import TOOLS
18
+ from react_agent .utils import load_chat_model
19
19
20
20
# Define the function that calls the model
21
21
@@ -42,7 +42,7 @@ async def call_model(
42
42
)
43
43
44
44
# Initialize the model with tool binding. Change the model or add more tools here.
45
- model = init_chat_model (configuration .model_name ).bind_tools (TOOLS )
45
+ model = load_chat_model (configuration .model_name ).bind_tools (TOOLS )
46
46
47
47
# Prepare the input for the model, including the current system time
48
48
message_value = await prompt .ainvoke (
Original file line number Diff line number Diff line change 1
1
"""Utility & helper functions."""
2
2
3
+ from langchain .chat_models import init_chat_model
4
+ from langchain_core .language_models import BaseChatModel
3
5
from langchain_core .messages import BaseMessage
4
6
5
7
@@ -13,3 +15,13 @@ def get_message_text(msg: BaseMessage) -> str:
13
15
else :
14
16
txts = [c if isinstance (c , str ) else (c .get ("text" ) or "" ) for c in content ]
15
17
return "" .join (txts ).strip ()
18
+
19
+
20
+ def load_chat_model (fully_specified_name : str ) -> BaseChatModel :
21
+ """Load a chat model from a fully specified name.
22
+
23
+ Args:
24
+ fully_specified_name (str): String in the format 'provider/model'.
25
+ """
26
+ provider , model = fully_specified_name .split ("/" , maxsplit = 1 )
27
+ return init_chat_model (model , model_provider = provider )
You can’t perform that action at this time.
0 commit comments