From 68b999158539ce6887f700164c9d7cab3d4d1a21 Mon Sep 17 00:00:00 2001 From: Albert Kim Jr Date: Tue, 25 Jun 2024 16:24:24 -0700 Subject: [PATCH] Updated starter example (#266) * Updated starter example * Update openai-gpt.ipynb * Update openai-gpt.ipynb * Update openai-gpt.ipynb * Update openai-gpt.ipynb --- examples/openai-gpt.ipynb | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) 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": {