z-ai-web-dev-sdk
Version:
SDK for Z AI Web Dev
78 lines (77 loc) • 2.15 kB
TypeScript
interface ZAIConfig {
baseUrl: string;
apiKey: string;
chatId?: string;
userId?: string;
}
interface ChatMessage {
role: 'system' | 'user' | 'assistant';
content: string;
}
interface CreateChatCompletionBody {
model?: string;
messages: ChatMessage[];
[key: string]: any;
}
interface CreateImageGenerationBody {
model?: string;
prompt: string;
size?: '1024x1024' | '768x1344' | '864x1152' | '1344x768' | '1152x864' | '1440x720' | '720x1440';
}
interface ImageGenerationResponse {
created: number;
data: Array<{
base64: string;
}>;
content_filter?: Array<{
role: string;
level: number;
}>;
}
interface SearchFunctionArgs {
query: string;
num?: number;
recency_days?: number;
}
interface SearchFunctionResultItem {
url: string;
name: string;
snippet: string;
host_name: string;
rank: number;
date: string;
favicon: string;
}
interface FunctionMap {
web_search: {
args: SearchFunctionArgs;
result: SearchFunctionResultItem[];
};
}
type FunctionName = keyof FunctionMap;
type FunctionArgs<T extends FunctionName> = FunctionMap[T]['args'];
type FunctionResult<T extends FunctionName> = FunctionMap[T]['result'];
declare class ZAI {
private config;
chat: {
completions: {
create: (body: CreateChatCompletionBody) => Promise<any>;
};
};
images: {
generations: {
create: (body: CreateImageGenerationBody) => Promise<ImageGenerationResponse>;
};
};
functions: {
invoke: <T extends FunctionName>(function_name: T, args: FunctionArgs<T>) => Promise<FunctionResult<T>>;
};
private constructor();
static create(): Promise<ZAI>;
private createChatCompletion;
private createImageGeneration;
private downloadImageAsBase64;
private invokeFunction;
}
export default ZAI;
export type { ZAIConfig, ChatMessage, CreateChatCompletionBody, CreateImageGenerationBody, ImageGenerationResponse, SearchFunctionArgs, SearchFunctionResultItem, FunctionMap, FunctionName, FunctionArgs, FunctionResult, };