openai.openai
Home > @runlightyear/openai > OpenAI
OpenAI class
Connector to the OpenAI API
Signature:declare class OpenAI extends RestConnector
Extends:
Example 1
Import
import { OpenAI } from "@runlightyear/openAI"
Example 2
Use in an action
defineAction({
name: "openAIExample",
title: "OpenAI Example"
apps: ["openai"],
run: async ({ auths }) => {
const openai = new OpenAI({ auth: auths.openai });
}
}
Example 3
List models
const result = await openai.listModels();
const models = result.data.data;
console.log("Model ids: ", models.map((model) => model.id).join(", "));
Example 4
Create a completion
const result = await openai.createCompletion({
model: "text-davinci-003",
prompt: "Say this is a test",
maxTokens: 7,
temperature: 0,
});
const choice = result.data.choices[0];
const completion = choice.text;
console.log("Completion: ", completion);
Example 5
Create a chat completion
const result = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [
{
role: "system",
content: "You are a helpful assistant.",
},
{
role: "user",
content: "Hello!",
},
],
});
const choice = result.data.choices[0];
const completion = choice.message.content;
console.log("Completion: ", completion);
Example 6
Create an image
const result = await openai.createImage({
prompt: "A cute baby sea otter",
n: 2,
size: "1024x1024",
});
const images = result.data.data;
console.log("Url: ", images[0].url);
Constructors
Constructor | Modifiers | Description |
---|---|---|
(constructor)(props) | Constructs a new instance of the OpenAI class |
Properties
Property | Modifiers | Type | Description |
---|---|---|---|
authType | static | AuthType |
Assistants Methods
Method | Modifiers | Description |
---|---|---|
createAssistant(props) | (BETA) Create an assistant. | |
deleteAssistant(props) | (BETA) Delete an assistant | |
listAssistants(props) | (BETA) List assistants | |
modifyAssistant(props) | (BETA) Modify an assistant | |
retrieveAssistant(props) | (BETA) Retrieve an assistant |
Chat Methods
Method | Modifiers | Description |
---|---|---|
createChatCompletion(props) | Given a chat conversation, the model will return a chat completion response. |
Completions Methods
Method | Modifiers | Description |
---|---|---|
createCompletion(props) | Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position. |
Images Methods
Method | Modifiers | Description |
---|---|---|
createImage(props) | Given a prompt and/or an input image, the model will generate a new image. |
Messages Methods
Method | Modifiers | Description |
---|---|---|
createMessage(props) | (BETA) Create a message | |
listMessageFiles(props) | (BETA) List message files | |
listMessages(props) | (BETA) List messages | |
modifyMessage(props) | (BETA) Modify a message | |
retrieveMessage(props) | (BETA) Retrieve a message | |
retrieveMessageFile(props) | (BETA) Retrieve a message file |
Models Methods
Method | Modifiers | Description |
---|---|---|
listModels() | List and describe the various models available in the API. You can refer to the Models documentation to understand what models are available and the differences between them. |
Runs Methods
Method | Modifiers | Description |
---|---|---|
cancelRun(props) | (BETA) Cancel a run | |
createRun(props) | (BETA) Create a run | |
createThreadAndRun(props) | (BETA) Create a thread and run | |
listRuns(props) | (BETA) List runs | |
listRunSteps(props) | (BETA) List run steps | |
modifyRun(props) | (BETA) Modify a run | |
retrieveRun(props) | (BETA) Retrieve a run | |
retrieveRunStep(props) | (BETA) Retrieve a run step |
Threads Methods
Method | Modifiers | Description |
---|---|---|
createThread(props) | (BETA) Create a thread | |
deleteThread(props) | (BETA) Delete a thread | |
modifyThread(props) | (BETA) Modify a thread | |
retrieveThread(props) | (BETA) Retrieve a thread |
Other Methods
Method | Modifiers | Description |
---|---|---|
getBaseUrl() | ||
getDefaultHeaders() |