-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy path02-tools-chatlas.py
37 lines (30 loc) · 1.08 KB
/
02-tools-chatlas.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import requests
from chatlas import ChatAnthropic
from dotenv import load_dotenv
load_dotenv() # Loads OPENAI_API_KEY from the .env file
chat = ChatAnthropic(
model="claude-3-5-sonnet-latest",
system_prompt=(
"You are a helpful assistant that can check the weather. "
"Report results in imperial units."
),
)
# Define a simple tool for getting the current weather
def get_weather(latitude: float, longitude: float):
"""
Get the current weather for a location using latitude and longitude.
"""
base_url = "https://api.open-meteo.com/v1/forecast"
params = {
"latitude": latitude,
"longitude": longitude,
"current": "temperature_2m,wind_speed_10m,relative_humidity_2m",
}
try:
response = requests.get(base_url, params=params)
response.raise_for_status() # Raise an exception for bad status codes
return response.text
except requests.RequestException as e:
return f"Error fetching weather data: {str(e)}"
chat.register_tool(get_weather)
chat.chat("What is the weather in Seattle?")