laravelgpt
Version:
CLI tools for AI agents
142 lines (141 loc) • 6.2 kB
TypeScript
import type { Config } from '../types';
import type { VideoAnalysisOptions } from '../types';
export interface ModelOptions {
model: string;
maxTokens: number;
systemPrompt?: string;
tokenCount?: number;
webSearch?: boolean;
timeout?: number;
debug: boolean | undefined;
reasoningEffort?: 'low' | 'medium' | 'high';
}
export interface ProviderConfig {
model?: string;
maxTokens?: number;
apiKey?: string;
referer?: string;
appName?: string;
debugLogMaxLength?: number;
}
export interface BaseModelProvider {
executePrompt(prompt: string, options?: ModelOptions): Promise<string>;
supportsWebSearch(modelName: string): Promise<{
supported: boolean;
model?: string;
error?: string;
}>;
tokenUsage?: {
promptTokens: number;
completionTokens: number;
totalTokens: number;
};
executeVideoPrompt?(prompt: string, options: VideoAnalysisOptions): Promise<string>;
}
export declare abstract class BaseProvider implements BaseModelProvider {
protected config: Config;
protected availableModels?: Promise<Set<string>>;
tokenUsage?: {
promptTokens: number;
completionTokens: number;
totalTokens: number;
};
constructor();
/**
* Resolves a model name to an available model from the provider.
* This method implements a multi-step resolution process:
* 1. Try exact match with provider prefix
* 2. Try exact match within any provider namespace
* 3. Try prefix matching with various provider prefixes
* 4. Try handling special suffixes like -latest or -exp
* 5. Try finding similar models based on string similarity
*
* If no match is found, it throws a ModelNotFoundError with helpful suggestions.
*
* @param options The model options containing the requested model name
* @returns The resolved model name that can be used with the provider's API
* @throws ModelNotFoundError if no matching model is found
*/
protected getModel(options: ModelOptions | undefined): Promise<string>;
/**
* Try to find an exact match for the model in the available models.
* @param model The requested model name
* @param availableModels Set of available models
* @returns The matched model name or undefined if no match found
*/
private tryExactMatch;
/**
* Try to find a match for the model within any provider namespace.
* @param model The requested model name
* @param modelWithoutPrefix The model name without provider prefix
* @param availableModels Set of available models
* @returns The matched model name or undefined if no match found
*/
private tryProviderNamespaceMatch;
/**
* Try to find a match using various prefix matching strategies.
* @param model The requested model name
* @param modelWithoutPrefix The model name without provider prefix
* @param availableModels Set of available models
* @returns The matched model name or undefined if no match found
*/
private tryPrefixMatch;
/**
* Try to handle models with -latest suffix by finding the latest version.
* @param model The requested model name
* @param availableModels Set of available models
* @returns The matched model name or undefined if no match found
*/
private trySuffixHandling;
/**
* Try to handle models with -exp or -exp-* suffix by finding a non-experimental version.
* @param model The requested model name
* @param availableModels Set of available models
* @returns The matched model name or undefined if no match found
*/
private tryExperimentalSuffixHandling;
/**
* Find similar models based on string similarity.
* @param model The requested model name
* @param modelWithoutPrefix The model name without provider prefix
* @param availableModels Set of available models
* @returns Array of similar model names
*/
private findSimilarModels;
protected getSystemPrompt(options?: ModelOptions): string | undefined;
protected logRequestStart(options: ModelOptions, model: string, maxTokens: number, systemPrompt: string | undefined, endpoint: string, headers?: Record<string, string>): void;
protected handleLargeTokenCount(tokenCount: number): {
model?: string;
error?: string;
};
protected debugLog(options: ModelOptions | undefined, message: string, ...args: any[]): void;
protected truncateForLogging(obj: any, maxLength?: number): string;
/**
* Determines if the given model supports the reasoning effort parameter.
* Also checks the OVERRIDE_SAFETY_CHECKS environment variable to allow bypassing model restrictions.
*/
protected doesModelSupportReasoningEffort(model: string): boolean;
protected setTokenUsage(promptTokens: number, completionTokens: number): void;
abstract supportsWebSearch(modelName: string): Promise<{
supported: boolean;
model?: string;
error?: string;
}>;
abstract executePrompt(prompt: string, options: ModelOptions): Promise<string>;
executeVideoPrompt?(prompt: string, options: VideoAnalysisOptions): Promise<string>;
}
export declare function retryWithBackoff<T>(operation: () => Promise<T>, maxAttempts?: number, baseDelay?: number, // 1 second
shouldRetry?: (error: any) => boolean): Promise<T>;
export declare class GoogleVertexAIProvider extends BaseProvider {
private readonly _getAuthHeaders;
private readonly getAuthHeaders;
constructor();
private initializeModels;
supportsWebSearch(modelName: string): Promise<{
supported: boolean;
model?: string;
error?: string;
}>;
executePrompt(prompt: string, options: ModelOptions): Promise<string>;
}
export declare function createProvider(name: string, options?: any): Promise<import("./gemini").GeminiProvider | import("./openai").OpenAIProvider | import("./openrouter").OpenRouterProvider | import("./perplexity").PerplexityProvider | import("./modelbox").ModelBoxProvider | import("./anthropic").AnthropicProvider | import("./xai").XAIProvider>;