import { default as OpenAI } from 'openai'; import { Stream } from 'openai/streaming'; import { APIResource } from '../../../resource'; export declare class Completions extends APIResource { protected resources: Record; protected system: string; /** * Creates a model response for the given chat conversation. * * See https://api.minimax.chat/document/guides/chat-model/chat/api */ create(body: ChatCompletionCreateParamsNonStreaming, options?: OpenAI.RequestOptions): Promise; create(body: ChatCompletionCreateParamsStreaming, options?: OpenAI.RequestOptions): Promise>; protected buildCreateParams(params: ChatCompletionCreateParams): ChatCompletions.ChatCompletionCreateParams; static fromResponse(model: ChatModel, data: ChatCompletions.ChatCompletion): OpenAI.ChatCompletion; static fromSSEResponse(model: ChatModel, response: Response, controller: AbortController): Stream; } export interface ChatCompletionCreateParamsNonStreaming extends OpenAI.ChatCompletionCreateParamsNonStreaming { model: ChatModel; } export interface ChatCompletionCreateParamsStreaming extends OpenAI.ChatCompletionCreateParamsStreaming { model: ChatModel; } export type ChatCompletionCreateParams = ChatCompletionCreateParamsNonStreaming | ChatCompletionCreateParamsStreaming; export type ChatModel = 'abab5-chat' | 'abab5.5-chat' | 'abab5.5-chat-pro'; export declare namespace ChatCompletions { type ChatMessage = { sender_type: 'USER' | 'BOT' | 'FUNCTION'; sender_name?: string; text: string; }; interface ChatCompletionCreateParams { /** * 模型名称 */ model: ChatModel; /** * 对话背景、人物或功能设定 * * 和 bot_setting 互斥 */ prompt?: string | null; /** * 对话 meta 信息 * * 和 bot_setting 互斥 */ role_meta?: { /** * 用户代称 */ user_name: string; /** * AI 代称 */ bot_name: string; }; /** * pro 模式下,可以设置 bot 的名称和内容 * * 和 prompt 互斥 */ bot_setting?: { bot_name: string; content: string; }[]; /** * pro 模式下,设置模型回复要求 */ reply_constraints?: { sender_type: string; sender_name: string; }; /** * 对话内容 */ messages: ChatMessage[]; /** * 如果为 true,则表明设置当前请求为续写模式,回复内容为传入 messages 的最后一句话的续写; * * 此时最后一句发送者不限制 USER,也可以为 BOT。 */ continue_last_message?: boolean | null; /** * 内容随机性 */ temperature?: number | null; /** * 生成文本的多样性 */ top_p?: number | null; /** * 最大生成token数,需要注意的是,这个参数并不会影响模型本身的生成效果, * * 而是仅仅通过以截断超出的 token 的方式来实现功能需要保证输入上文的 token 个数和这个值加一起小于 6144 或者 16384,否则请求会失败 */ tokens_to_generate?: number | null; /** * 对输出中易涉及隐私问题的文本信息进行脱敏, * * 目前包括但不限于邮箱、域名、链接、证件号、家庭住址等,默认 false,即开启脱敏 */ skip_info_mask?: boolean | null; /** * 对输出中易涉及隐私问题的文本信息进行打码, * * 目前包括但不限于邮箱、域名、链接、证件号、家庭住址等,默认true,即开启打码 */ mask_sensitive_info?: boolean | null; /** * 生成多少个结果;不设置默认为1,最大不超过4。 * * 由于 beam_width 生成多个结果,会消耗更多 token。 */ beam_width?: number | null; /** * 是否以流式接口的形式返回数据,默认 false */ stream?: boolean | null; /** * 是否使用标准 SSE 格式,设置为 true 时, * 流式返回的结果将以两个换行为分隔符。 * * 只有在 stream=true 时,此参数才会生效。 */ use_standard_sse?: boolean | null; } type ChatCompletionChoice = { index?: number; text: string; messages: { sender_type: 'BOT'; sender_name: string; text: string; }[]; finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call'; }; interface ChatCompletion { id: string; created: number; model: ChatModel; reply: string; choices: ChatCompletionChoice[]; usage: { /** * Number of tokens in the generated completion. */ completion_tokens: number; /** * Number of tokens in the prompt. */ prompt_tokens: number; /** * Total number of tokens used in the request (prompt + completion). */ total_tokens: number; }; input_sensitive: boolean; output_sensitive: boolean; base_resp: { status_code: number; status_msg: string; }; } type ChatCompletionChunkChoice = { index: number; delta: string; messages: { sender_type: 'BOT'; sender_name: string; text: string; }[]; finish_reason: 'stop' | 'length' | 'content_filter' | 'function_call' | null; }; interface ChatCompletionChunk { request_id: string; created: number; model: ChatModel; reply: string; choices: ChatCompletionChunkChoice[]; usage: { total_tokens: number; }; input_sensitive: false; output_sensitive: false; base_resp: { status_code: number; status_msg: string; }; } }