Skip to content

Commit

Permalink
fix(tools): handle non-existing locations in OpenMeteo (#513)
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Dvorak <toomas2d@gmail.com>
  • Loading branch information
Tomas2D authored Mar 6, 2025
1 parent bd4112b commit 2030b64
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions python/beeai_framework/tools/weather/openmeteo.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from beeai_framework.context import RunContext
from beeai_framework.emitter.emitter import Emitter
from beeai_framework.logger import Logger
from beeai_framework.tools import ToolInputValidationError
from beeai_framework.tools import ToolError, ToolInputValidationError
from beeai_framework.tools.tool import StringToolOutput, Tool, ToolRunOptions

logger = Logger(__name__)
Expand Down Expand Up @@ -75,7 +75,9 @@ def _geocode(self, input: OpenMeteoToolInput) -> dict[str, str]:
)

response.raise_for_status()
results = response.json()["results"]
results = response.json().get("results", [])
if not results:
raise ToolError(f"Location '{input.location_name}' was not found.")
return results[0]

def get_params(self, input: OpenMeteoToolInput) -> dict[str, Any]:
Expand Down

0 comments on commit 2030b64

Please sign in to comment.