Module ai.azure
ballerinax/ai.azure Ballerina library
1.4.2
Overview
Azure OpenAI Service provides access to OpenAI's powerful language models within the Microsoft Azure platform.
The Azure OpenAI connector offers APIs for connecting with Azure OpenAI Large Language Models (LLMs), enabling the integration of advanced conversational AI, text generation, and language processing capabilities into applications.
Key Features
- Connect and interact with Azure OpenAI Large Language Models (LLMs)
- Support for GPT-4, GPT-3.5, and other advanced OpenAI models
- Seamless integration with Azure AI infrastructure
- Secure communication with API key and token authentication
Prerequisites
Before using this module in your Ballerina application, first you must obtain the nessary configuration to engage the LLM.
- Create an Azure account.
- Create an Azure OpenAI resource.
- Obtain the tokens. Refer to the Azure OpenAI Authentication guide to learn how to generate and use tokens.
Quickstart
To use the ai.azure module in your Ballerina application, update the .bal file as follows:
Step 1: Import the module
Import the ai.azure; module.
import ballerinax/ai.azure;
Step 2: Intialize the Model Provider
Here's how to initialize the Model Provider:
import ballerina/ai; import ballerinax/ai.azure; final ai:ModelProvider azureOpenAiModel = check new azure:OpenAiModelProvider("https://service-url", "api-key", "deployment-id", "deployment-version");
Step 4: Invoke chat completion
ai:ChatMessage[] chatMessages = [{role: "user", content: "hi"}]; ai:ChatAssistantMessage response = check azureOpenAiModel->chat(chatMessages, tools = []); chatMessages.push(response);