Download src/services/batch-loop-checkpoint.js from VanyaJ/bada-terminal: direct link, hf CLI and curl.
- Browser
- Download file 2.74 kB
-
https://huggingface.co/VanyaJ/bada-terminal/resolve/main/src/services/batch-loop-checkpoint.js
- Command line
-
hf download hf://VanyaJ/bada-terminal/src/services/batch-loop-checkpoint.js
-
curl -L -o batch-loop-checkpoint.js https://huggingface.co/VanyaJ/bada-terminal/resolve/main/src/services/batch-loop-checkpoint.js
2.74 kB
| // ๊ฒํ ์ controller๋ฅผ ์์ฑํ๊ฑฐ๋ HUD/๊ธฐ์ต ์๋ฆผ์ ๋ณด๋ด์ง ์๋๋ค. ์ค์ ์คํ๋ง ์ค๋ ์ท์ ์์ฑํ๋ค. | |
| // ์ค๋ช ๋ฌธ์: docs/specs/batch-step-continuation.md (v0.18.0, R67 ์งํ ์ค) | |
| const db=require('../../knowledge-db'),{hash}=require('./bong-browser-resolution'); | |
| function create(checkpoint,run,controller,ledger){ | |
| return(phase,iteration,{history,meta,result=null})=>checkpoint.loopEvent({iteration,phase,controller:{currentIteration:controller.circuitBreaker.currentIteration,cumulativeCost:controller.circuitBreaker.cumulativeCost,cumulativeTokens:controller.circuitBreaker.cumulativeTokens,consecutiveFailures:controller.circuitBreaker.consecutiveFailures,startTime:controller.circuitBreaker.startTime,metricHistory:Object.fromEntries(controller.circuitBreaker.metricHistory),hasWarnedBudget:controller.hasWarnedBudget,iterationResults:controller.iterationResults},history,meta:meta??null,ledgerRun:db.getLoopRun(ledger.record.run_id),ledgerIteration:db.getLoopIterations(ledger.record.run_id).find(r=>r.iteration_number===iteration),result}); | |
| } | |
| function usage(event,actual){ | |
| const entries=(actual.usage.entries||[]).slice(0,event.usageIds.length),requests=Object.fromEntries(event.requestKeys.map(k=>[k,actual.requests?.[k]])); | |
| return hash(entries.map(e=>e.id))===hash(event.usageIds)&&hash({entries,requests})===event.usageHash; | |
| } | |
| function verify(c,actual,memory={}){ | |
| for(const event of Object.values(c.loopEvents||{})){ | |
| if(!usage(event,actual))throw Error('Unverified loop usage prefix'); | |
| if(['steps','evaluated','settled','committed'].includes(event.phase)){ | |
| const prefix=(actual.usage.entries||[]).slice(0,event.usageIds.length),cost=prefix.reduce((n,e)=>n+e.costUsd,0),tokens=prefix.reduce((n,e)=>n+(e.totalTokens||0),0); | |
| if(Math.abs(cost-event.controller.cumulativeCost)>1e-9||tokens!==event.controller.cumulativeTokens)throw Error('Unverified loop controller usage'); | |
| } | |
| if(event.phase==='evaluation_intent'||event.phase==='committed'){ | |
| const outputs={},steps=require('../db/batch-checkpoint-record').stepsFor({steps:c.definition.steps}); | |
| for(const key of event.entryKeys){const e=c.entries[key];if(e.iteration!==event.iteration)continue;const r=require('./batch-step-output').resolved(c,key,memory);if(r||e.status==='completed')outputs[e.stepId]=r?r.output:e.output;} | |
| if(steps.some(s=>!Object.hasOwn(outputs,s.id)))throw Error('Incomplete loop evaluation inputs'); | |
| if(event.phase==='committed'){ | |
| const saved=event.ledgerIteration.step_outputs,body=typeof saved==='string'?JSON.parse(saved):saved; | |
| if(!require('../db/batch-recovery-record').same(outputs,body))throw Error('Unverified loop iteration outputs'); | |
| } | |
| } | |
| } | |
| } | |
| module.exports={create,usage,verify}; | |