Skip to content

Commit 614eb37

Browse files
authored
notebook 1 (#978)
1 parent 887af32 commit 614eb37

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"# Install dependencies. \n",
10+
"!pip install -U agentops openai-agents"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"metadata": {},
17+
"outputs": [],
18+
"source": [
19+
"# Set the API keys for your AgentOps and OpenAI accounts.\n",
20+
"import os\n",
21+
"\n",
22+
"os.environ[\"OPENAI_API_KEY\"] = ''\n",
23+
"os.environ[\"AGENTOPS_API_KEY\"] = ''\n",
24+
"\n",
25+
"if os.environ[\"OPENAI_API_KEY\"] == '':\n",
26+
" raise ValueError(\"OPENAI_API_KEY is not set. You can get one at https://platform.openai.com/api-keys\")\n",
27+
"if os.environ[\"AGENTOPS_API_KEY\"] == '':\n",
28+
" raise ValueError(\"AGENTOPS_API_KEY is not set. You can get one at https://app.agentops.ai/\")\n"
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": null,
34+
"metadata": {},
35+
"outputs": [],
36+
"source": [
37+
"from agents import Agent, Runner, function_tool\n",
38+
"import agentops\n",
39+
"\n",
40+
"# AgentOps automatically reads the API key from the environment variable\n",
41+
"agentops.init(tags=[\"weather-checker\", \"agentops-example\"])\n",
42+
"\n",
43+
"@function_tool\n",
44+
"def get_weather(city: str) -> str:\n",
45+
" return f\"The weather in {city} is sunny.\"\n",
46+
"\n",
47+
"\n",
48+
"agent = Agent(\n",
49+
" name=\"Weather checker\",\n",
50+
" instructions=\"You are a helpful agent that checks the weather in a given city.\",\n",
51+
" tools=[get_weather],\n",
52+
")\n",
53+
"\n",
54+
"\n",
55+
"async def main():\n",
56+
" print(\"Starting agent...\")\n",
57+
" result = await Runner.run(agent, \n",
58+
" input=\"What's the weather in San Francisco?\")\n",
59+
" print(result.final_output)\n",
60+
" # The weather in San Francisco is sunny.\n",
61+
"\n",
62+
"await main()\n"
63+
]
64+
},
65+
{
66+
"cell_type": "markdown",
67+
"metadata": {},
68+
"source": [
69+
"You can check the trace in the AgentOps UI: https://app.agentops.ai/traces"
70+
]
71+
},
72+
{
73+
"cell_type": "code",
74+
"execution_count": null,
75+
"metadata": {},
76+
"outputs": [],
77+
"source": []
78+
}
79+
],
80+
"metadata": {
81+
"kernelspec": {
82+
"display_name": "base",
83+
"language": "python",
84+
"name": "python3"
85+
},
86+
"language_info": {
87+
"codemirror_mode": {
88+
"name": "ipython",
89+
"version": 3
90+
},
91+
"file_extension": ".py",
92+
"mimetype": "text/x-python",
93+
"name": "python",
94+
"nbconvert_exporter": "python",
95+
"pygments_lexer": "ipython3",
96+
"version": "3.12.7"
97+
}
98+
},
99+
"nbformat": 4,
100+
"nbformat_minor": 2
101+
}

0 commit comments

Comments
 (0)