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

1 year ago

0.0.32

1 year ago

0.0.28

1 year ago

0.0.29

1 year ago

0.0.26

1 year ago

0.0.27

1 year ago

0.0.25

1 year ago

0.0.23

1 year ago

0.0.24

1 year ago

0.0.20

1 year ago

0.0.21

1 year ago

0.0.22

1 year ago

0.0.17

1 year ago

0.0.18

1 year ago

0.0.14

1 year ago

0.0.15

1 year ago

0.0.16

1 year ago

0.0.13

1 year ago

0.0.12

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago