ballerinax/azure.openai.chat Ballerina library

1.0.2

Overview

This is a generated connector from Azure OpenAI Chat Completions API OpenAPI specification.

The Azure Azure OpenAI Service REST API Chat Completions Endpoint will create completions for chat messages with the ChatGPT (preview) and GPT-4 (preview) models.

Prerequisites

Quickstart

To use the Azure OpenAI Chat connector in your Ballerina application, update the .bal file as follows:

Step 1: Import connector

Import the ballerinax/azure.openai.chat module into the Ballerina project.

Copy
import ballerinax/azure.openai.chat;
import ballerina/io;

Step 2: Create a new connector instance

Create and initialize a chat:Client with the obtained apiKey and a serviceUrl containing the deployed models.

Copy
final chat:Client chatClient = check new (
    config = {auth: {apiKey: apiKey}},
    serviceUrl = serviceUrl
);

Step 3: Invoke connector operation

  1. Now you can use the operations available within the connector.

    Note: These operations are in the form of remote operations.

    Following is an example of creating a conversation with an OpenAI gpt-35-turbo model:

    Copy
    public function main() returns error? {
    
        final chat:Client chatClient = check new (
            config = {auth: {apiKey: apiKey}},
            serviceUrl = serviceUrl
        );
    
        chat:Chat_completions_body chatBody = {
            messages: [{role: "user", content: "What is Ballerina?"}]  
        };
    
        chat:Inline_response_200 chatResult = check chatClient->/deployments/["chat"]/chat/completions.post("2023-03-15-preview", chatBody);
    
        io:println(chatResult);
    }
  2. Use bal run command to compile and run the Ballerina program.

Import

import ballerinax/azure.openai.chat;Copy

Metadata

Released date: over 1 year ago

Version: 1.0.2

License: Apache-2.0


Compatibility

Platform: any

Ballerina version: 2201.4.1

GraalVM compatible: Yes


Pull count

Total: 3811

Current verison: 1153


Weekly downloads


Source repository


Keywords

AI/Chat

Azure OpenAI

Cost/Paid

GPT-3.5

ChatGPT

Vendor/Microsoft


Contributors

Other versions