ballerinax/azure.openai.embeddings Ballerina library

1.0.3

Overview

The Azure OpenAI Embeddings API connector(https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference#embeddings/) OpenAPI specification.

The Azure OpenAI Service REST API Embeddings Endpoint will generate a vector representation of a given input that can be easily consumed by machine learning models and other algorithms.

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 Embeddings connector in your Ballerina application, update the .bal file as follows:

Step 1: Import connector

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

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

Step 2: Create a new connector instance

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

Copy
final embeddings:Client embeddingsClient = 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 obtaining embeddings from a GPT-3 ada model:

    Copy
    public function main() returns error? {
    
        final embeddings:Client embeddingsClient = check new (
            config = {auth: {apiKey: apiKey}},
            serviceUrl = serviceUrl
        );
    
        embeddings:Deploymentid_embeddings_body embeddingsBody = {
            input: "I have bought several of Vitality canned"
        };
    
        embeddings:Inline_response_200 embeddingsResult = check embeddingsClient->/deployments/["embedding"]/embeddings.post("2023-03-15-preview", embeddingsBody);
    
        io:println(embeddingsResult);
    }
  2. Use bal run command to compile and run the Ballerina program.

Import

import ballerinax/azure.openai.embeddings;Copy

Other versions

Metadata

Released date: about 1 hour ago

Version: 1.0.3

License: Apache-2.0


Compatibility

Platform: any

Ballerina version: 2201.8.0

GraalVM compatible: Yes


Pull count

Total: 10341

Current verison: 0


Weekly downloads


Source repository


Keywords

Type/Connector

AI/Embeddings

Azure OpenAI

Cost/Paid

GPT-3

Vendor/Microsoft

Area/AI & Machine Learning


Contributors