-
Notifications
You must be signed in to change notification settings - Fork 651
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
Update weather function API by using pyowm #334
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent code! The tests coverage is high enough. Leave some tiny suggestions.
Hi @yiyiyi0817. Sorry, I cannot see your updates. Did you push the changes? |
@dandansamax Sorry if my previous response was unclear. What I meant is that I will push my updates later. |
Hello@dandansamax, I have pushed my updates and would appreciate it if you could review them and consider merging them into the master branch. Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Please wait @lightaime to have a look.
Thanks @yiyiyi0817! It looks awesome. Some small comments:
|
Hi Guohao@lightaime, Thank you for your suggestion. I will convert the output to a string type and include the enhancement in role_playing_with_function.py to add "and get the current weather of the city where KAUST is located." I've separated the weather module into four distinct functions because the required units for temperature, wind, visibility distance, and sunrise/sunset are different, potentially leading to a function with numerous parameters. Moreover, there might be instances where the LLM would only need information on one of those aspects at a time, not all together. Hence, I'm contemplating whether combining them would indeed streamline the process or if it's more practical to maintain them as separate functions to cater to specific needs efficiently. I’m open to further discussion on this matter if needed. |
Hi @yiyiyi0817. Thanks for your explanation. It makes sense to separate them since the units. However, it will also increase the difficulty for function calling because more functions need to be considered in the function calling process. How about we introduce temp_units, wind_units, ... and combine them into a single function? WDYT? |
Given the convenience it brings to function calling, I agree with the proposal to merge these functions into one. I'll push the updated version soon. Thank you for the feedback! @lightaime |
Hi. Sorry to modify your code. But I added the |
Hello, I have submitted new code and look forward to your review and merging. @lightaime @dandansamax |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @yiyiyi0817. It looks great!! Just some last picky comments.
camel/functions/weather_functions.py
Outdated
raise ValueError("OPENWEATHERMAP_API_KEY not found in environment \ | ||
variables. Get OPENWEATHERMAP_API_KEY here: \ | ||
https://openweathermap.org/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raise ValueError("OPENWEATHERMAP_API_KEY not found in environment \ | |
variables. Get OPENWEATHERMAP_API_KEY here: \ | |
https://openweathermap.org/") | |
raise ValueError("`OPENWEATHERMAP_API_KEY` not found in environment \ | |
variables. Get `OPENWEATHERMAP_API_KEY` here: \ | |
`https://openweathermap.org`.") |
camel/functions/weather_functions.py
Outdated
""" | ||
Retrieve the OpenWeatherMap API key from environment variables. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually use r-string
for docstrings.
""" | |
Retrieve the OpenWeatherMap API key from environment variables. | |
r"""Retrieve the OpenWeatherMap API key from environment variables. |
camel/functions/weather_functions.py
Outdated
Raises: | ||
ValueError: If the API key is not found in the environment variables. | ||
""" | ||
# Get OPENWEATHERMAP_API_KEY here: https://openweathermap.org/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Get OPENWEATHERMAP_API_KEY here: https://openweathermap.org/ | |
# Get `OPENWEATHERMAP_API_KEY` here: https://openweathermap.org |
camel/functions/weather_functions.py
Outdated
""" | ||
Fetch and return a comprehensive weather report for a given city as a\ | ||
string. The report includes current weather conditions, temperature, \ | ||
wind details, visibility, and sunrise/sunset times, all formatted as \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
""" | |
Fetch and return a comprehensive weather report for a given city as a\ | |
string. The report includes current weather conditions, temperature, \ | |
wind details, visibility, and sunrise/sunset times, all formatted as \ | |
r"""Fetch and return a comprehensive weather report for a given city as a | |
string. The report includes current weather conditions, temperature, | |
wind details, visibility, and sunrise/sunset times, all formatted as |
camel/functions/weather_functions.py
Outdated
city (string): The name of the city for which the weather information | ||
is desired. Format "City, CountryCode" (e.g., "Paris, FR" | ||
for Paris, France). If the country code is not provided, | ||
the API will search for the city in all countries, which | ||
may yield incorrect results if multiple cities with the | ||
same name exist. | ||
temp_units (string): Units for temperature. Options: 'kelvin', | ||
'celsius', 'fahrenheit'. Default is 'kelvin'. | ||
wind_units (string): Units for wind speed. Options: 'meters_sec', | ||
'miles_hour', 'knots', 'beaufort'. | ||
Default is 'meters_sec'. | ||
visibility_units (string): Units for visibility distance. Options: | ||
'meters', 'miles'. Default is 'meters'. | ||
time_units (string): Format for sunrise and sunset times. Options: | ||
'unix', 'iso', 'date'. Default is 'unix'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation of the docstring is a bit weird here. We use 4 spaces for indentation usually.
assert visibility is not None, \ | ||
"Visibility information is missing from the report" | ||
assert visibility_min <= visibility <= visibility_max, \ | ||
f"Visibility {visibility} not in range for {visibility_units}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. Can we use brackets instead of back slash for formatting?
assert match, f"Sunrise and sunset information in {time_units} \ | ||
format is missing from the report." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. Can we use brackets instead of back slash for formatting?
assert sunrise_time < sunset_time, "Sunrise time is not before \ | ||
sunset time in the report." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. Can we use brackets instead of a back slash for formatting?
return key | ||
|
||
|
||
def test_temperature(api_key): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also do all the 4 tests in one function. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add WEATHER_FUNCS
to the function_list
and test it.
Hello @lightaime, I’ve updated my code format based on the previous suggestions and pushed the new version. If there are still any other details that need attention, please let me know. Thank you! |
Thanks @yiyiyi0817!! |
Co-authored-by: Tianqi Xu <tianqi.xu@kaust.edu.sa> Co-authored-by: lig <guohao.li@kaust.edu.sa>
Co-authored-by: Tianqi Xu <tianqi.xu@kaust.edu.sa> Co-authored-by: lig <guohao.li@kaust.edu.sa>
Description
This PR introduces a new API function, and a set of test cases to validate its functionality. This feature enhancement enhances the CAMEL project by providing access to current weather data based on city name.
This update integrates features related to the OpenWeatherMap API, enabling new weather-related functionality. It is a new edition of #328 .
In order to use these new features, an API key from OpenWeatherMap is required. Contributors and users who want to run this code will need to:
OPENWEATHERMAP_API_KEY
'. This is critical to ensure the security and privacy of your API key. Please do not hardcode the key into your codebase.Please ensure the 'OPENWEATHER_API_KEY' is correctly configured in the environment before running the application. Incorrect handling of the API key may lead to errors or unexpected behavior.
Thank you for your attention to this requirement as we integrate these exciting new weather features.
Motivation and Context
Motivation:
Weather data is a valuable resource for a wide range of applications, from optimizing energy consumption to improving travel safety. Users of the CAMEL project have expressed the need for a reliable and easy-to-use way to access current weather information based on geographical coordinates. This addition of the 'get_current_weather', 'get_current_wind', 'get_current_visibility_distance', 'get_sunrise_sunset' API fulfills that need, providing real-time weather data to CAMEL users, enhancing their experience, and enabling new possibilities for data analysis.
Context:
Prior to this change, users had to rely on external services or implement custom solutions to obtain weather data. 'get_current_weather', 'get_current_wind', 'get_current_visibility_distance', 'get_sunrise_sunset' API simplifies this process, making it more accessible and integrated within the CAMEL framework. This addition aligns with our project's goal of providing comprehensive and user-friendly AI capabilities. It leverages the OpenWeatherMap API to retrieve accurate and up-to-date weather information, which complements the existing functionality of CAMEL.
An issue has been raised to propose this change (#57)
Types of changes
Implemented Tasks
Checklist
Go over all the following points, and put an
x
in all the boxes that apply.If you are unsure about any of these, don't hesitate to ask. We are here to help!