PabloRod11 commited on
Commit
b477459
·
verified ·
1 Parent(s): 89f2054

Show local generation progress and bound stage output length

Browse files
Files changed (1) hide show
  1. research.js +9 -3
research.js CHANGED
@@ -86,9 +86,15 @@ window.PocketResearch = (() => {
86
  let lastError;
87
  for(let attempt=0;attempt<2;attempt++) {
88
  try {
89
- const result=await engine.chat.completions.create({messages:[{role:'system',content:system},{role:'user',content:JSON.stringify({question:input.question,sources:contextSources,prior_stage_outputs:prior,correction:attempt?`Previous output was invalid: ${lastError?.message || String(lastError)}. Follow the schema and exact prior IDs.`:undefined})}],temperature:0.2,max_tokens:1100});
90
- if(result.choices[0].finish_reason==='length') throw new Error('Model output exceeded its token limit.');
91
- const output=JSON.parse(result.choices[0].message.content.trim().replace(/^```(?:json)?\s*/, '').replace(/\s*```$/, ''));
 
 
 
 
 
 
92
  validate(output,schemas[stage],sourceIDs);validateLinks(stage,output,prior);
93
  if(stage==='gap') output.gaps.forEach(gap=>{gap.evidence_status=contextSources.some(s=>s.abstract)?'AI interpretation; source support requires review':'No excerpts in model context; speculative search target';if(!contextSources.some(s=>s.abstract))gap.confidence='low';});
94
  if(stage==='architect') output.hypotheses.forEach(h=>h.evidence_status='Speculative proposal; not a validated finding');
 
86
  let lastError;
87
  for(let attempt=0;attempt<2;attempt++) {
88
  try {
89
+ const stream=await engine.chat.completions.create({messages:[{role:'system',content:system},{role:'user',content:JSON.stringify({question:input.question,sources:contextSources,prior_stage_outputs:prior,correction:attempt?`Previous output was invalid: ${lastError?.message || String(lastError)}. Follow the schema and exact prior IDs.`:undefined})}],temperature:0.2,max_tokens:stage==='framer'?350:stage==='scout'?450:850,stream:true});
90
+ let content='',finishReason=null,chunks=0;
91
+ for await(const chunk of stream) {
92
+ content+=chunk.choices[0]?.delta.content || '';
93
+ finishReason=chunk.choices[0]?.finish_reason || finishReason;
94
+ if(++chunks%25===0) progress(`Local AI: ${name} (${agents.length+1}/6), generating… ${chunks} chunks received`);
95
+ }
96
+ if(finishReason==='length') throw new Error('Model output exceeded its token limit.');
97
+ const output=JSON.parse(content.trim().replace(/^```(?:json)?\s*/, '').replace(/\s*```$/, ''));
98
  validate(output,schemas[stage],sourceIDs);validateLinks(stage,output,prior);
99
  if(stage==='gap') output.gaps.forEach(gap=>{gap.evidence_status=contextSources.some(s=>s.abstract)?'AI interpretation; source support requires review':'No excerpts in model context; speculative search target';if(!contextSources.some(s=>s.abstract))gap.confidence='low';});
100
  if(stage==='architect') output.hypotheses.forEach(h=>h.evidence_status='Speculative proposal; not a validated finding');