Module ai.azure
ballerinax/ai.azure Ballerina library
1.1.1
Overview
This module offers APIs for connecting with AzureOpenAI Large Language Models (LLM).
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);
Import
import ballerinax/ai.azure;Other versions
1.1.1