@h-lumos/llm-sdk
Version:
95 lines (93 loc) • 3.29 kB
TypeScript
import { default as OpenAI } from 'openai';
import { Stream } from 'openai/streaming';
import { APIResource } from '../../resource';
export declare class Completions extends APIResource {
/**
* Creates a model response for the given chat conversation.
*
* See https://cloud.tencent.com/document/product/1729/97732
*/
create(body: ChatCompletionCreateParamsNonStreaming, options?: OpenAI.RequestOptions): Promise<OpenAI.ChatCompletion>;
create(body: ChatCompletionCreateParamsStreaming, options?: OpenAI.RequestOptions): Promise<Stream<OpenAI.ChatCompletionChunk>>;
static fromSSEResponse(model: string, stream: Stream<ChatCompletions.ChatCompletion>, controller: AbortController): Stream<OpenAI.ChatCompletionChunk>;
static fromResponse(model: string, data: ChatCompletions.ChatCompletion): OpenAI.ChatCompletion;
protected hash(data: string): string;
}
export interface ChatCompletionCreateParamsNonStreaming extends OpenAI.ChatCompletionCreateParamsNonStreaming {
model: ChatModel;
}
export interface ChatCompletionCreateParamsStreaming extends OpenAI.ChatCompletionCreateParamsStreaming {
model: ChatModel;
}
export type ChatCompletionCreateParams = ChatCompletionCreateParamsNonStreaming | ChatCompletionCreateParamsStreaming;
export type ChatModel = 'hunyuan';
export declare namespace ChatCompletions {
interface ChatCompletionCreateParams {
/**
* 腾讯云账号的 APPID
*/
app_id: number;
/**
* API 密钥
*/
secret_id: string;
/**
* 当前 UNIX 时间戳,单位为秒,可记录发起 API 请求的时间。
*/
timestamp: number;
/**
* 签名的有效期,是一个符合 UNIX Epoch 时间戳规范的数值,单位为秒;Expired 必须与 Timestamp 的差值小于90天
*/
expired: number;
/**
* 请求 ID,用于问题排查
*/
query_id?: string;
/**
* 内容随机性
*/
temperature?: number | null;
/**
* 生成结果的多样性
*/
top_p?: number | null;
/**
* 是否返回流式结果
*
* 0:同步,1:流式 (默认,协议:SSE)
*
* 同步请求超时:60s,如果内容较长建议使用流式
*/
stream?: number | null;
/**
* 会话内容, 按对话时间序排列,长度最多为40
* 最大支持16k tokens上下文
*/
messages: OpenAI.ChatCompletionMessageParam[];
}
type CompletionChoicesDelta = {
content: string;
};
type CompletionChoice = {
finish_reason: 'stop';
/**
* 内容,同步模式返回内容,流模式为 null
*/
messages: OpenAI.ChatCompletionMessage;
/**
* 内容,流模式返回内容,同步模式为 null
*/
delta: CompletionChoicesDelta;
};
interface ChatCompletion {
choices: CompletionChoice[];
created: string;
note: string;
id: string;
usage: OpenAI.CompletionUsage;
error?: {
message: string;
code: number;
};
}
}