0.0.32 • Published 8 months ago
@restackio/integrations-openai v0.0.32
@restackio/integrations-openai
This package provides an integration for OpenAI's API, specifically tailored for use with the Restack AI framework.
Installation
To install the package, use npm or yarn:
npm install @restackio/integrations-openai
Features
- OpenAI Chat Completions (base and streaming)
- Rate limiting support
- Cost calculation
- Tool calls handling
- Event streaming
Usage
Basic Setup
// services.ts
import Restack from "@restackio/ai";
import { openaiService } from "@restackio/integrations-openai";
export async function services() {
const client = new Restack();
openaiService({ client, options: { rateLimit: 1000 } }).catch((err) => {
console.error("Error starting OpenAi service:", err);
});
}
services().catch((err) => {
console.error("Error running services:", err);
});
Chat Completions
For basic chat completions:
// openaiChatCompletionsBase.ts
import { log, step } from "@restackio/ai/workflow";
import * as openaiFunctions from "@restackio/integrations-openai/functions";
import { openaiTaskQueue } from "@restackio/integrations-openai/taskQueue";
export async function openaiChatCompletionsBaseWorkflow() {
const response = await step<typeof openaiFunctions>({
taskQueue: openaiTaskQueue,
}).openaiChatCompletionsBase({
userContent: "Hello, how are you?",
model: "gpt-4",
apiKey: "your-api-key-here",
});
}
For streaming chat completions:
// streamingChatCompletions.ts
import { log, step } from "@restackio/ai/workflow";
import * as openaiFunctions from "@restackio/integrations-openai/functions";
import { openaiTaskQueue } from "@restackio/integrations-openai/taskQueue";
export async function streamingChatsCompletionsWorkflow() {
const response = await step<typeof openaiFunctions>({
taskQueue: openaiTaskQueue,
}).openaiChatCompletionsStream({
newMessage: "Tell me a story",
model: "gpt-4",
streamAtCharacter: ".",
streamEvent: {
workflowEventName: "story_chunk",
},
apiKey: "your-api-key-here",
});
}
Configuration
The package uses environment variables for configuration. Make sure to set:
OPENAI_API_KEY
: Your OpenAI API key
0.0.30
8 months ago
0.0.32
8 months ago
0.0.28
8 months ago
0.0.29
8 months ago
0.0.26
8 months ago
0.0.27
8 months ago
0.0.25
8 months ago
0.0.23
9 months ago
0.0.24
9 months ago
0.0.20
10 months ago
0.0.21
10 months ago
0.0.22
10 months ago
0.0.17
10 months ago
0.0.18
10 months ago
0.0.14
10 months ago
0.0.15
10 months ago
0.0.16
10 months ago
0.0.13
11 months ago
0.0.12
11 months ago
0.0.11
11 months ago
0.0.10
11 months ago
0.0.9
11 months ago
0.0.8
11 months ago
0.0.7
11 months ago
0.0.6
11 months ago
0.0.5
11 months ago
0.0.4
11 months ago
0.0.3
11 months ago
0.0.2
11 months ago
0.0.1
11 months ago