AI 050T00A ENU PowerPoint 02

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 14

AI-050: Develop

Generative AI
Solutions with Azure
OpenAI Service

© Copyright Microsoft Corporation. All rights reserved.


Use Azure OpenAI APIs in
your applications
Agenda

• Use the APIs

• Integrate Azure OpenAI into your app

© Copyright Microsoft Corporation. All rights reserved.


Learning Objectives
After completing this module, you will be able to:

1 Integrate Azure OpenAI into your application

2 Differentiate between different endpoints available to


your application

3 Generate completions to prompts using the REST API and language


specific SDKs
Integrating Azure OpenAI into your app

Applications submit prompts to deployed models. Responses are completions.

• 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

ChatCompletion will be the endpoint we focus on for this course

Use Completion and Embeddings with GPT-3 based


models
Use ChatCompletion with GPT-35-Turbo and later models

© Copyright Microsoft Corporation. All rights reserved.


Using the Azure OpenAI REST API
Completion Endpoint

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>

© Copyright Microsoft Corporation. All rights reserved.


Exercise: Integrate Azure OpenAI into your app

Use the hosted lab environment if provided, or view


the lab instructions at the link below:

https://aka.ms/mslearn-azure-openai-api

© Copyright Microsoft Corporation. All rights reserved.


Knowledge check

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

In this module, we:

Integrated Azure OpenAI into your application


Differentiated between different endpoints available to your application
Generated completions from the ChatCompletion endpoint

© Copyright Microsoft Corporation. All rights reserved.


Resources

Use the Azure OpenAI service API

https://aka.ms/mslearn-build-openai

© Copyright Microsoft Corporation. All rights reserved.


Thank you.

© Copyright Microsoft Corporation. All rights reserved.

You might also like