99"""
1010
1111import os
12- from typing import Any , Dict , List
12+ from typing import List , cast
1313
1414from gradient import Gradient , ResponsesModels
15+ from gradient .types .responses import (
16+ ResponseInputFunctionCall ,
17+ ResponseInputFunctionCallOutput ,
18+ ResponseInputItem ,
19+ ResponseTool ,
20+ )
1521from gradient .types .responses .response_create_response import ResponseOutputFunctionCall
1622
1723
1824def _load_dotenv () -> None :
1925 try :
20- from dotenv import load_dotenv
26+ from dotenv import load_dotenv # type: ignore[reportMissingImports]
2127
2228 load_dotenv ()
2329 except ImportError :
@@ -33,7 +39,7 @@ def _load_dotenv() -> None:
3339client = Gradient (model_access_key = MODEL_ACCESS_KEY )
3440
3541# One function tool: get_weather
36- get_weather_tool = {
42+ get_weather_tool : ResponseTool = {
3743 "type" : "function" ,
3844 "function" : {
3945 "name" : "get_weather" ,
@@ -50,9 +56,10 @@ def _load_dotenv() -> None:
5056}
5157
5258# Initial conversation: single user message
53- input_messages : List [Dict [str , Any ]] = [
54- {"type" : "message" , "role" : "user" , "content" : "What's the weather in New York?" },
55- ]
59+ input_messages : List [ResponseInputItem ] = cast (
60+ List [ResponseInputItem ],
61+ [{"type" : "message" , "role" : "user" , "content" : "What's the weather in New York?" }],
62+ )
5663
5764# First call: model may return a function_call
5865response = client .responses .create (
@@ -65,18 +72,23 @@ def _load_dotenv() -> None:
6572# If the model returned a function call, append it and the tool result, then call again
6673for item in response .output :
6774 if isinstance (item , ResponseOutputFunctionCall ):
68- input_messages .append ({
69- "type" : "function_call" ,
70- "id" : item . id ,
71- " name" : item .name ,
72- "arguments" : item . arguments ,
73- } )
75+ input_messages .append (
76+ cast (
77+ ResponseInputFunctionCall ,
78+ { "type" : "function_call" , "id" : item . id , " name" : item .name , "arguments" : item . arguments } ,
79+ )
80+ )
7481 # Simulated tool result (in a real app you would call your function here)
75- input_messages .append ({
76- "type" : "function_call_output" ,
77- "call_id" : item .id ,
78- "output" : '{"temperature": 22, "unit": "celsius", "conditions": "sunny"}' ,
79- })
82+ input_messages .append (
83+ cast (
84+ ResponseInputFunctionCallOutput ,
85+ {
86+ "type" : "function_call_output" ,
87+ "call_id" : item .id ,
88+ "output" : '{"temperature": 22, "unit": "celsius", "conditions": "sunny"}' ,
89+ },
90+ )
91+ )
8092 response = client .responses .create (
8193 model = ResponsesModels .GPT_5_1_CODEX_MAX ,
8294 input = input_messages ,
0 commit comments