UNPKG

huggingface-chat

Version:

A lightweight and powerful Node.js API client for Hugging Face Chat. Interact with open-source LLMs like Llama 3, Mixtral, and Gemma for conversational AI, text generation, and more. Supports ESM and CJS modules.

165 lines 5.19 kB
export interface Conversation { id: string; model: string; systemPrompt: string; title: string; history: History[]; } export interface History { id: string; role: string; content: string; createdAt: number; updatedAt: number; } export interface Model { id: string | null; name: string | null; displayName: string | null; preprompt: string | null; promptExamples: { title: string; prompt: string; }[]; websiteUrl: string | null; description: string | null; datasetName: string | null; datasetUrl: string | null; modelUrl: string | null; parameters: { [key: string]: any; }; } export interface Sesson { id: string; title: string; model: string; } export interface ChatResponse { id: string | undefined; stream: ReadableStream | undefined; completeResponsePromise: () => Promise<string>; } export interface Tools { baseUrl: string; color: string; createdAt: string; createdById: string; createdByName: string; description: string; displayName: string; endpoint: string; icon: string; inputs: string; last24HoursUseCount: string; name: string; outputComponent: string; outputComponentIdx: string; review: string; searchTokens: string; showOutput: string; type: string; updatedAt: string; useCount: string; _id: string; } export interface ChatOptions { tools?: string[]; rawResponse?: boolean; filePath?: string; } /** * ChatBot class for managing conversations and interactions with models on Hugging Face. */ export default class ChatBot { private cookie; private path; private headers; private chatLength; private models; private sessons; private currentModel; private currentModelId; private currentConversation; private currnetSesson; private currentConversionID; private tools; /** * Constructs a new instance of the ChatBot class. * @param {string} cookie - The user's authentication cookie. * @param {string} path - The path to a file containing the authentication cookie. * @throws {Error} If both `cookie` and `path` are provided or if neither is provided. */ constructor(cookie?: string, path?: string); /** * Initializes the ChatBot instance. * @async * @returns {Promise<void>} */ intialize(): Promise<void>; /** * Switches the current model for the chat. * @param {string} value - The ID of the model to switch to. * @throws {Error} If the provided model ID is not a string or if the model is not found. */ switchModel(value: string): void; /** * Lists available models that can be used with the chat. * @returns {Model[]} An array of available model names. */ listAvilableModels(): Model[]; /** * Lists available sessions for the chat. * @returns {Sesson[]} An array of available sessions. */ listAvilableSesson(): Sesson[]; /** * Returns the currently selected model for the chat. * @returns {Model | null} The current model. */ showCurrentModel(): Model | null; /** * Reads cookies from a specified file path. * @param {string} path - The path to the file containing the cookies. * @throws {Error} If the path is undefined. * @private */ private readCookiesFromPath; /** * Fetches remote conversations from a server. * @returns {Promise<Sesson[]>} A promise that resolves to an array of fetched conversations. * @throws {Error} If the server response is not successful. */ getRemoteConversations(): Promise<Sesson[]>; /** * Fetches remote LLMs from a server. * @returns {Promise<Model[]>} A promise that resolves to an array of fetched conversations. * @throws {Error} If the server response is not successful. */ getRemoteLlms(): Promise<Model[]>; getToolList(pageNumber: number): Promise<any[]>; /** * Initializes a new chat conversation. * @returns {Promise<Conversation>} The conversation ID of the new chat. * @throws {Error} If the creation of a new conversation fails. */ getNewChat(systemPrompt?: string): Promise<Conversation>; downloadFile(conversation: string, fileSha: string, name: string): Promise<void>; /** * Initiates a chat with the provided text. * @param {string} text - The user's input text or prompt. * @param {string} currentConversionID - The conversation ID for the current chat. * @param {ChatOptions} options * @returns {Promise<ChatResponse>} An object containing conversation details. * @throws {Error} If there is an issue with the chat request. */ chat(text: string, currentConversionID?: string, options?: ChatOptions): Promise<ChatResponse>; /** * get the details of current conversation * @returns {Promise<Conversation>} A Promise that return conversation details * @throws {Error} If there is an api error */ private getConversationHistory; private metadataParser; } //# sourceMappingURL=chat.d.ts.map