ballerinax/azure.openai.text Ballerina library

1.0.4

Overview

The Azure OpenAI Completions API connector(https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference#completions/) 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.

Key Features

  • Programmatic access to create and manage resources via REST API
  • Send and publish data through the API
  • Manage user accounts and profiles
  • Secure authentication with API key or OAuth support

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

Other versions

Metadata

Released date: 9 days ago

Version: 1.0.4

License: Apache-2.0


Compatibility

Platform: any

Ballerina version: 2201.8.0

GraalVM compatible: Yes


Pull count

Total: 5391

Current verison: 8


Weekly downloads


Source repository


Keywords

Type/Connector

AI/Text

Azure OpenAI

Cost/Paid

Completions

GPT-3

Vendor/Microsoft

Area/AI & Machine Learning


Contributors