aisapi
Version:
A JavaScript/TypeScript API library for multiple AI providers
44 lines • 1.46 kB
TypeScript
import { AiProvider, ProviderOptions, TextGenerationParams, TextGenerationResponse, ImageGenerationParams, ImageGenerationResponse } from '../types';
/**
* AI服务基类
* 包含共享的基础功能,各服务商只需继承并添加特定实现
*/
export declare abstract class BaseProvider implements AiProvider {
/** 服务提供商名称 */
abstract readonly name: string;
/** API访问密钥 */
protected apiKey?: string;
/** API服务地址 */
protected baseUrl: string;
/** 请求等待时间上限(毫秒) */
protected timeout: number;
/**
* 创建服务实例
* @param options 配置参数
*/
constructor(options?: ProviderOptions);
/**
* 获取默认服务地址
* 每个子类需要提供自己的实现
*/
protected abstract getDefaultBaseUrl(): string;
/**
* 检查API密钥
*/
protected validateApiKey(): void;
/**
* 文本生成功能
* 必须由各服务商实现
*/
abstract generateText(params: TextGenerationParams): Promise<TextGenerationResponse>;
/**
* 图像生成功能
* 可选实现(不是所有服务商都支持)
*/
generateImage?(params: ImageGenerationParams): Promise<ImageGenerationResponse>;
/**
* 发送HTTP请求的通用方法
*/
protected sendRequest<T>(url: string, method: string, body?: any): Promise<T>;
}
//# sourceMappingURL=base.d.ts.map