npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

openai-threads

v1.0.3

Published

This library is designed to facilitate the interaction with OpenAI's Assistant API through the concept of a `thread,` which represents a conversation with an OpenAI assistant.

Downloads

47

Readme

OpenAI-Threads

OpenAI-Threads is a Node.js module designed to interact with OpenAI's Thread API. It provides a simple and intuitive interface for creating and managing conversation threads with OpenAI's AI assistants. This module allows you to create threads, send messages, run threads, handle tool functions, and monitor the status of thread runs.

Features

  • Easy to create and manage conversation threads.
  • Send user messages to the thread.
  • Run threads with instructions.
  • Poll thread runs for status updates.
  • Register and handle custom events.
  • Register and execute custom functions during a thread run.

Installation

npm install openai-threads

or using yarn:

yarn add openai-threads

Usage

First, import the OpenAIThread class from the openai-threads package and instantiate it with the ID of your assistant.

import { OpenAIThread } from "openai-threads";

const thread = new OpenAIThread("your-assistant-id");

Register Functions

Register functions that can be called during the thread run. These must be the same function name as the function's added to the Assistant on the website or through other code.

thread.registerFunction("functionName", async ({ argument }) => {
  // Your function implementation
  return { success: true, data: "result" };
});

Register Events

Register event handlers to listen for thread updates.

thread.registerEvent("event-name", (run) => {
  // Your event handling logic
});

const events = [
    'requires_action',
    'queued',
    'in_progress',
    'completed',
    'expired',
    'cancelling',
    'cancelled',
    'failed'
];

Create a Thread

Create a new conversation thread.

await thread.createThread();

Send a User Message

Send a message from the user to the thread.

await thread.createUserMessage("Your message to the AI.");

Run the Thread

Run the thread with specific instructions.

await thread.runThread("Your instructions for the AI.");

Run the Thread, waiting for polling to decide completion or failure

Run the thread with specific instructions.

await thread.runThreadAndWait("Your instructions for the AI.");

Get the Latest Response

Retrieve the most recent response from the thread.

const response = await thread.getResponse();

Get All Messages

Fetch all messages from the thread.

const messages = await thread.getMessages();

Documentation

For more detailed information about the methods and their parameters, please refer to the OpenAI API documentation.

Examples

You can find an example script on how to use OpenAI-Threads in the examples directory.

Contributing

Contributions are welcome! Please feel free to submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Support

If you need help or have any questions, please open an issue in the GitHub repository.


Remember to replace `"your-assistant-id"` with the actual assistant ID provided by OpenAI and adjust the examples as needed for your actual use case. You should also provide a `LICENSE.md` file if you reference it in the README.

Additionally, make sure you have the necessary permissions and rights to use OpenAI's API, follow their guidelines, and handle user data responsibly as per their policies and any relevant laws.