import { CallbackManagerForLLMRun } from '@langchain/core/callbacks/manager'; import { Embeddings, EmbeddingsParams } from '@langchain/core/embeddings'; import { BaseChatModel, BaseChatModelCallOptions } from '@langchain/core/language_models/chat_models'; import { BaseMessage } from '@langchain/core/messages'; import { ChatGenerationChunk, ChatResult } from '@langchain/core/outputs'; import { StructuredTool } from '@langchain/core/tools'; import { Tiktoken } from 'js-tiktoken'; import { EmbeddingsRequester, ModelRequester } from 'koishi-plugin-chatluna/llm-core/platform/api'; import type { FileHandlingConfig } from 'koishi-plugin-chatluna/llm-core/platform/client'; import { ModelInfo } from 'koishi-plugin-chatluna/llm-core/platform/types'; import type { ModelUsageReporter } from 'koishi-plugin-chatluna/llm-core/platform/usage'; export interface ChatLunaModelCallOptions extends BaseChatModelCallOptions { model?: string; /** Sampling temperature to use */ temperature?: number; /** * Maximum number of tokens to generate in the completion. -1 returns as many * tokens as possible given the prompt and the model's maximum context size. */ maxTokens?: number; /** * Maximum number of tokens to crop the context to. * If not set, the model's maximum context size will be used. */ maxTokenLimit?: number; /** Total probability mass of tokens to consider at each step */ topP?: number; /** Penalizes repeated tokens according to frequency */ frequencyPenalty?: number; /** Penalizes repeated tokens */ presencePenalty?: number; /** Number of completions to generate for each prompt */ n?: number; /** Dictionary used to adjust the probability of specific tokens being generated */ logitBias?: Record; id?: string; stream?: boolean; tools?: StructuredTool[]; tool_choice?: string; variables?: Record; variables_hide?: Record; /** * Override request params for this request only. */ overrideRequestParams?: Record; } export interface ChatLunaModelInput extends ChatLunaModelCallOptions { llmType?: string; modelMaxContextSize?: number; modelInfo: ModelInfo; requester: ModelRequester; maxConcurrency?: number; maxRetries?: number; isThinkModel?: boolean; fileHandlingConfig?: FileHandlingConfig; usageReporter?: ModelUsageReporter; } export declare class ChatLunaChatModel extends BaseChatModel { private _options; protected __encoding: Tiktoken; private _requester; private _modelName; private _maxModelContextSize; private _modelInfo; private _isThinkModel; private _fileHandlingConfig?; private _report?; lc_serializable: boolean; constructor(_options: ChatLunaModelInput); get callKeys(): (keyof ChatLunaModelCallOptions)[]; /** * Get the parameters used to invoke the model */ invocationParams(options?: this['ParsedCallOptions']): ChatLunaModelCallOptions; _streamResponseChunks(messages: BaseMessage[], options: this['ParsedCallOptions'], runManager?: CallbackManagerForLLMRun, reportUsage?: boolean, promptTokens?: number): AsyncGenerator; private _createTokenUsageTracker; private _handleStreamChunk; private _hasToolCallChunk; private _hasResponse; private _updateTokenUsageFromChunk; private _finalizeStream; private _reportStreamUsage; private _closeStream; private _shouldRethrowStreamError; private _isNonRetryableError; _generate(messages: BaseMessage[], options: this['ParsedCallOptions'], runManager?: CallbackManagerForLLMRun): Promise; private _reportUsage; private _reportFailedUsage; private _generateWithRetry; private _createStream; /** @ignore */ private _completion; cropMessages(messages: BaseMessage[], tools?: StructuredTool[], systemMessageLength?: number, maxTokenLimit?: number): Promise<[BaseMessage[], number]>; countMessageTokens(message: BaseMessage): Promise; clearContext(id: string): Promise; getModelMaxContextSize(modelName?: string): number; getNumTokens(text: string, modelName?: string): Promise; _llmType(): string; get modelName(): string; get modelInfo(): ModelInfo; get isThinkModel(): boolean; get fileHandlingConfig(): FileHandlingConfig; _modelType(): string; /** @ignore */ _combineLLMOutput(...llmOutputs: any[]): any; } export interface ChatLunaBaseEmbeddingsParams extends EmbeddingsParams { /** * Timeout to use when making requests. */ timeout?: number; /** * The maximum number of documents to embed in a single request. This is * limited by the OpenAI API to a maximum of 2048. */ batchSize?: number; /** * Whether to strip new lines from the input text. This is recommended by * OpenAI, but may not be suitable for all use cases. */ stripNewLines?: boolean; maxRetries?: number; client: EmbeddingsRequester; model?: string; usageReporter?: ModelUsageReporter; } export declare abstract class ChatLunaBaseEmbeddings extends Embeddings { } export declare class ChatLunaEmbeddings extends ChatLunaBaseEmbeddings { modelName: string; batchSize: number; stripNewLines: boolean; timeout?: number; private _client; private _report?; constructor(fields?: ChatLunaBaseEmbeddingsParams); embedDocuments(texts: string[]): Promise; embedQuery(text: string): Promise; private _reportUsage; private _reportFailedUsage; private _embeddingWithRetry; }