ballerinax/azure.openai.text Ballerina library

1.0.3

Overview

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

The Azure OpenAI Service REST API Completions Endpoint will generate one or more predicted completions based on a provided prompt. The service can also return the probabilities of alternative tokens at each position.

Prerequisites

Quickstart

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

Step 1: Import connector

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

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

Step 2: Create a new connector instance

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

Copy
final text:Client textClient = 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 on text completion using an OpenAI text-davinci-002 model:

    Copy
    public function main() returns error? {
    
    final text:Client textClient = check new (
        config = {auth: {apiKey: apiKey}},
        serviceUrl = serviceUrl
    );
    
    text:Deploymentid_completions_body completionsBody = {
        prompt: "What is Ballerina?"
    };
    
    text:Inline_response_200 completionsResult = check textClient->/deployments/["davinci"]/completions.post("2023-03-15-preview", completionsBody);
    
    io:println(completionsResult);
    }
  2. Use bal run command to compile and run the Ballerina program.

Import

import ballerinax/azure.openai.text;Copy

Metadata

Released date: over 1 year ago

Version: 1.0.3

License: Apache-2.0


Compatibility

Platform: any

Ballerina version: 2201.4.1

GraalVM compatible: Yes


Pull count

Total: 4189

Current verison: 4182


Weekly downloads


Source repository


Keywords

AI/Text

Azure OpenAI

Cost/Paid

Completions

GPT-3

Vendor/Microsoft


Contributors

Other versions