UNPKG

@zhengxs/wechaty-plugin-assistant

Version:
54 lines (52 loc) 2.11 kB
import { EBOptions, ERNIEBot } from '@zhengxs/erniebot'; import { default as Keyv } from 'keyv'; import { ChatMessage, GetMessageByIdFunction, UpsertMessageFunction } from './llm-api'; export interface EBApiOptions extends EBOptions { /** @defaultValue `4096` **/ maxModelTokens?: number; /** @defaultValue `1000` **/ maxResponseTokens?: number; messageStore?: Keyv; getMessageById?: GetMessageByIdFunction; upsertMessage?: UpsertMessageFunction; } type SendMessageOptions = { conversationId?: string; parentMessageId?: string; messageId?: string; abortSignal?: AbortSignal; stream?: boolean; }; export declare class ERNIEBotAPI { protected _maxModelTokens: number; protected _maxResponseTokens: number; protected _getMessageById: GetMessageByIdFunction; protected _upsertMessage: UpsertMessageFunction; protected _messageStore: Keyv<ChatMessage>; api: ERNIEBot; constructor(opts: EBApiOptions); /** * Sends a message to the OpenAI chat completions endpoint, waits for the response * to resolve, and returns the response. * * If you want your response to have historical context, you must provide a valid `parentMessageId`. * * If you want to receive a stream of partial responses, use `opts.onProgress`. * * Set `debug: true` in the `ChatGPTAPI` constructor to log more info on the full prompt sent to the OpenAI chat completions API. You can override the `systemMessage` in `opts` to customize the assistant's instructions. * * @param message - The prompt message to send * * @returns The response from ChatGPT */ sendMessage(text: string, opts?: SendMessageOptions): Promise<ChatMessage>; protected _buildMessages(text: string, opts: SendMessageOptions): Promise<{ messages: any[]; maxTokens: number; numTokens: number; }>; protected _getTokenCount(text: string): Promise<number>; _defaultGetMessageById(id: string): Promise<ChatMessage>; _defaultUpsertMessage(message: ChatMessage): Promise<void>; } export {};