1.0.5 • Published 12 months ago

openai-lite v1.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
12 months ago

OpenAI-Lite

OpenAI-Lite is a lightweight, Typescript-based npm package that provides a thin wrapper to interact with the OpenAI API. It includes type support for the completions, transcription, chat, and embedding endpoints. This makes it easier and more efficient for developers to leverage the power of OpenAI's language models, without needing to manually handle the low-level details of API calls.

Features

  • OpenAI Completions: Generate responses based on given prompts.
  • OpenAI Chat: Generate a model response for a given chat conversation.
  • OpenAI Embeddings: Get a vector representation of a given input.
  • OpenAI Transcriptions: Transcribe audio into the input language.

Installation

Install openai-lite using npm:

npm install openai-lite

Usage

Before using the package, you need to provide your OpenAI API key:

import { OpenAILite } from "openai-lite";

const openai = new OpenAILite("YOUR_OPENAI_API_KEY");

Completions

const prompt =
  'Translate the following English text to French: "{text: "Hello, world!"}"';

openai
  .complete({
    model: "text-davinci-003",
    prompt,
    max_tokens: 60,
  })
  .then((response) => {
    console.log(response.choices[0].text.trim());
  })
  .catch((error) => {
    console.error(error);
  });

Chat

const messages = [
  { role: "system", content: "You are a helpful assistant." },
  { role: "user", content: "Who won the world series in 2020?" },
];

openai
  .chat({
    model: "gpt-3.5-turbo",
    messages,
  })
  .then((response) => {
    console.log(response.choices[0].message.content.trim());
  })
  .catch((error) => {
    console.error(error);
  });

Embeddings

openai
  .embed({
    model: "text-embedding-ada-002",
    input: "The quick brown fox jumps over the lazy dog.",
  })
  .then((response) => {
    console.log(response.data[0].embedding);
  })
  .catch((error) => {
    console.error(error);
  });

Transcriptions

openai
  .transcribe({
    model: "whisper-1",
    file: "path_to_your_audio_file.mp3",
  })
  .then((response) => {
    console.log(response.transcriptions);
  })
  .catch((error) => {
    console.error(error);
  });

Contributing

Contributions are welcome! Please read our contributing guidelines to get started.

License

This project is licensed under the MIT License. See the LICENSE file for details.

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago