Skip to content

Commit

Permalink
Update OpenAI example to use LLM SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
Lothiraldan committed Oct 12, 2023
1 parent 0dad1d2 commit eaa5385
Showing 1 changed file with 20 additions and 31 deletions.
51 changes: 20 additions & 31 deletions integrations/llm/openai/notebooks/Comet_and_OpenAI.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -139,30 +139,26 @@
" \"\"\"\n",
" Answer a question\n",
" \"\"\"\n",
" try:\n",
" # Create a chat completion using the question and system instructions\n",
" messages = [\n",
" {\n",
" \"role\": \"system\",\n",
" \"content\": \"Answer the question and if the question can't be answered, say \\\"I don't know\\\"\",\n",
" },\n",
" {\"role\": \"user\", \"content\": question},\n",
" ]\n",
" # Create a chat completion using the question and system instructions\n",
" messages = [\n",
" {\n",
" \"role\": \"system\",\n",
" \"content\": \"Answer the question and if the question can't be answered, say \\\"I don't know\\\"\",\n",
" },\n",
" {\"role\": \"user\", \"content\": question},\n",
" ]\n",
"\n",
" response = openai.ChatCompletion.create(\n",
" messages=messages,\n",
" temperature=0,\n",
" max_tokens=max_tokens,\n",
" top_p=1,\n",
" frequency_penalty=0,\n",
" presence_penalty=0,\n",
" stop=stop_sequence,\n",
" model=model,\n",
" )\n",
" return response[\"choices\"][0][\"message\"][\"content\"].strip()\n",
" except Exception as e:\n",
" print(e)\n",
" return \"\""
" response = openai.ChatCompletion.create(\n",
" messages=messages,\n",
" temperature=0,\n",
" max_tokens=max_tokens,\n",
" top_p=1,\n",
" frequency_penalty=0,\n",
" presence_penalty=0,\n",
" stop=stop_sequence,\n",
" model=model,\n",
" )\n",
" return response[\"choices\"][0][\"message\"][\"content\"].strip()"
]
},
{
Expand Down Expand Up @@ -211,13 +207,6 @@
"source": [
"answer_question(\"What is the airspeed velocity of an unladen swallow?\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -242,7 +231,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.9.1"
}
},
"nbformat": 4,
Expand Down

0 comments on commit eaa5385

Please sign in to comment.