fix(models): give an actionable diagnostic when output hits the token ceiling
A response stopped at finish_reason=length (or Messages max_tokens / Responses max_output_tokens) is still rejected whole - a complete leading tool call is never applied because a later call may be cut mid-argument. Previously the model only saw a generic incompleteness message and would repeat the same oversized multi-tool turn. Now these paths raise a shared output_truncated diagnostic telling the model to split proposals into one file per response. Regression covers streaming/non-streaming Chat, Responses and Messages, including the AB sample shape.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { createHash } from 'node:crypto';
|
||||
import { protocolFailure, normalizeProtocolResponse, validateModelResponse, reportedUsage } from './protocols.mjs';
|
||||
import { protocolFailure, outputTruncatedFailure, normalizeProtocolResponse, validateModelResponse, reportedUsage } from './protocols.mjs';
|
||||
import { httpFailure } from '../../server/diagnostics.mjs';
|
||||
import { upstreamCapture } from './upstream-error.mjs';
|
||||
import { messagesStream } from './messages-stream.mjs';
|
||||
@@ -155,6 +155,7 @@ export async function readModelStream(response, config, signal, onProgress, tool
|
||||
}
|
||||
value = terminal;
|
||||
} else {
|
||||
if (done && finish === 'length') throw outputTruncatedFailure('stream_interrupted');
|
||||
if (!done || !['stop', 'tool_calls'].includes(finish)) throw protocolFailure('Chat流未完整终结或达到输出上限,未执行工具。', 'stream_interrupted');
|
||||
value = { choices: [{ message: { role: 'assistant', content: text, ...(hasReasoning ? { reasoning_content: reasoning } : {}), ...(calls.size ? { tool_calls: [...calls.entries()].sort((a, b) => a[0] - b[0]).map(([, item]) => item) } : {}) }, finish_reason: finish }], usage };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user