Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

chathub-adapter

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chathub-adapter

A package for using different chat-focused llms seamlessly

latest
Source
npmnpm
Version
1.3.0
Version published
Weekly downloads
10
-50%
Maintainers
1
Weekly downloads
 
Created
Source

ChatHub - Adapter

A simple-to-use, one-for-all SDK for interacting with trending LLM models.

Key Features

  • All-In-One SDK: use only one package to talk to ChatGPT, GPT-4, Claude-2, Claude-Instant, and PaLM at once

  • Universal conversation: conversations may be used across different LLMs, e.g.switching from ChatGPT to Claude during one conversation.

  • Conversation storage: conversations stored in local file system, with customizable cache directory and simple, black-boxed method for manipulation.

  • Conversation setup: customize your conversation context for role-playing, scenario enacting .etc

Installation & Use

Install

Run npm i chathub-adapter.

Use

To use this package, you will first need to import the ChatHub class and instantiate it.

import { ChatHub } from "chathub-adapter";

const Hub = new ChatHub(
 // Required. If there are multiple models, load them all in the array
 [{ model: `YourModelNameHere`, APIKey: `YourAPIKeyHere` }]
);

// To send a message
const response = await Hub.sendMessage(`Hello there!`, `YourDesiredModel`);
// If you are using `ChatGPT`, you can expect `General Kenobi!`
console.log(response.text);

// Continuing a conversation
const anotherResponse = await Hub.sendMessage(`How are you?`, `YourDesiredModel`, {
 // Pass the corresponding `conversationId`
 conversationId: response.conversationId
});
console.log(anotherResponse.text);

Types and Interfaces

Currently supported models: ChatGPT, GPT-4, Claude-v1, Claude-v2, Claude-Instant,ChatPaLM2.

Please note that this package will not grant you access to models you previously have no access to. e.g. Using this package will not allow you to use GPT-4 if your account is not valid to use its API.

Type NameAllow Contents
ModelOptionsNames of all supported models (case sensitive)
ChatOptionsProperties: conversationId, context, and systemMessage
ModelConfigConfiguration for your model, has two properties: model and APIKey.
ConversationThe interface in which conversation messages and their corresponding id
ConversationMessageProperties: role and content. role allows user, system, and assistant; content is string
conversationIdA UUID v4 for identifying conversations
contextA general context in which the conversation takes place
systemMessageA information-prompting message for LLM, used to provide contextual information that should not be mentioned by the user

Class and Methods

The main exported class for managing conversations and models is ChatHub.

ChatHub has the following public methods

Class ChatHub

Method NameParametersReturn ValueFunction
constructorconfig, cacheDirAn instance of ChatHubInstantiate a ChatHub class
sendMessagetext,model,optionsChatResponseSend your message to designated model
hasModelmodelbooleanCheck whether a certain model is activated in the ChatHub instance
getAllModelsnoneIterableIterator<ModelOptions>An iterator for all instantiated models
generateTextpromptPromise<string>The generated text with TextPaLM(currently only supports TextPaLM)

Class ConversationManager

If you want to import/export or manage your conversation in some other ways, you can instantiate a ConversationManager. Method are named as clear as possible.

This package is still being updated, star the GitHub repo to stay tuned!

Keywords

LLM

FAQs

Package last updated on 06 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts