@zhengxs/erniebot
Version:
非官方 JS-SDK,可以调用文心大模型的能力,包含文本创作、通用对话、语义向量、AI作图等
49 lines (48 loc) • 1.57 kB
TypeScript
import ERNIEBot from './index';
import { APIError } from './error';
import type { HTTPSearchParams, APIRequestInit, APIResponseProps, APIRequestOptions, APIHeaders, MaybePromise } from './interfaces';
export type APIBackendModuleInfo = {
moduleId: string;
};
export type APIBackendResourceInfo = {
resourceId: string;
models: {
[model: string]: APIBackendModuleInfo;
};
};
export type APIBackendResources = {
[resource: string]: APIBackendResourceInfo;
};
export declare abstract class APIBackend {
client: ERNIEBot;
abstract apiType: string;
abstract baseURL: string;
abstract resources: APIBackendResources;
setup(client: ERNIEBot): void;
/**
* 覆盖当前请求路径
*
* @param path - 当前路径
* @param model - 请求模型
* @returns 返回空值将使用预设的路径
*/
overrideResourcePath(path: string, model: string): string | undefined;
/**
* 返回默认请求参数
*/
defaultQuery(): MaybePromise<HTTPSearchParams>;
/**
* 添加授权请求头
*/
authHeaders(options: APIRequestOptions): APIHeaders;
/**
* 预处理请求
*/
prepareRequest(req: APIRequestInit, init: {
url: string;
options: APIRequestOptions;
}): MaybePromise<void>;
transformResponse(type: 'json', data: any): any;
parseResponse({ response, options, controller }: APIResponseProps): Promise<any>;
protected makeStatusError(ecode: number | undefined, error: Error, message: string, headers: Headers): APIError;
}