AI 050T00A ENU PowerPoint 02
AI 050T00A ENU PowerPoint 02
AI 050T00A ENU PowerPoint 02
Generative AI
Solutions with Azure
OpenAI Service
• Completion - model takes an input prompt, and generates one or more predicted completions
• Embeddings - model takes input and returns a vector representation of that input
• ChatCompletion - model takes input in the form of a chat conversation (where roles are specified with
the message they send), and the next chat completion is generated
https://endpoint.openai.azure.com/openai/deployments/deployment/
completions
{
"id": “1234….",
"object": "text_completion",
"created": 1679001781,
{
"model": “gpt-35-turbo",
"prompt": "Your favorite
Shakespeare "choices": [
play is", {
"max_tokens": 5 "text": "Macbeth",
} "index": 0,
"logprobs": null,
"finish_reason":
"stop"
}
]
}
© Copyright Microsoft Corporation. All rights reserved.
Using the Azure OpenAI REST API
Embedding Endpoint
https://endpoint.openai.azure.com/openai/deployments/
deployment/embeddings
{
"object": "list",
"data": [
{
{
"object": "embedding",
"input": "The food was delicious
"embedding": [
and
0.0172990688066482523,
the waiter was very
....
friendly..."
0.0134544348834753042,
}
],
"index": 0
}
],
"model": "text-embedding-
ada:002"
}
© Copyright Microsoft Corporation. All rights reserved.
Using the Azure OpenAI REST API
ChatCompletion Endpoint
https://endpoint.openai.azure.com/openai/deployments/deployment/
chat/completions
{
"messages":[ {
{"role": "system", "id": “unique_id", "object": "chat.completion",
"content": "You are an assistant "created": 1679001781, "model": "gpt-35-turbo",
that teaches people about AI."}, "usage": { "prompt_tokens": 95,
{"role": "user", "completion_tokens": 84, "total_tokens":
"content": "Does Azure OpenAI 179},
support multiple languages?"}, "choices": [
{"role": "assistant", {"message":
"content": "Yes, Azure OpenAI { "role": "assistant",
supports several languages."}, "content": "Yes, other Azure Cognitive
{"role": "user", Services also support
translation…"},
"content": "Do other Cognitive
"finish_reason": "stop",
Services support translation?"}
"index": 0}
]
]
}
}
© Copyright Microsoft Corporation. All rights reserved.
Using the Azure OpenAI SDKs
Language specific SDKs are available for use in your Pseudo code structure:
applications, in both C# and Python.
<include library>
Code structure follows a similar pattern for both
languages.
<create client>
Parameters such as Max Response and <define chat messages and options>
Temperature are defined in the chat options.
<send request>
Both synchronous and asynchronous API versions
are available.
<extract response content>
https://aka.ms/mslearn-azure-openai-api
Which REST endpoint should you use to interact with a GPT-4 model?
1
Completion
Embeddings
ChatCompletion
When using the .NET SDK, which method should you use to call the ChatCompletion API?
2
ChatMessage()
GetChatCompletions()
GetCompletions()
When using the Python SDK, which method should you use to call the ChatCompletion API?
3
openai.ChatCompletion.get()
openai.ChatCompletion.create()
openai.chat.complete()
Learning Recap
https://aka.ms/mslearn-build-openai