支持CROS
This commit is contained in:
+11
-1
@@ -21,7 +21,17 @@ export class ChatCompletionSseWriter {
|
||||
|
||||
commandEvent(event: Record<string, unknown>): void {
|
||||
const chunks = this.accumulator.event(event);
|
||||
if (chunks) this.addText(chunks);
|
||||
if (event.type === "text_delta" && typeof event.delta === "string") {
|
||||
this.addText([event.delta]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.type !== "turn_end") return;
|
||||
if (event.hadToolCalls === true) {
|
||||
this.outputText = "";
|
||||
return;
|
||||
}
|
||||
if (chunks && this.outputText === "") this.addText(chunks);
|
||||
}
|
||||
|
||||
finish(finalText: string, usage?: CommandUsage, includeUsage = false): void {
|
||||
|
||||
@@ -67,6 +67,7 @@ export function buildCommandPrompt(request: ChatCompletionRequest): string {
|
||||
"严格执行 system 消息和最后一条 user 消息中的具体指令,并结合此前消息理解上下文。",
|
||||
"调用方可能要求改写问题、生成检索词、提取数据、分类或输出特定格式。这些属于内部处理任务,也必须严格执行。",
|
||||
"如果最后一条 user 消息要求改写、压缩、提取或输出指定格式,只返回要求的结果,不回答消息中包含的问题。",
|
||||
"如需调用工具,调用工具的 turn 只发起工具调用,不输出面向用户的文本;所有工具结束后,仅在不再调用工具的最终 turn 输出回答。",
|
||||
"不要复述 JSON,不要输出角色标签,不要添加指令未要求的解释或格式。",
|
||||
"JSON 数据开始:",
|
||||
JSON.stringify(envelope),
|
||||
|
||||
@@ -33,6 +33,14 @@ export async function createServer(config: BridgeConfig): Promise<BridgeServer>
|
||||
});
|
||||
const coordinator = new RequestCoordinator();
|
||||
|
||||
app.addHook("onRequest", async (_request, reply) => {
|
||||
reply.raw.setHeader("Access-Control-Allow-Origin", "*");
|
||||
reply.raw.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
|
||||
reply.raw.setHeader("Access-Control-Allow-Methods", "POST, OPTIONS");
|
||||
});
|
||||
|
||||
app.options("/*", async (_request, reply) => reply.status(204).send());
|
||||
|
||||
app.setErrorHandler((error, _request, reply) => {
|
||||
const fastifyError = error as Error & { code?: string; statusCode?: number };
|
||||
if (fastifyError.code === "FST_ERR_CTP_BODY_TOO_LARGE") {
|
||||
|
||||
Reference in New Issue
Block a user