From 05611fd50e801e85c7e67ec8be3dc5f04e8e36be Mon Sep 17 00:00:00 2001 From: Chris Continanza Date: Tue, 19 Mar 2024 12:34:16 -0400 Subject: [PATCH] Fix user agent string in example weather tool --- README.md | 6 ++++++ tool_use_package/weather_tool_example.py | 9 +++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2320bf8..33a4e2c 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,12 @@ Additionally, anthropic-tools introduces a new *structured* prompt format that y anthropic-tools also supports a number of pre-built tools out of the box, built on top of the same primitives available to you. These are here in case you want even easier tool use for some of our most common tools, such as search or SQL. +Run the example weather tool: +```bash +export ANTHROPIC_API_KEY= +python -m tool_use_package.weather_tool_example +``` + ### BaseTool BaseTool is the class that should be used to define individual tools. All you need to do to create a tool is inherit `BaseTool` and define the `use_tool()` method for the tool. ```python diff --git a/tool_use_package/weather_tool_example.py b/tool_use_package/weather_tool_example.py index 10d1059..e09fcb8 100644 --- a/tool_use_package/weather_tool_example.py +++ b/tool_use_package/weather_tool_example.py @@ -22,11 +22,12 @@ def use_tool(self, city: str): url = "https://nominatim.openstreetmap.org/search" params = {'q': city, 'format': 'json', 'limit': 1} - response = requests.get(url, params=params).json() + response = requests.get(url, params=params, headers={"User-Agent":"anthropic weather tool"}) + response_json = response.json() - if response: - lat = response[0]["lat"] - lon = response[0]["lon"] + if response_json: + lat = response_json[0]["lat"] + lon = response_json[0]["lon"] else: raise ValueError("Could not find lat and long coordinates for given place.")