Azure OpenAI
is a service provided by Microsoft that integrates OpenAI’s advanced language models into the Azure cloud platform. It allows developers to access and use OpenAI’s capabilities, such as natural language processing, code generation, and more, through Azure’s infrastructure.
Recently, we have deployed our first version of the OpenAI GPT-4
model into the Azure cloud platform. This model is a powerful natural language model that can generate text based on a given prompt.
What is GPT-4?
GPT-4
is a transformer-based language model that was developed by OpenAI. It is a powerful language model that can generate text based on a given prompt. It has been trained on a large dataset of text and can generate coherent and engaging text that is often considered to be the next big thing in language models.
How can I use the GPT-4 API?
To use the GPT-4 API, you need to follow these steps:
- Create an Azure account.
- Create a resource group.
- Create a new OpenAI resource.
- Generate an API key.
- Use the API key to make API requests.
1. Create an Azure account
To use the GPT-4 API, you need to have an Azure account. If you don’t have one, you can create one for free by following the steps in the Azure sign-up page.
2. Create a resource group
Create a resource group to organize your Azure resources. To create a new resource group, follow these steps:
- Go to the Azure portal.
- Click on the
Resource groups
option in the left-hand menu. - Click on the
+ Create
button. - Enter a name for your resource group and select your subscription.
- Click on the
Review + create
button.
3. Create a new OpenAI resource
To create a new OpenAI resource, follow these steps:
- Go to the Azure portal.
- Click on the
Create a resource
button. - Search for
OpenAI
in the search bar. - Click on the
OpenAI
resource. - Click on the
Create
button. - Enter a name for your OpenAI resource and select your subscription.
- Select the resource group you created earlier.
- Select the pricing tier.
- Click on the
Create
button.
4. Generate an API key
To generate an API key, follow these steps:
- Go to the Azure portal.
- Click on the
All resources
option in the left-hand menu. - Search for your OpenAI resource.
- Click on the resource.
- Click on the
Show access keys
button. - Copy the
Key 1
value.
5. Use the API key to make API requests
To make API requests, we need to include the API key in the request headers. Here’s an example of how to make a request to the GPT-4 API with REST styles.
1 | curl $AZURE_OPENAI_ENDPOINT/openai/deployments/gpt-4o/chat/completions?api-version=2023-07-01-preview \ |
Place your API key and endpoint in the appropriate variables, and update which deployments model (gpt-4, gpt-4o or other models) and model version of your endpoint is using.
The Azure OpenAI also supports multiple programming languages, including Python
, JavaScript
, and C#
. You can use the API to generate text in your preferred programming language.
GPT-4 Chat Roles
In above message parameter, you may notice thata there are three roles: system
, user
, and assistant
. The GPT-4 API supports three chat roles. Let digger deeper into each role:
System: This role sets the context or guidelines for the conversation. It’s where you can specify instructions or constraints for how the assistant should behave throughout the interaction.
User: This role represents the input from the person interacting with the model. Any questions or prompts posed by the user fall under this role.
Assistant: This role is for the model’s responses. It contains the output generated by the assistant based on the user input and the context provided by the system.
In another word. The system
role sets the context, the user
role represents the input, and the assistant
role contains the output.
Use system to define the conversation’s tone, behavior, or rules.
Use user for all queries or statements made by the person.
Use assistant for the model’s replies.
Example
Let’s say we want to classify the product feedback classification as Suggestion
, Meanless
, Compliment
, Complaint
, or Others
. We can use the GPT-4 API to generate text based on the given prompt and classify the feedback.
First, we define the context or guidelines to let the assistant know what result we want to achieve. Given below content to the system
role.
1 | {"role": "system", "content": "There are 5 classifications: Suggestion, Meanless, Compliment, Complaint, Please provide a classification for user input."}, |
And, we only the OpenAI
to reply me the classification word when user input is provided. So we define the assistant
role as classification word
.
1 | {"role": "assistant", "content": "A classification word"} |
Now, we can ask the user to provide the feedback and provide the user
role.
1 | {"role": "user", "content": "its great and easy to use"} |
After the conversation, the assistant
role will provide the classification word as Compliment
. You will notice that there is a piece of json indicates the assistant
role content value in the response. The OpenAI gpt-4o model knows “its great and easy to use” is a “Compliment” and provides the classification word as “Compliment”.
1 | "message": { |
Let’s try another user input.
1 | {"role": "user", "content": "I'm in your walls"} |
The assistant
role will provide the classification word as Meanless
. Because this input is not meanful for any product feedback.
Conclusion
In this article, we have explored the role of the Azure OpenAI GPT-4 API and how it can be used to generate text. We have also learned about the chat roles and how to use them to classify the product feedback.