Skip to content

Commit

Permalink
Updated starter example (#266)
Browse files Browse the repository at this point in the history
* Updated starter example

* Update openai-gpt.ipynb

* Update openai-gpt.ipynb

* Update openai-gpt.ipynb

* Update openai-gpt.ipynb
  • Loading branch information
albertkimjunior authored Jun 25, 2024
1 parent 635a9e3 commit 68b9991
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions examples/openai-gpt.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand Down

0 comments on commit 68b9991

Please sign in to comment.