bugfix
This commit is contained in:
@@ -505,8 +505,6 @@ export class AgentHarness {
|
||||
|
||||
const messagesCopy = [...messages];
|
||||
let iterations = 0;
|
||||
// Track last char of last yielded text chunk to detect missing spaces between tokens
|
||||
let lastChunkTail = '';
|
||||
|
||||
while (iterations < maxIterations) {
|
||||
if (signal?.aborted) break;
|
||||
@@ -525,24 +523,15 @@ export class AgentHarness {
|
||||
try {
|
||||
const stream = await model.stream(messagesCopy, { signal });
|
||||
for await (const chunk of stream) {
|
||||
const contents: string[] = [];
|
||||
if (typeof chunk.content === 'string' && chunk.content.length > 0) {
|
||||
contents.push(chunk.content);
|
||||
yield { type: 'chunk', content: chunk.content };
|
||||
} else if (Array.isArray(chunk.content)) {
|
||||
for (const block of chunk.content) {
|
||||
if (block.type === 'text' && block.text) contents.push(block.text);
|
||||
if (block.type === 'text' && block.text) {
|
||||
yield { type: 'chunk', content: block.text };
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const content of contents) {
|
||||
// DeepInfra/GLM streams tokens without leading spaces; inject one when
|
||||
// both the tail of the previous chunk and the head of this chunk are
|
||||
// word characters (\w), which would otherwise merge two words.
|
||||
if (lastChunkTail && /\w/.test(lastChunkTail) && /\w/.test(content[0])) {
|
||||
yield { type: 'chunk', content: ' ' };
|
||||
}
|
||||
lastChunkTail = content[content.length - 1];
|
||||
yield { type: 'chunk', content };
|
||||
}
|
||||
response = response ? response.concat(chunk) : chunk;
|
||||
}
|
||||
} catch (invokeError: any) {
|
||||
@@ -700,7 +689,6 @@ export class AgentHarness {
|
||||
|
||||
// After all tool calls complete, emit a space separator before the next LLM streaming pass
|
||||
yield { type: 'chunk', content: ' ' };
|
||||
lastChunkTail = ' ';
|
||||
}
|
||||
|
||||
// Max iterations reached - yield done with apology
|
||||
|
||||
Reference in New Issue
Block a user