ballerinax/ai.openai Ballerina library

1.3.2

Overview

OpenAI provides powerful AI models for natural language processing, image generation, and other advanced tasks.

The OpenAI connector offers APIs for connecting with OpenAI Large Language Models (LLMs), enabling the integration of advanced conversational AI, text generation, and language processing capabilities into applications.

Key Features

  • Connect and interact with OpenAI Large Language Models (LLMs)
  • Support for GPT-4o, GPT-4, GPT-3.5, and other advanced models
  • Efficient handling of conversational prompts and completions
  • Secure communication with API key authentication

Prerequisites

Before using this module in your Ballerina application, first you must obtain the nessary configuration to engage the LLM.

Quickstart

To use the ai.openai module in your Ballerina application, update the .bal file as follows:

Step 1: Import the module

Import the ai.openai; module.

Copy
import ballerinax/ai.openai;

Step 2: Intialize the Model Provider

Here's how to initialize the Model Provider:

Copy
import ballerina/ai;
import ballerinax/ai.openai;

final ai:ModelProvider openAiModel = check new openai:ModelProvider("openAiApiKey", modelType = openai:GPT_4O);

Step 4: Invoke chat completion

Copy
ai:ChatMessage[] chatMessages = [{role: "user", content: "hi"}];
ai:ChatAssistantMessage response = check openAiModel->chat(chatMessages, tools = []);

chatMessages.push(response);

Import

import ballerinax/ai.openai;Copy

Other versions

See more...

Metadata

Released date: 2 days ago

Version: 1.3.2

License: Apache-2.0


Compatibility

Platform: java21

Ballerina version: 2201.12.0

GraalVM compatible: Yes


Pull count

Total: 10250

Current verison: 21


Weekly downloads


Source repository


Keywords

Agent

Model

Provider

Vendor/OpenAI

Area/AI & Machine Learning

Type/Connector


Contributors