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

Fix user agent string in example weather tool #22

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<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
Expand Down
11 changes: 6 additions & 5 deletions tool_use_package/weather_tool_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ class WeatherTool(BaseTool):
"""Retrieves the weather """

def use_tool(self, city: str):
"""Gets the lat and long of the given city, then uses these to get the weater forecast from the public open-meteo API."""
"""Gets the lat and long of the given city, then uses these to get the weather forecast from the public open-meteo API."""

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.")

Expand Down