UNPKG

@zhengxs/erniebot

Version:

非官方 JS-SDK,可以调用文心大模型的能力,包含文本创作、通用对话、语义向量、AI作图等

56 lines (55 loc) 2.26 kB
export type Headers = Record<string, string>; export interface AuthCredentials { ak: string; sk: string; } export declare class AuthSignature { private credentials; headersToSign: string[]; constructor(credentials: AuthCredentials); /** * Generate the signature based on http://gollum.baidu.com/AuthenticationMechanism * * @param method - The http request method, such as GET, POST, DELETE, PUT, ... * @param resource - The request path. * @param params - The query strings. * @param headers - The http request headers. * @param timestamp - Set the current timestamp. * @param expirationInSeconds - The signature validation time. * @param headersToSign - The request headers list which will be used to calcualate the signature. * @returns The signature. */ generateAuthorization(method: string, resource: string, params?: Record<string, string>, headers?: Record<string, string>, timestamp?: number, expirationInSeconds?: number, headersToSign?: string[]): Promise<string>; /** * 规范化网址 * * @see https://developers.google.com/search/docs/crawling-indexing/canonicalization?hl=zh-cn * @param uri - 网址 * @returns */ uriCanonicalization(uri: string): string; /** * Canonical the query strings. * * @see http://gollum.baidu.com/AuthenticationMechanism#生成CanonicalQueryString * @param params - The query strings. */ queryStringCanonicalization(params: Record<string, string>): string; /** * Canonical the http request headers. * * @see http://gollum.baidu.com/AuthenticationMechanism#生成CanonicalHeaders * @param headers - The http request headers. * @param headersToSign - The request headers list which will be used to calcualate the signature. * @returns canonicalHeaders and signedHeaders */ headersCanonicalization(headers: Headers, headersToSign?: string[]): readonly [string[], string[]]; } export declare class TokenManager { #private; getAccessToken(credentials: AuthCredentials): Promise<string>; requestAccessToken({ ak, sk }: AuthCredentials): Promise<{ access_token: string; expires_in: number; }>; }