फ़ंक्शन कॉल्स के साथ स्ट्रीमिंग
आप देख चुके हैं कि function-calling LLMs के साथ कितने उपयोगी केस खुल जाते हैं, और इनके अपने इवेंट टाइप होते हैं. जब मॉडल किसी टूल को कॉल करने की तैयारी कर रहा हो, तब उपयोगकर्ताओं को रियल-टाइम फ़ीडबैक देने या टूल उपयोग को ट्रैक करने के लिए लॉगिंग में यह काफ़ी काम आता है.
आपने पहले जो convert_timezone() फ़ंक्शन टाइमज़ोन के बीच डेटाटाइम बदलने के लिए परिभाषित किया था, और Responses API के लिए उस फ़ंक्शन की परिभाषा वाली tools लिस्ट—यह सब आपके लिए पहले से सेट है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
OpenAI Responses API के साथ काम करना
अभ्यास निर्देश
- streaming कॉन्टेक्स्ट मैनेजर को पूरा करें:
client.responses.create()कॉल करें और मॉडल"gpt-5.4-mini",prompt, औरtoolsलिस्ट पास करें. - लूप के अंदर,
"function_call_arguments.delta"इवेंट्स की जाँच करें. "function_call_arguments.done"इवेंट्स के लिए एक कंडीशन जोड़ें.- आख़िर में एक कंडीशन जोड़ें जो इवेंट टाइप
"response.completed"होने पर जाँच करे और एक अंतिम completion मैसेज प्रिंट करे.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
prompt = "What time is 2:30pm on January 20th in New York in Tokyo time?"
# Open the streaming connection and enable tool-calling
with ____ as stream:
for event in stream:
# Filter for function call arguments delta events
if ____:
print(f"\nTool args streaming: {event.delta}")
# Filter for function call arguments complete events
elif ____:
print("Tool call args complete.")
# Filter for response completed events
elif ____:
print("\n--- Completed ---")