/** * The following code is modified based on * https://github.com/token-js/token.js/blob/main/src/index.ts * * MIT License * Copyright (c) 2024 RPate97 * https://github.com/token-js/token.js/blob/main/LICENSE */ import { LLMChat, LLMProvider } from './chat/index.js'; import { models } from './models.js'; import { ConfigOptions } from './userTypes/index.js'; export * from './models.js'; export * from './userTypes/index.js'; type TokenJSInterface = { chat: LLMChat; extendModelList
>(provider: P, name: string, featureSupport: extendedModelFeatureSupport
): void; }; export type extendedModelFeatureSupport
= ((typeof models)[P]['models'] extends readonly string[] ? (typeof models)[P]['models'][number] : never) | {
streaming: boolean;
json: boolean;
toolCalls: boolean;
images: boolean;
};
type extendedModelList = Array<{
provider: LLMProvider;
name: string;
featureSupport: extendedModelFeatureSupport >(provider: P, name: string): boolean;
/**
* Extends the predefined model list by adding a new model with specified features.
*
* @param provider - The LLM provider (e.g., 'openai', 'anthropic')
* @param name - The model name/identifier to add
* @param featureSupport - Either:
* - A string matching an existing model name from the same provider to copy its feature support
* - An object specifying which features the model supports:
* | Feature | Type | Description |
* |------------|---------|----------------------------------------------|
* | streaming | boolean | Whether the model supports streaming responses|
* | json | boolean | Whether the model supports JSON mode |
* | toolCalls | boolean | Whether the model supports function calling |
* | images | boolean | Whether the model supports image inputs |
* @returns The TokenJS instance for chaining
*
* @example
* ```typescript
* // Example in 2 steps: Adding a custom Anthropic model
* const tokenjs = new TokenJS();
*
* // Step 1: Register the new model name
* tokenjs.extendModelList(
* "anthropic",
* 'claude-3-5-custom',
* "claude-3-sonnet-20240229" // Copy features from existing model
* );
*
* // Step 2: Using the extended model in a chat completion
* const result = await tokenjs.chat.completions.create({
* stream: true,
* provider: 'anthropic',
* model: 'claude-3-5-custom' as any, // Note: Type casting as 'any' required
* messages: [
* {
* role: 'user',
* content: 'Tell me about yourself.',
* },
* ],
* });
* ```
*
* Note: When using extended models, type casting (`as any`) is required
*/
extendModelList >(provider: P, name: string, featureSupport: extendedModelFeatureSupport ): this;
}
//# sourceMappingURL=index.d.ts.map