feat: 允许通过设置 systemTemplate 为空字符串来关闭系统消息

This commit is contained in:
WJG 2024-06-20 21:47:20 +08:00
parent 84a46b688b
commit 6e73ce8eee
No known key found for this signature in database
GPG Key ID: 258474EF8590014A

View File

@ -9,6 +9,7 @@ import { withDefault } from "../utils/base";
import { ChatCompletionCreateParamsBase } from "openai/resources/chat/completions";
import { Logger } from "../utils/log";
import { kProxyAgent } from "./proxy";
import { isNotEmpty } from "../utils/is";
export interface ChatOptions {
user: string;
@ -68,8 +69,8 @@ class OpenAIClient {
`🔥 onAskAI\n🤖 System: ${system ?? "None"}\n😊 User: ${user}`.trim()
);
}
const systemMsg: ChatCompletionMessageParam[] = system
? [{ role: "system", content: system }]
const systemMsg: ChatCompletionMessageParam[] = isNotEmpty(system)
? [{ role: "system", content: system! }]
: [];
let signal: AbortSignal | undefined;
if (requestId) {
@ -120,8 +121,8 @@ class OpenAIClient {
`🔥 onAskAI\n🤖 System: ${system ?? "None"}\n😊 User: ${user}`.trim()
);
}
const systemMsg: ChatCompletionMessageParam[] = system
? [{ role: "system", content: system }]
const systemMsg: ChatCompletionMessageParam[] = isNotEmpty(system)
? [{ role: "system", content: system! }]
: [];
const stream = await this._client!.chat.completions.create({
model,