适配chat结构

This commit is contained in:
Sirius
2026-08-12 16:03:25 +08:00
parent 3e7a4c9540
commit f65ac095bb
5 changed files with 264 additions and 38 deletions
+5 -5
View File
@@ -291,7 +291,7 @@ interface StoredResponse {
input_items: ResponseInputItem[];
}
interface StructuredValidation {
export interface StructuredValidation {
validate: (text: string) => { valid: boolean; errors: string[] };
}
@@ -1107,14 +1107,14 @@ function buildResponsesPrompt(
].join("\n\n");
}
function buildRepairPrompt(
export function buildRepairPrompt(
originalPrompt: string,
format: ResponseTextFormat,
invalidOutput: string,
validationErrors: string[],
): string {
return [
"这是同一 Responses 请求的唯一一次结构化输出修复步骤。",
"这是同一请求的唯一一次结构化输出修复步骤。",
"保留原始答案的语义,只修复 JSON 语法和 Schema 违规;只返回修复后的 JSON,禁止代码围栏和解释。",
formatDirective(format),
"校验错误:",
@@ -1320,7 +1320,7 @@ async function executeAttempt(
};
}
function createStructuredValidation(format: ResponseTextFormat): StructuredValidation | undefined {
export function createStructuredValidation(format: ResponseTextFormat): StructuredValidation | undefined {
if (format.type === "text") return undefined;
if (format.type === "json_object") {
return {
@@ -1761,7 +1761,7 @@ function toResponseUsage(usage?: CommandUsage): ResponseUsage | null {
};
}
function addUsage(left?: CommandUsage, right?: CommandUsage): CommandUsage | undefined {
export function addUsage(left?: CommandUsage, right?: CommandUsage): CommandUsage | undefined {
if (!left && !right) return undefined;
return {
inputTokens: (left?.inputTokens ?? 0) + (right?.inputTokens ?? 0),