Ballerina Central will undergo scheduled maintenance on Wednesday, August 06, from 00:30 AM to 01:30 AM UTC. During this time, Ballerina Central login and sign up will be temporarily disabled. We appreciate your patience as we work to improve your experience. For more information, reach out to contact@ballerina.io
 

ballerinax/openai.embeddings Ballerina library

1.0.5

Overview

This is a generated connector for the OpenAI Embeddings API OpenAPI specification. OpenAI is an American artificial intelligence research laboratory consisting of a non-profit corporation and a for-profit subsidiary. OpenAI conducts AI research with the declared intention of promoting and developing friendly AI. The OpenAI Embeddings API provides a way to access embeddings from new AI models developed by OpenAI for a variety of tasks.

Prerequisites

Before using this connector in your Ballerina application, complete the following:

Quick start

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

Step 1: Import the connector

First, import the ballerinax/openai.embeddings module into the Ballerina project.

Copy
import ballerinax/openai.embeddings;

Step 2: Create a new connector instance

Create and initialize an embeddings:Client with the obtained apiKey.

Copy
embeddings:Client embeddingsClient = check new ({
    auth: {
        token: "sk-XXXXXXXXX"
    }
});

Step 3: Invoke the connector operation

  1. Now, you can use the operations available within the connector. Following is an example on obtaining embeddings from GPT-3 ada model.

    Copy
    public function main() returns error? {
        embeddings:CreateEmbeddingRequest req = {
            model: "text-embedding-ada-002",
            input: "I have bought several of the Vitality canned"
        };
        embeddings:CreateEmbeddingResponse res = check embeddingsClient->/embeddings.post(req);
    }
  2. Use bal run command to compile and run the Ballerina program.

Import

import ballerinax/openai.embeddings;Copy

Other versions

See more...

Metadata

Released date: almost 2 years ago

Version: 1.0.5

License: Apache-2.0


Compatibility

Platform: any

Ballerina version: 2201.4.1


Pull count

Total: 470

Current verison: 384


Weekly downloads


Source repository


Keywords

AI/Embeddings

OpenAI

Cost/Paid

GPT-3

Vendor/OpenAI


Contributors