Skip to content

Commit a3d41f3

Browse files
authored
Refactor notebook examples for linitng (#980)
1 parent b205b41 commit a3d41f3

File tree

4 files changed

+31
-33
lines changed

4 files changed

+31
-33
lines changed

agentops/instrumentation/openai_agents/instrumentor.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
from the `agents.tracing` module.
1515
1616
TODO Calls to the OpenAI API are not available in this tracing context, so we may
17-
need to monkey-patch the `openai` from here to get that data. While we do have
18-
separate instrumentation for the OpenAI API, in order to get it to nest with the
17+
need to monkey-patch the `openai` from here to get that data. While we do have
18+
separate instrumentation for the OpenAI API, in order to get it to nest with the
1919
spans we create here, it's probably easier (or even required) that we incorporate
20-
that here as well.
20+
that here as well.
2121
"""
22+
2223
from typing import Collection
2324
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor # type: ignore
2425
from agentops.logging import logger

examples/openai_agents_sdk/customer_service_agent.ipynb

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"metadata": {},
77
"outputs": [],
88
"source": [
9-
"# Install dependencies. \n",
9+
"# Install dependencies.\n",
1010
"!pip install -U agentops openai-agents"
1111
]
1212
},
@@ -19,13 +19,13 @@
1919
"# Set the API keys for your AgentOps and OpenAI accounts.\n",
2020
"import os\n",
2121
"\n",
22-
"os.environ[\"OPENAI_API_KEY\"] = ''\n",
23-
"os.environ[\"AGENTOPS_API_KEY\"] = ''\n",
22+
"os.environ[\"OPENAI_API_KEY\"] = \"\"\n",
23+
"os.environ[\"AGENTOPS_API_KEY\"] = \"\"\n",
2424
"\n",
25-
"if os.environ[\"OPENAI_API_KEY\"] == '':\n",
25+
"if os.environ[\"OPENAI_API_KEY\"] == \"\":\n",
2626
" 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"
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/\")"
2929
]
3030
},
3131
{
@@ -73,9 +73,7 @@
7373
"### TOOLS\n",
7474
"\n",
7575
"\n",
76-
"@function_tool(\n",
77-
" name_override=\"faq_lookup_tool\", description_override=\"Lookup frequently asked questions.\"\n",
78-
")\n",
76+
"@function_tool(name_override=\"faq_lookup_tool\", description_override=\"Lookup frequently asked questions.\")\n",
7977
"async def faq_lookup_tool(question: str) -> str:\n",
8078
" if \"bag\" in question or \"baggage\" in question:\n",
8179
" return (\n",
@@ -95,9 +93,7 @@
9593
"\n",
9694
"\n",
9795
"@function_tool\n",
98-
"async def update_seat(\n",
99-
" context: RunContextWrapper[AirlineAgentContext], confirmation_number: str, new_seat: str\n",
100-
") -> str:\n",
96+
"async def update_seat(context: RunContextWrapper[AirlineAgentContext], confirmation_number: str, new_seat: str) -> str:\n",
10197
" \"\"\"\n",
10298
" Update the seat for a given confirmation number.\n",
10399
"\n",
@@ -190,9 +186,7 @@
190186
" if isinstance(new_item, MessageOutputItem):\n",
191187
" print(f\"{agent_name}: {ItemHelpers.text_message_output(new_item)}\")\n",
192188
" elif isinstance(new_item, HandoffOutputItem):\n",
193-
" print(\n",
194-
" f\"Handed off from {new_item.source_agent.name} to {new_item.target_agent.name}\"\n",
195-
" )\n",
189+
" print(f\"Handed off from {new_item.source_agent.name} to {new_item.target_agent.name}\")\n",
196190
" elif isinstance(new_item, ToolCallItem):\n",
197191
" print(f\"{agent_name}: Calling a tool\")\n",
198192
" elif isinstance(new_item, ToolCallOutputItem):\n",

examples/openai_agents_sdk/tool_usage_agent.ipynb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"metadata": {},
77
"outputs": [],
88
"source": [
9-
"# Install dependencies. \n",
9+
"# Install dependencies.\n",
1010
"!pip install -U agentops openai-agents"
1111
]
1212
},
@@ -19,13 +19,13 @@
1919
"# Set the API keys for your AgentOps and OpenAI accounts.\n",
2020
"import os\n",
2121
"\n",
22-
"os.environ[\"OPENAI_API_KEY\"] = ''\n",
23-
"os.environ[\"AGENTOPS_API_KEY\"] = ''\n",
22+
"os.environ[\"OPENAI_API_KEY\"] = \"\"\n",
23+
"os.environ[\"AGENTOPS_API_KEY\"] = \"\"\n",
2424
"\n",
25-
"if os.environ[\"OPENAI_API_KEY\"] == '':\n",
25+
"if os.environ[\"OPENAI_API_KEY\"] == \"\":\n",
2626
" 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"
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/\")"
2929
]
3030
},
3131
{
@@ -40,6 +40,7 @@
4040
"# AgentOps automatically reads the API key from the environment variable\n",
4141
"agentops.init(tags=[\"weather-checker\", \"agentops-example\"])\n",
4242
"\n",
43+
"\n",
4344
"@function_tool\n",
4445
"def get_weather(city: str) -> str:\n",
4546
" return f\"The weather in {city} is sunny.\"\n",
@@ -54,12 +55,12 @@
5455
"\n",
5556
"async def main():\n",
5657
" print(\"Starting agent...\")\n",
57-
" result = await Runner.run(agent, \n",
58-
" input=\"What's the weather in San Francisco?\")\n",
58+
" result = await Runner.run(agent, input=\"What's the weather in San Francisco?\")\n",
5959
" print(result.final_output)\n",
6060
" # The weather in San Francisco is sunny.\n",
6161
"\n",
62-
"await main()\n"
62+
"\n",
63+
"await main()"
6364
]
6465
},
6566
{

examples/openai_agents_sdk/web_search_agent.ipynb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"metadata": {},
77
"outputs": [],
88
"source": [
9-
"# Install dependencies. \n",
9+
"# Install dependencies.\n",
1010
"!pip install -U agentops openai-agents"
1111
]
1212
},
@@ -19,13 +19,13 @@
1919
"# Set the API keys for your AgentOps and OpenAI accounts.\n",
2020
"import os\n",
2121
"\n",
22-
"os.environ[\"OPENAI_API_KEY\"] = ''\n",
23-
"os.environ[\"AGENTOPS_API_KEY\"] = ''\n",
22+
"os.environ[\"OPENAI_API_KEY\"] = \"\"\n",
23+
"os.environ[\"AGENTOPS_API_KEY\"] = \"\"\n",
2424
"\n",
25-
"if os.environ[\"OPENAI_API_KEY\"] == '':\n",
25+
"if os.environ[\"OPENAI_API_KEY\"] == \"\":\n",
2626
" 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"
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/\")"
2929
]
3030
},
3131
{
@@ -40,6 +40,7 @@
4040
"# AgentOps automatically reads the API key from the environment variable\n",
4141
"agentops.init(tags=[\"web-search-agent\", \"agentops-example\"])\n",
4242
"\n",
43+
"\n",
4344
"async def main():\n",
4445
" agent = Agent(\n",
4546
" name=\"Web searcher\",\n",
@@ -55,6 +56,7 @@
5556
" print(result.final_output)\n",
5657
" # The New York Giants are reportedly pursuing quarterback Aaron Rodgers after his ...\n",
5758
"\n",
59+
"\n",
5860
"await main()"
5961
]
6062
},

0 commit comments

Comments
 (0)