Skip to content

Commit

Permalink
updated Expanding examples for AOAI
Browse files Browse the repository at this point in the history
  • Loading branch information
shirkey committed Apr 29, 2023
1 parent bade6ac commit bfcc9f7
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions l7-expanding.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
"## Setup"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "281c747b",
"metadata": {},
"source": [
"> NOTE: the following setup code (first two code blocks of this notebook) have been modified to work with the Azure OpenAI services instead of OpenAI services\n",
"> - Environment variables have been changed to avoid any collisions\n",
"> - OpenAI's `chat-3.5-turbo` is named `chat-35-turbo` in Azure OpenAI, but the notes have remained the same to avoid confusion with the video course material "
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -26,7 +37,13 @@
"from dotenv import load_dotenv, find_dotenv\n",
"_ = load_dotenv(find_dotenv()) # read local .env file\n",
"\n",
"openai.api_key = os.getenv('OPENAI_API_KEY')"
"chat_completions_config = {\n",
" 'api_type': 'azure',\n",
" 'api_base': os.getenv('AZURE_OPENAI_ENDPOINT'),\n",
" 'api_key': os.getenv('AZURE_OPENAI_API_KEY'),\n",
" 'api_version': os.getenv('AZURE_OPENAI_MODEL_CHAT_VERSION'),\n",
" 'engine': os.getenv('AZURE_OPENAI_MODEL_CHAT'),\n",
"}"
]
},
{
Expand All @@ -38,12 +55,13 @@
},
"outputs": [],
"source": [
"def get_completion(prompt, model=\"gpt-3.5-turbo\",temperature=0): # Andrew mentioned that the prompt/ completion paradigm is preferable for this class\n",
"def get_completion(prompt, temperature=0, config=chat_completions_config): # Andrew mentioned that the prompt/ completion paradigm is preferable for this class\n",
" messages = [{\"role\": \"user\", \"content\": prompt}]\n",
" \n",
" config['messages']=messages\n",
" config['temperature']=temperature # this is the degree of randomness of the model's output\n",
" response = openai.ChatCompletion.create(\n",
" model=model,\n",
" messages=messages,\n",
" temperature=temperature, # this is the degree of randomness of the model's output\n",
" **config\n",
" )\n",
" return response.choices[0].message[\"content\"]"
]
Expand Down Expand Up @@ -203,7 +221,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
"version": "3.11.3"
}
},
"nbformat": 4,
Expand Down

0 comments on commit bfcc9f7

Please sign in to comment.