Skip to content

Python SDK for AI agent monitoring, LLM cost tracking, benchmarking, and more. Integrates with most LLMs and agent frameworks including CrewAI, Agno, OpenAI Agents SDK, Langchain, Autogen, AG2, and CamelAI

Updated starter example (#266)

Albert Kim Jr68b999158539
diff --git a/examples/openai-gpt.ipynb b/examples/openai-gpt.ipynb
index ebbd5bd8..ddc511c1 100644
--- a/examples/openai-gpt.ipynb
+++ b/examples/openai-gpt.ipynb
@@ -102,12 +102,35 @@
},
"outputs": [],
"source": [
- "message = ({\"role\": \"user\", \"content\": \"Hello\"},)\n",
- "openai.chat.completions.create(\n",
+ "message = ({\"role\": \"user\", \"content\": \"Write a 12 word poem about secret agents.\"},)\n",
+ "res = openai.chat.completions.create(\n",
" model=\"gpt-3.5-turbo\", messages=message, temperature=0.5, stream=True\n",
")"
]
},
+ {
+ "cell_type": "markdown",
+ "id": "4a231440",
+ "metadata": {},
+ "source": [
+ "Streamed completions are also automatically logged to AgentOps."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "19704228",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "full_response = \"\"\n",
+ "for chunk in res:\n",
+ " if chunk.choices[0].delta.content is not None:\n",
+ " full_response += chunk.choices[0].delta.content\n",
+ " \n",
+ "print(full_response.strip())"
+ ]
+ },
{
"cell_type": "markdown",
"id": "bf75276ad9fbb3f4",
@@ -230,15 +253,15 @@
},
{
"cell_type": "code",
- "outputs": [],
- "source": [
- "agentops.end_session(\"Success\")"
- ],
+ "execution_count": null,
+ "id": "4ca2b49fc06adddb",
"metadata": {
"collapsed": false
},
- "id": "4ca2b49fc06adddb",
- "execution_count": null
+ "outputs": [],
+ "source": [
+ "agentops.end_session(\"Success\")"
+ ]
}
],
"metadata": {