Azure Open AI

Serhan ayberk Kılıç
PEAKUP Tech News
Published in
7 min readJun 1, 2023

Azure Open AI

Azure Open AI is a cloud-based platform offered by Microsoft Azure, which provides tools and services for developing and deploying artificial intelligence (AI) models and solutions. It includes pre-built APIs for natural language processing, computer vision, and speech recognition, as well as custom machine learning capabilities for training and deploying models tailored to specific business needs.

Azure Open AI empowers developers and data scientists to build intelligent applications with ease, using popular programming languages and frameworks such as Python, R, and TensorFlow. It also offers seamless integration with other Azure services, such as Azure Cognitive Services, Azure Machine Learning, and Azure Databricks, for creating end-to-end AI solutions.

With Azure Open AI, organizations can accelerate their digital transformation journey and unlock the potential of AI to drive innovation and enhance customer experiences.

Comparing Azure OpenAI and OpenAI

Azure Open AI and OpenAI are two different platforms with different capabilities. Azure Open AI is a cloud-based platform offered by Microsoft Azure, which provides tools and services for developing and deploying artificial intelligence (AI) models and solutions. It includes pre-built APIs for natural language processing, computer vision, and speech recognition, as well as custom machine learning capabilities for training and deploying models tailored to specific business needs. On the other hand, OpenAI is an independent research organization that focuses on advancing AI in a safe and beneficial manner. While OpenAI provides access to state-of-the-art AI models and technologies, it does not offer the same level of cloud-based development and deployment capabilities as Azure Open AI.

How do the capabilities of Azure OpenAI compare to OpenAI?

Azure Open AI and OpenAI are two different platforms with different capabilities. Azure Open AI is a cloud-based platform offered by Microsoft Azure, which provides tools and services for developing and deploying artificial intelligence (AI) models and solutions. It includes pre-built APIs for natural language processing, computer vision, and speech recognition, as well as custom machine learning capabilities for training and deploying models tailored to specific business needs. On the other hand, OpenAI is an independent research organization that focuses on advancing AI in a safe and beneficial manner. While OpenAI provides access to state-of-the-art AI models and technologies, it does not offer the same level of cloud-based development and deployment capabilities as Azure Open AI.

Azure Open AI GPT-4: The Next Generation of Language Models

Azure Open AI Service is a cloud-based platform that allows you to access and use powerful AI models such as ChatGPT and GPT-4. GPT-4 is the latest and most advanced model from OpenAI, and it is now available in preview in Azure Open AI Service.

What is GPT-4?

GPT-4 is a large-scale neural network that can generate natural language text based on a given prompt. It is trained on a massive corpus of text from the internet, and it can learn from any kind of text, such as news articles, books, social media posts, code, and more.

GPT-4 is a generative model, which means it can create new text that is coherent and relevant to the prompt. It can also perform various natural language tasks, such as answering questions, summarizing text, writing essays, composing emails, creating chatbot responses, and more.

GPT-4 is a transformer-based model, which means it uses a special architecture that allows it to process long sequences of text and capture complex relationships between words and sentences. It also uses attention mechanisms, which enable it to focus on the most important parts of the input and the output.

GPT-4 is a self-attention model, which means it can learn from its own generated text and improve over time. It can also use context information, such as previous messages in a conversation or previous sentences in a document, to generate more relevant and consistent text.

GPT-4 is a very large model, with 175 billion parameters. This makes it one of the largest and most powerful language models ever created. It can generate high-quality text across a wide range of domains and topics.

How to use GPT-4 in Azure Open AI Service?

To use GPT-4 in Azure Open AI Service, you need to do the following steps:

  • Apply for access to GPT-4 by filling out this form. Existing Azure Open AI customers can request access to GPT-4 models.
  • Create an Azure Open AI Service resource in the Azure portal. You need an Azure subscription to do this.
  • Deploy a GPT-4 model to your resource. You can choose from different models with different capabilities and sizes. For more information about model deployment, see the resource deployment guide.
  • Authenticate to your resource using either API keys or Azure Active Directory (Azure AD). You can obtain an API key from the Azure portal or use managed identities for Azure resources or user-assigned identities to authorize access using Azure AD credentials.
  • Use the Chat Completion API to interact with the GPT-4 model. This is a new dedicated API for conversational interfaces that expects input formatted in a chat-like transcript format and returns a completion that represents a model-written message in the chat. You can use this API for both chat and non-chat scenarios.
  • Alternatively, you can use the Completion API with Chat Markup Language (ChatML) to interact with the ChatGPT model (gpt-35-turbo). This is an older API that requires a unique token based prompt format known as ChatML. This provides lower level access than the Chat Completion API, but also requires additional input validation.

