0.0.34 • Published 1 year ago

@restackio/integrations-openai v0.0.34

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

@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.33

1 year ago

0.0.34

1 year ago

0.0.30

2 years ago

0.0.32

1 year ago

0.0.28

2 years ago

0.0.29

2 years ago

0.0.26

2 years ago

0.0.27

2 years ago

0.0.25

2 years ago

0.0.23

2 years ago

0.0.24

2 years ago

0.0.20

2 years ago

0.0.21

2 years ago

0.0.22

2 years ago

0.0.17

2 years ago

0.0.18

2 years ago

0.0.14

2 years ago

0.0.15

2 years ago

0.0.16

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago