Generative AI with Azure OpenAI (GPT-4 Overview)
Tags: ai, openai, azure, tutorial
Published: 2023-05-23 17:04:30

Hey, there! In this article we'll learn about Generative AI, and how to use the Azure OpenAI service for natural language interaction with GPT-4.

## **Generative AI overview**

Generative Artificial Intelligence is a type of AI that creates new and original content based on what it has learned from previous data. It can be used to generate text, images, music, and more.  

In short, it's an AI that generates content based on what is described in the input (prompt).

####**Azure OpenAI**

Azure OpenAI is part of the Azure Cognitive Services that uses generative AI models. In this sense, these are the workloads that we can consider:

- Generating Natural Language.
- Generating Code.
- Generating Images. 

For our Azure OpenAI overview, we'll exemplify the first scenario: *Generate content* through text.

## **Exploring Azure OpenAI**

####**Create Azure OpenAI service:**

As a first point, within Azure we'll have to create a new OpenAI resource like any other. 

Here, in addition to the subscription and resource group, we must specify the name, region, and the pricing tier for the new resource.

![Create Azure OpenAI resource](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2x83c4hn41t2uy075duo.png)

With the service created, here we can see the resource overview, keys & endpoints, and the *Go to Azure OpenAI Studio* option to go to the low-code dashboard.

![Azure OpenAI resource](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yovohtgezrhjhcwsukke.png)

####**Azure OpenAI Studio:**

And here we have it: The Azure OpenAI portal (https://oai.azure.com/). 

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u7ouzw7lamfp2i77zbiz.png)

The first thing we must do is create/establish a new deployment to specify which model we want to use.

In our example we'll use the `gpt-4-32k` model for the natural language interaction between the assistant and the users.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4fsb19dpan19cym460js.png)

Here we can learn more about the available models: [Azure OpenAI Service models](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/concepts/models#gpt-4-models).

####**Chat playground**

With the model established, we can now go to the playground to interact with it:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3hvhktg65stpwwwd093p.png)

To adjust our chat assistant, it is important to take into account three aspects/roles:

- **System message (prompt):** Instructions we can give the model about how it should behave and any context it should reference when generating a response.
- **User:** The user's question or comment.
- **Assistant:** The assistant's response.

####**Example:**

Let's suppose that we want our wizard to be an expert on Azure resources, and that it only responds to us if the resources are considered as IaaS, or SaaS. 

For this scenario we would have this System message (prompt):

`You are an assistant that knows about Azure resources, and who only answers if the resource name is of type Platform as a Service (PaaS), or Infrastructure as a Service (IaaS).`

We can also indicate to the assistant examples so that it has more context:

`User: Azure App Service.` 
`Assistant: Platform as a Service (PaaS)`

`User: Azure SQL Database.` 
`Assistant: Platform as a Service (PaaS)`

`User: Azure Virtual Machine.`
`Assistant: Infrastructure as a Service (IaaS)`

The recommendation is always to provide useful information so that the attendee has a good context of the topic to be discussed.

####**Interaction with the example:**

![Chat examples](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y2grmb8qnf7n5bo0bkow.png)

####**Parameters for the model:**

Within our *Chat Playground* area, we can see the parameters option to optimize our model:

- **Temperature:** Controls randomness. At higher temperatures, the answers can be more creative and unexpected.
- **Max length (tokens):** Set a limit on the number of tokens per model response.
- **Top probabilities:** Similar to temperature, this controls randomness but uses a different method.

You can learn more about it [here](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/chatgpt-quickstart?pivots=programming-language-studio&tabs=command-line).

## **Thanks for reading!**

If you have any questions or ideas in mind, it will be a pleasure to be able to be in communication with you, and together exchange knowledge with each other.

If you would like to learn more about Azure OpenAI, this Microsoft Learn module is a good option: [Introduction to Azure OpenAI Service](https://learn.microsoft.com/en-us/training/modules/explore-azure-openai/). 

See you on [Twitter](https://twitter.com/esDanielGomez) / [LinkedIn](https://www.linkedin.com/in/esdanielgomez).