What are some examples of GPT-4 applications?

You can use GPT-4 for various applications that require natural language generation or understanding. Here are some examples:

  • Content creation: You can use GPT-4 to generate high-quality content for your website, blog, social media, newsletter, or marketing campaign. You can also use it to create captions, headlines, summaries, reviews, testimonials, or slogans.
  • Education: You can use GPT-4 to create educational materials such as quizzes, exercises, essays, tutorials, or courses. You can also use it to provide feedback, guidance, or explanations to students or learners.
  • Entertainment: You can use GPT-4 to create entertaining content such as stories, poems, jokes, songs, lyrics, scripts, or games. You can also use it to generate personalized recommendations or suggestions based on your preferences or interests.
  • Business: You can use GPT-4 to automate business tasks such as writing emails, reports, proposals, invoices, contracts, or presentations. You can also use it to generate insights, analysis, forecasts, or strategies based on data or information.
  • Research: You can use GPT-4 to assist you with research tasks such as finding relevant sources, summarizing articles, synthesizing information, generating hypotheses, or writing papers.
  • Healthcare: You can use GPT-4 to provide health-related information such as diagnosis, treatment options, symptoms, or prevention tips. You can also use it to create health-related content such as articles, blogs, newsletters, or podcasts.

Generate text based on a prompt

# Import the openai library
import openai
# Set the api_type, api_key, api_base and api_version for Azure OpenAI
openai.api_type = "azure"
openai.api_key = "sk-..." # Replace with your API key
openai.api_base = "https://<your-resource-name>.cognitiveservices.azure.com" # Replace with your resource name
openai.api_version = "2023-05-15"
# Set the deployment name and the model name
deployment_id = "deployment-name" # Replace with your deployment name
model = "gpt-3.5-turbo" # Replace with your model name
# Set the prompt text
prompt = "Once upon a time"
# Call the completions API to generate text based on the prompt
completion = openai.Completion.create(
deployment_id=deployment_id,
model=model,
prompt=prompt
)
# Print the generated text
print(completion.choices[0].text)

How to Authenticate to Azure Open AI Service

Azure Open AI Service is a cloud-based platform that allows you to access and use powerful AI models such as ChatGPT and GPT-4. To use these models, you need to authenticate to the service using either API keys or Azure Active Directory (Azure AD).

API Key Authentication

API key authentication is a simple and convenient way to authenticate to Azure Open AI Service. You can obtain an API key from the Azure portal after creating an Azure Open AI Service resource. You need to include the API key in the api-key HTTP header for every API request you make.

For example, if you want to use the completions API to generate text based on a prompt, you can use the following curl command:

curl https://<your-resource-name>.cognitiveservices.azure.com/openai/deployments/<your-deployment-name>/completions?api-version=2022-12-01 \\ -H "Content-Type: application/json" \\ -H "api-key: <your-api-key>" \\ -d '{"prompt": "Once upon a time"}' Copy

Azure AD Authentication

Azure AD authentication is a more secure and flexible way to authenticate to Azure Open AI Service. You can use managed identities for Azure resources or user-assigned identities to authorize access to the service using Azure AD credentials.

To use Azure AD authentication, you need to do the following steps:

  • Assign yourself or your identity to the Cognitive Services User role for your Azure Open AI Service resource.
  • Acquire an Azure AD access token for the resource https://cognitiveservices.azure.com.
  • Use the access token as a bearer token in the Authorization HTTP header for every API request you make.

For example, if you want to use the completions API to generate text based on a prompt, you can use the following curl command:

curl https://<your-resource-name>.cognitiveservices.azure.com/openai/deployments/<your-deployment-name>/completions?api-version=2022-12-01 \\ -H "Content-Type: application/json" \\ -H "Authorization: Bearer <your-access-token>" \\ -d '{"prompt": "Once upon a time"}'

--

--