fix: streaming

This commit is contained in:
Han Xiao 2025-02-09 15:23:26 +08:00
parent de2bc3771b
commit c2931c6e2a
3 changed files with 5 additions and 4 deletions

View File

@ -11,7 +11,7 @@
"defaults": {
"search_provider": "jina",
"llm_provider": "gemini",
"step_sleep": 1000
"step_sleep": 0
},
"providers": {
"gemini": {

View File

@ -312,7 +312,6 @@ export async function getResponse(question: string, tokenBudget: number = 1_000_
await sleep(STEP_SLEEP);
step++;
totalStep++;
context.actionTracker.trackAction({totalStep, thisStep, gaps, badAttempts});
const budgetPercentage = (context.tokenTracker.getTotalUsage() / tokenBudget * 100).toFixed(2);
console.log(`Step ${totalStep} / Budget used ${budgetPercentage}%`);
console.log('Gaps:', gaps);
@ -355,13 +354,15 @@ export async function getResponse(question: string, tokenBudget: number = 1_000_
object = result.object;
totalTokens = result.totalTokens;
}
context.tokenTracker.trackUsage('agent', totalTokens);
thisStep = object as StepAction;
// print allowed and chose action
const actionsStr = [allowSearch, allowRead, allowAnswer, allowReflect].map((a, i) => a ? ['search', 'read', 'answer', 'reflect'][i] : null).filter(a => a).join(', ');
console.log(`${thisStep.action} <- [${actionsStr}]`);
console.log(thisStep)
context.actionTracker.trackAction({totalStep, thisStep, gaps, badAttempts});
context.tokenTracker.trackUsage('agent', totalTokens);
// reset allowAnswer to true
allowAnswer = true;
allowReflect = true;

View File

@ -114,7 +114,7 @@ app.post('/v1/chat/completions', (async (req: Request, res: Response) => {
system_fingerprint: 'fp_' + requestId,
choices: [{
index: 0,
delta: { content: `${action.thisStep.think}` },
delta: { content: `${action.thisStep.think}\n` },
logprobs: null,
finish_reason: null
}]