Fix AI output showing UTF-8 bytes as hex escapes instead of Chinese.
Decode <0xE5><0xA7><0xA4> style model output to proper characters; add prompt rule to use normal Chinese text. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
import type { AiRequestBody } from "@/lib/ai/types";
|
||||
import { decodeHexByteEscapes } from "@/lib/ai/decode-text";
|
||||
|
||||
function emitText(text: string, onUpdate: (text: string) => void) {
|
||||
onUpdate(decodeHexByteEscapes(text));
|
||||
}
|
||||
|
||||
function parseApiError(text: string, status: number): string {
|
||||
const trimmed = text.trim();
|
||||
@@ -41,11 +46,11 @@ export async function streamAiCompletion(
|
||||
break;
|
||||
}
|
||||
text += decoder.decode(value, { stream: true });
|
||||
onUpdate(text);
|
||||
emitText(text, onUpdate);
|
||||
}
|
||||
|
||||
text += decoder.decode();
|
||||
onUpdate(text);
|
||||
emitText(text, onUpdate);
|
||||
|
||||
if (!text.trim()) {
|
||||
throw new Error("AI 返回内容为空,请检查模型配置或稍后重试");
|
||||
|
||||
Reference in New Issue
Block a user