/** * The following code is modified based on * https://github.com/token-js/token.js/blob/main/src/chat/index.ts * * MIT License * Copyright (c) 2024 RPate97 * https://github.com/token-js/token.js/blob/main/LICENSE */ import { ChatCompletionCreateParamsBase } from 'openai/resources/chat/completions'; import { models } from '../models.js'; import { CompletionResponse, ConfigOptions, StreamCompletionResponse } from '../userTypes/index.js'; export type OpenAIModel = (typeof models.openai.models)[number]; export type OpenAINonStreamingModel = (typeof models)['openai-non-streaming']['models'][number]; export type AI21Model = (typeof models.ai21.models)[number]; export type AnthropicModel = (typeof models.anthropic.models)[number]; export type GeminiModel = (typeof models.gemini.models)[number]; export type MistralModel = (typeof models.mistral.models)[number]; export type PerplexityModel = (typeof models.perplexity.models)[number]; export type GroqModel = (typeof models.groq.models)[number]; export type OpenRouterModel = string; export type OpenAICompatibleModel = string; export type AzureOpenAIModel = string; export type LLMChatModel = OpenAIModel | OpenAINonStreamingModel | AI21Model | AnthropicModel | GeminiModel | MistralModel | PerplexityModel | GroqModel | OpenRouterModel | OpenAICompatibleModel; export type LLMProvider = keyof typeof models; type ProviderModelMap = { openai: OpenAIModel; 'openai-non-streaming': OpenAINonStreamingModel; ai21: AI21Model; anthropic: AnthropicModel; gemini: GeminiModel; mistral: MistralModel; perplexity: PerplexityModel; groq: GroqModel; openrouter: OpenRouterModel; 'openai-compatible': OpenAICompatibleModel; 'azure-openai': AzureOpenAIModel; }; type CompletionBase
= Pick = CompletionBase & {
stream: true;
};
export type CompletionNonStreaming = CompletionBase & {
stream?: false | null;
};
export type ProviderCompletionParams = CompletionStreaming | CompletionNonStreaming ;
export type CompletionParams = {
[P in LLMProvider]: CompletionStreaming | CompletionNonStreaming ;
}[LLMProvider];
export declare class LLMCompletions {
private opts;
constructor(opts: ConfigOptions);
create (body: CompletionNonStreaming ): Promise (body: CompletionStreaming ): Promise (body: CompletionBase ): Promise