feat: 大量优化和bug修复

This commit is contained in:
2026-05-23 22:23:29 +08:00
parent 92b063c4c4
commit fc71e924e7
39 changed files with 1381 additions and 302 deletions
+8 -4
View File
@@ -1,5 +1,5 @@
// server/utils/openai.ts - OpenAI Chat Completions 流式调用工具
import { getSysConfig } from "~~/server/utils/sysConfig";
import type { SysConfig } from "~~/server/utils/sysConfig";
/** 复用编码器计算 SSE data 字节长度,避免循环里频繁创建对象 */
const textEncoder = new TextEncoder();
@@ -46,16 +46,20 @@ export interface AskAnswerStreamResult {
*
* 对 OCS 客户端仍返回普通 JSON;流式只发生在服务端到 OpenAI 之间
* 这样既能更早读取上游内容,又不破坏 AnswererWrapper 的 handler 契约
*
* cfg 由调用方传入(通过 getUserEffectiveApiConfig 或 getSysConfig 获取),
* 不在此处直接读取系统配置,确保用户自定义配置可正确生效
*/
export const askAnswerStream = async ({
prompt,
systemPrompt
systemPrompt,
cfg
}: {
prompt: string;
systemPrompt: string;
/** 生效配置,由调用方传入;含 key 等敏感信息,不做日志 */
cfg: SysConfig;
}): Promise<AskAnswerStreamResult> => {
const cfg = await getSysConfig();
if (!cfg.openAiApiKey) {
throw new Error("OPENAI_API_KEY is not set.");
}