Skip to content
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

Merged
merged 8 commits into from
Nov 9, 2023
Prev Previous commit
Next Next commit
Partial revert to the old version.
  • Loading branch information
yiyiyi0817 committed Oct 31, 2023
commit b82c32186e9415274721f89b0dc3ce10490e1552
17 changes: 7 additions & 10 deletions camel/functions/weather_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

from camel.functions import OpenAIFunction

# Define a constant for error message
ERROR_MESSAGE = "Unexpected error occurred while fetching"


def get_openweathermap_api_key() -> str:
"""
Expand Down Expand Up @@ -103,8 +100,8 @@ def get_current_weather(city: str, units: str = 'kelvin') -> dict:
# Catch any unexpected exceptions
return {
dandansamax marked this conversation as resolved.
Show resolved Hide resolved
"error":
f"{ERROR_MESSAGE} weather for {city}. \
Reason: {str(e)}"
f"Unexpected error occurred while fetching weather \
for {city}. Reason: {str(e)}"
}


Expand Down Expand Up @@ -152,8 +149,8 @@ def get_current_wind(city: str, units: str = 'meters_sec') -> dict:
# Catch any unexpected exceptions
return {
"error":
f"{ERROR_MESSAGE} wind data for {city}. \
Reason: {str(e)}"
f"Unexpected error occurred while fetching wind data \
for {city}. Reason: {str(e)}"
}


Expand Down Expand Up @@ -201,8 +198,8 @@ def get_current_visibility_distance(city: str, units: str = 'meters') -> dict:
# Catch any unexpected exceptions
return {
"error":
f"{ERROR_MESSAGE} visibility distance for {city}. \
Reason: {str(e)}"
f"Unexpected error occurred while fetching \
visibility distance for {city}. Reason: {str(e)}"
}


Expand Down Expand Up @@ -247,7 +244,7 @@ def get_sunrise_sunset(city: str, units: str = 'unix') -> Dict[str, str]:
# Handle any exceptions that may occur during the request
return {
"error":
f"{ERROR_MESSAGE} sunrise and sunset times for \
f"Failed to fetch sunrise and sunset times for \
{city}. Reason: {str(e)}"
}

Expand Down
Loading