export type CreateApiV1PlaygroundChatCompletionsArgs = {body: {apiKeyId: string | number, frequency_penalty?: number | undefined, max_tokens?: number | undefined, messages: Array<{content: string | Array>, role: 'system' | 'user' | 'assistant' | 'tool'}>, model: string, presence_penalty?: number | undefined, stream?: boolean | undefined, temperature?: number | undefined, top_p?: number | undefined}}; export type CreateApiV1PlaygroundChatCompletionsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * 模型广场聊天代理 * * POST /v1/playground/chat/completions */ export const createApiV1PlaygroundChatCompletions = async (args: CreateApiV1PlaygroundChatCompletionsArgs, options: CreateApiV1PlaygroundChatCompletionsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/playground/chat/completions${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };