File tree 2 files changed +19
-6
lines changed 2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -38,13 +38,16 @@ async def analyze_and_route_query(
38
38
return {"router" : state .router }
39
39
40
40
configuration = AgentConfiguration .from_runnable_config (config )
41
- model = load_chat_model (configuration .query_model )
41
+ structured_output_kwargs = (
42
+ {"method" : "function_calling" } if "openai" in configuration .query_model else {}
43
+ )
44
+ model = load_chat_model (configuration .query_model ).with_structured_output (
45
+ Router , ** structured_output_kwargs
46
+ )
42
47
messages = [
43
48
{"role" : "system" , "content" : configuration .router_system_prompt }
44
49
] + state .messages
45
- response = cast (
46
- Router , await model .with_structured_output (Router ).ainvoke (messages )
47
- )
50
+ response = cast (Router , await model .ainvoke (messages ))
48
51
return {"router" : response }
49
52
50
53
@@ -140,7 +143,12 @@ class Plan(TypedDict):
140
143
steps : list [str ]
141
144
142
145
configuration = AgentConfiguration .from_runnable_config (config )
143
- model = load_chat_model (configuration .query_model ).with_structured_output (Plan )
146
+ structured_output_kwargs = (
147
+ {"method" : "function_calling" } if "openai" in configuration .query_model else {}
148
+ )
149
+ model = load_chat_model (configuration .query_model ).with_structured_output (
150
+ Plan , ** structured_output_kwargs
151
+ )
144
152
messages = [
145
153
{"role" : "system" , "content" : configuration .research_plan_system_prompt }
146
154
] + state .messages
Original file line number Diff line number Diff line change @@ -37,7 +37,12 @@ class Response(TypedDict):
37
37
queries : list [str ]
38
38
39
39
configuration = AgentConfiguration .from_runnable_config (config )
40
- model = load_chat_model (configuration .query_model ).with_structured_output (Response )
40
+ structured_output_kwargs = (
41
+ {"method" : "function_calling" } if "openai" in configuration .query_model else {}
42
+ )
43
+ model = load_chat_model (configuration .query_model ).with_structured_output (
44
+ Response , ** structured_output_kwargs
45
+ )
41
46
messages = [
42
47
{"role" : "system" , "content" : configuration .generate_queries_system_prompt },
43
48
{"role" : "human" , "content" : state .question },
You can’t perform that action at this time.
0 commit comments