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 16, 2023
1 parent 0dad1d2 commit 2ba9a0b
Showing 1 changed file with 19 additions and 30 deletions.
49 changes: 19 additions & 30 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 Down

0 comments on commit 2ba9a0b

Please sign in to comment.