Skip to content

Commit 5f7f480

Browse files
committed
chatCompletions update
1 parent 89d782b commit 5f7f480

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

Instructions/Labs/02-natural-language-azure-openai.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ To show how to integrate with an Azure OpenAI model, we'll use a short command-l
5555

5656
4. Make sure the type of shell indicated on the top left of the Cloud Shell pane is switched to *Bash*. If it's *PowerShell*, switch to *Bash* by using the drop-down menu.
5757

58-
5. Once the terminal starts, enter the following command to download the sample application and save it to a folder called `azure-openai`. If your Cloud Shell already has a folder named `azure-openai`, run `rm -r azure-openai -f` before cloning the repo.
58+
5. Once the terminal starts, enter the following command to download the sample application and save it to a folder called `azure-openai`.
5959

6060
```bash
61+
rm -r azure-openai -f
6162
git clone https://github.com/MicrosoftLearning/mslearn-openai azure-openai
6263
```
6364

@@ -130,19 +131,24 @@ For this exercise, you'll complete some key parts of the application to enable u
130131
OpenAIClient client = new OpenAIClient(new Uri(oaiEndpoint), new AzureKeyCredential(oaiKey));
131132
132133
// Build completion options object
133-
CompletionsOptions completionsOptions = new CompletionsOptions()
134+
ChatCompletionsOptions chatCompletionsOptions = new ChatCompletionsOptions()
134135
{
135-
Prompts = {
136-
text
136+
Messages =
137+
{
138+
new ChatMessage(ChatRole.System, "You are a helpful assistant. Summarize the following text in 60 words or less."),
139+
new ChatMessage(ChatRole.User, text),
137140
},
138-
MaxTokens = 60,
141+
MaxTokens = 120,
139142
Temperature = 0.7f,
140143
};
141144
142145
// Send request to Azure OpenAI model
143-
Completions completionsResponse = client.GetCompletions(oaiModelName, completionsOptions);
144-
string completion = completionsResponse.Choices[0].Text;
145-
Console.WriteLine($"Chatbot: {completion}");
146+
ChatCompletions response = client.GetChatCompletions(
147+
deploymentOrModelName: oaiModelName,
148+
chatCompletionsOptions);
149+
string completion = response.Choices[0].Message.Content;
150+
151+
Console.WriteLine("Summary: " + completion + "\n");
146152
```
147153
148154
**Python**
@@ -151,17 +157,22 @@ For this exercise, you'll complete some key parts of the application to enable u
151157
# Set OpenAI configuration settings
152158
openai.api_type = "azure"
153159
openai.api_base = azure_oai_endpoint
154-
openai.api_version = "2022-12-01"
160+
openai.api_version = "2023-03-15-preview"
155161
openai.api_key = azure_oai_key
156162
157163
# Send request to Azure OpenAI model
158164
print("Sending request for summary to Azure OpenAI endpoint...\n\n")
159-
response = openai.Completion.create(
165+
response = openai.ChatCompletion.create(
160166
engine=azure_oai_model,
161-
prompt=text,
162167
temperature=0.7,
163-
max_tokens=60
168+
max_tokens=120,
169+
messages=[
170+
{"role": "system", "content": "You are a helpful assistant. Summarize the following text in 60 words or less."},
171+
{"role": "user", "content": text}
172+
]
164173
)
174+
175+
print("Summary: " + response.choices[0].message.content + "\n")
165176
```
166177
167178
## Run your application

Labfiles/02-nlp-azure-openai/Python/test-openai-model.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ def main():
1919

2020
# Set OpenAI configuration settings
2121

22-
23-
24-
print("Summary of text: " + response.choices[0].text + "\n")
2522

2623
except Exception as ex:
2724
print(ex)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
The process of making maple syrup begins by tapping a spout (sometimes called a spile) into the sugar maple tree. The spile is inserted into the tree about 2 inches deep and the sap is collected as it flows out. The sap is then taken to a sugar shack where it is boiled down to concentrate the sugars. As the sap boils, water in the sap is evaporated and the syrup becomes more and more thick. Once the syrup reaches the right sugar content, which is usually when the boiling point reaches 219 degrees Fahrenheit, it is bottled and enjoyed. tl;dr:
1+
The process of making maple syrup begins by tapping a spout (sometimes called a spile) into the sugar maple tree. The spile is inserted into the tree about 2 inches deep and the sap is collected as it flows out. The sap is then taken to a sugar shack where it is boiled down to concentrate the sugars. As the sap boils, water in the sap is evaporated and the syrup becomes more and more thick. Once the syrup reaches the right sugar content, which is usually when the boiling point reaches 219 degrees Fahrenheit, it is bottled and enjoyed.

0 commit comments

Comments
 (0)