@@ -27,26 +27,21 @@ def get_weather(latitude: float, longitude: float) -> str:
27
27
28
28
29
29
tools = [
30
- {
31
- "type" : "function" ,
32
- "name" : "get_weather" ,
33
- "description" :
34
- "Get current temperature for provided coordinates in celsius." ,
35
- "parameters" : {
36
- "type" : "object" ,
37
- "properties" : {
38
- "latitude" : {
39
- "type" : "number"
30
+ {
31
+ "type" : "function" ,
32
+ "name" : "get_weather" ,
33
+ "description" : "Get current temperature for provided coordinates in celsius." ,
34
+ "parameters" : {
35
+ "type" : "object" ,
36
+ "properties" : {
37
+ "latitude" : {"type" : "number" },
38
+ "longitude" : {"type" : "number" },
40
39
},
41
- "longitude" : {
42
- "type" : "number"
43
- }
40
+ "required" : ["latitude" , "longitude" ],
41
+ "additionalProperties" : False ,
44
42
},
45
- "required" : ["latitude" , "longitude" ],
46
- "additionalProperties" : False
47
- },
48
- "strict" : True
49
- }
43
+ "strict" : True ,
44
+ }
50
45
]
51
46
52
47
input_messages = [
@@ -59,14 +54,13 @@ def main():
59
54
model = "Qwen/Qwen3-1.7B"
60
55
client = OpenAI (base_url = base_url , api_key = "empty" )
61
56
response = client .responses .create (
62
- model = model , input = input_messages , tools = tools , tool_choice = "required"
57
+ model = model , input = input_messages , tools = tools , tool_choice = "required"
63
58
)
64
59
tool_call = response .output [0 ]
65
60
args = json .loads (tool_call .arguments )
66
-
61
+
67
62
result = get_weather (args ["latitude" ], args ["longitude" ])
68
-
69
-
63
+
70
64
input_messages .append (tool_call ) # append model's function call message
71
65
input_messages .append (
72
66
{ # append result message
@@ -76,9 +70,9 @@ def main():
76
70
}
77
71
)
78
72
response_2 = client .responses .create (
79
- model = model ,
80
- input = input_messages ,
81
- tools = tools ,
73
+ model = model ,
74
+ input = input_messages ,
75
+ tools = tools ,
82
76
)
83
77
print (response_2 .output_text )
84
78
0 commit comments