8000 added exception in weather tool · allient/create-fastapi-project@11d75c3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 11d75c3

Browse files
committed
added exception in weather tool
1 parent 0a3439e commit 11d75c3

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
#############################################
2-
# Project
3-
#############################################
41
PROJECT_NAME=
52
OPENAI_API_KEY=
63
UNSPLASH_API_KEY=
7-
SERP_API_KEY=
8-
#############################################
9-
# Wheater
10-
#############################################
11-
WHEATER_URL=https://wttr.in
4+
SERP_API_KEY=

create_fastapi_project/templates/langchain_basic/app/app/core/config.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
from pydantic import BaseSettings, AnyHttpUrl
2+
from pydantic import BaseSettings
33
from enum import Enum
44

55

@@ -17,7 +17,6 @@ class Settings(BaseSettings):
1717
OPENAI_API_KEY: str
1818
UNSPLASH_API_KEY: str
1919
SERP_API_KEY: str
20-
WHEATER_URL: AnyHttpUrl
2120

2221
class Config:
2322
case_sensitive = True

create_fastapi_project/templates/langchain_basic/app/app/utils/tools.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
pokemon_api_url = "https://pokeapi.co/api/v2/pokemon/"
1010
unsplash_api_url = f"https://api.unsplash.com/search/photos?client_id={settings.UNSPLASH_API_KEY}&query="
11+
weather_api_url = "https://wttr.in"
1112

1213

1314
class GeneralKnowledgeTool(BaseTool):
@@ -159,7 +160,9 @@ def _run(self, query: str, run_manager: Optional[Any] = None) -> str:
159160
async def _arun(self, query: str, run_manager: Optional[Any] = None) -> dict:
160161
"""Use the tool asynchronously."""
161162
async with httpx.AsyncClient() as client:
162-
response = await client.get(f"{settings.WHEATER_URL}/{query}?format=j1")
163+
response = await client.get(f"{weather_api_url}/{query}?format=j1")
164+
if response.status_code == 404:
165+
return f"Could not find weather for {query}"
163166
weather = response.json()
164167
temperature = weather["current_condition"][0]
165168
return temperature

0 commit comments

Comments
 (0)
0