Skip to content

Commit

Permalink
Merge pull request microsoft#259 from davidathompson/main
Browse files Browse the repository at this point in the history
Migrated to openai >= 1.0.0
  • Loading branch information
koreyspace authored Jan 4, 2024
2 parents 43d3dce + 35f2f13 commit 4f61c31
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions 07-building-chat-applications/notebook-openai.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,17 @@
"outputs": [],
"source": [
"import os\n",
"import openai\n",
"from openai import OpenAI\n",
"from dotenv import load_dotenv\n",
"\n",
"load_dotenv()\n",
"\n",
"openai.api_type = \"openai\"\n",
"API_KEY = os.getenv(\"OPENAI_API_KEY\",\"\")\n",
"assert API_KEY, \"ERROR: OpenAI Key is missing\"\n",
"openai.api_key = API_KEY\n",
"\n",
"RESOURCE_ENDPOINT = \"https://api.openai.com\" "
"client = OpenAI(\n",
" api_key=API_KEY\n",
" )\n"
]
},
{
Expand Down Expand Up @@ -292,12 +293,12 @@
"# Create your first prompt\n",
"text_prompt = \"Should oxford commas always be used?\"\n",
"\n",
"response = openai.ChatCompletion.create(\n",
"response = client.chat.completions.create(\n",
" model=model,\n",
" messages = [{\"role\":\"system\", \"content\":\"You are a helpful assistant.\"},\n",
" {\"role\":\"user\",\"content\":text_prompt},])\n",
"\n",
"response['choices'][0]['message']['content']"
"response.choices[0].message.content"
]
},
{
Expand Down Expand Up @@ -334,12 +335,12 @@
"outputs": [],
"source": [
"\n",
"response = openai.ChatCompletion.create(\n",
"response = client.chat.completions.create(\n",
" model=model,\n",
" messages = [{\"role\":\"system\", \"content\":\"You are a helpful assistant.\"},\n",
" {\"role\":\"user\",\"content\":text_prompt},])\n",
"\n",
"response['choices'][0]['message']['content']"
"response.choices[0].message.content"
]
},
{
Expand Down Expand Up @@ -424,12 +425,12 @@
"source": [
"#Setting a few additional, typical parameters during API Call\n",
"\n",
"response = openai.ChatCompletion.create(\n",
"response = client.chat.completions.create(\n",
" model=model,\n",
" messages = [{\"role\":\"system\", \"content\":\"You are a helpful assistant.\"},\n",
" {\"role\":\"user\",\"content\":prompt},])\n",
"\n",
"response['choices'][0]['message']['content']"
"response.choices[0].message.content"
]
},
{
Expand Down Expand Up @@ -496,12 +497,12 @@
"source": [
"#Setting a few additional, typical parameters during API Call\n",
"\n",
"response = openai.ChatCompletion.create(\n",
"response = client.chat.completions.create(\n",
" model=model,\n",
" messages = [{\"role\":\"system\", \"content\":\"You are a helpful assistant.\"},\n",
" {\"role\":\"user\",\"content\":prompt},])\n",
"\n",
"response['choices'][0]['message']['content']"
"response.choices[0].message.content"
]
},
{
Expand Down Expand Up @@ -569,12 +570,12 @@
"source": [
"#Setting a few additional, typical parameters during API Call\n",
"\n",
"response = openai.ChatCompletion.create(\n",
"response = client.chat.completions.create(\n",
" model=model,\n",
" messages = [{\"role\":\"system\", \"content\":\"You are a helpful assistant.\"},\n",
" {\"role\":\"user\",\"content\":prompt},])\n",
" {\"role\":\"user\",\"content\":prompt}])\n",
"\n",
"response['choices'][0]['message']['content']"
"response.choices[0].message.content"
]
},
{
Expand Down Expand Up @@ -645,7 +646,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
"version": "3.11.5"
},
"microsoft": {
"host": {
Expand Down

0 comments on commit 4f61c31

Please sign in to comment.