- tools.ipynb +60 -0
tools.ipynb
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 3,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"api_url='https://api.weather.com/v1/location/New York?apiKey=YOUR_API_KEY'\n",
|
13 |
+
"The current weather in New York is: Error: Unable to fetch weather data.\n"
|
14 |
+
]
|
15 |
+
}
|
16 |
+
],
|
17 |
+
"source": [
|
18 |
+
"# Code Agent Example: Retrieve Weather Information\n",
|
19 |
+
"def get_weather(city):\n",
|
20 |
+
" import requests\n",
|
21 |
+
" api_url = f\"https://api.weather.com/v1/location/{city}?apiKey=YOUR_API_KEY\"\n",
|
22 |
+
"\n",
|
23 |
+
" print(f\"api_url='{api_url}'\")\n",
|
24 |
+
"\n",
|
25 |
+
" response = requests.get(api_url)\n",
|
26 |
+
" if response.status_code == 200:\n",
|
27 |
+
" data = response.json()\n",
|
28 |
+
" return data.get(\"weather\", \"No weather information available\")\n",
|
29 |
+
" else:\n",
|
30 |
+
" return \"Error: Unable to fetch weather data.\"\n",
|
31 |
+
"\n",
|
32 |
+
"# Execute the function and prepare the final answer\n",
|
33 |
+
"result = get_weather(\"New York\")\n",
|
34 |
+
"final_answer = f\"The current weather in New York is: {result}\"\n",
|
35 |
+
"print(final_answer)"
|
36 |
+
]
|
37 |
+
}
|
38 |
+
],
|
39 |
+
"metadata": {
|
40 |
+
"kernelspec": {
|
41 |
+
"display_name": "Python 3",
|
42 |
+
"language": "python",
|
43 |
+
"name": "python3"
|
44 |
+
},
|
45 |
+
"language_info": {
|
46 |
+
"codemirror_mode": {
|
47 |
+
"name": "ipython",
|
48 |
+
"version": 3
|
49 |
+
},
|
50 |
+
"file_extension": ".py",
|
51 |
+
"mimetype": "text/x-python",
|
52 |
+
"name": "python",
|
53 |
+
"nbconvert_exporter": "python",
|
54 |
+
"pygments_lexer": "ipython3",
|
55 |
+
"version": "3.13.2"
|
56 |
+
}
|
57 |
+
},
|
58 |
+
"nbformat": 4,
|
59 |
+
"nbformat_minor": 2
|
60 |
+
}
|