-
Notifications
You must be signed in to change notification settings - Fork 11.5k
Add assistant_weather_tool example: Assistants API + Open-Meteo tool #2178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: shankark3121999@gmail.com