Add assistant_weather_tool example: Assistants API + Open-Meteo tool #2178
+0
−747,922
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🧠 Summary
Added a new example script assistant_weather_tool.py demonstrating how to build a GPT Assistant that can call an external weather API (Open-Meteo) using the Assistants API and function calling.
This recipe helps developers understand how to connect GPT models with real-world APIs through tool integration.
💡 Motivation
The OpenAI Cookbook currently has very few end-to-end examples showing Assistants API + function calling + external APIs.
This contribution makes it easier for developers to:
Define custom tools that call real APIs
Understand tool schema design and integration
Create assistants capable of retrieving live data
📁 Files Added
examples/assistants/assistant_weather_tool.py
✅ Checklist
Code runs successfully locally
Tested with valid OPENAI_API_KEY
Added detailed docstrings and comments
Follows repo style (black, isort)
Uses environment variables (no hardcoded keys)
Provides a practical, original learning example
📸 Example Output
Assistant created. assistant_id: asst_12345
Local tool demo (Open-Meteo):
Fetching weather for New York...
Tool result: {'location': 'New York, United States', 'temperature_c': 22.5, 'windspeed_kmh': 8.6, ...}
👤 Author
Name: Shankar Kumar
GitHub: @Shank312
Email: [email protected]