-
Notifications
You must be signed in to change notification settings - Fork 31.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added githubmodels-assignment-simple.ipynb
- Loading branch information
1 parent
6783adf
commit f8df5de
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
07-building-chat-applications/python/githubmodels-assignment-simple.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"from azure.ai.inference import ChatCompletionsClient\n", | ||
"from azure.ai.inference.models import SystemMessage, UserMessage\n", | ||
"from azure.core.credentials import AzureKeyCredential\n", | ||
"\n", | ||
"token = os.environ[\"GITHUB_TOKEN\"]\n", | ||
"endpoint = \"https://models.inference.ai.azure.com\"\n", | ||
"\n", | ||
"client = ChatCompletionsClient(\n", | ||
" endpoint=endpoint,\n", | ||
" credential=AzureKeyCredential(token),\n", | ||
")\n", | ||
"\n", | ||
"model_name = \"gpt-4o\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Create your first prompt\n", | ||
"text_prompt = \" My foot hurts, what can be wrong?\"\n", | ||
"\n", | ||
"response = client.complete(\n", | ||
" model=model_name,\n", | ||
" messages = [\n", | ||
" {\"role\":\"system\", \"content\":\"I'm a doctor, specialist on surgery\"},\n", | ||
" {\"role\":\"user\",\"content\":text_prompt},])\n", | ||
"\n", | ||
"response.choices[0].message.content" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.4" | ||
}, | ||
"orig_nbformat": 4 | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |