MCPcopy Index your code
hub / github.com/simstudioai/sim / updateStateWithResponse

Function updateStateWithResponse

apps/sim/providers/gemini/core.ts:262–299  ·  view source on GitHub ↗

* Updates state with model response metadata

(
  state: ExecutionState,
  response: GenerateContentResponse,
  model: string,
  startTime: number,
  endTime: number
)

Source from the content-addressed store, hash-verified

260 * Updates state with model response metadata
261 */
262function updateStateWithResponse(
263 state: ExecutionState,
264 response: GenerateContentResponse,
265 model: string,
266 startTime: number,
267 endTime: number
268): ExecutionState {
269 const usage = convertUsageMetadata(response.usageMetadata)
270 const cost = calculateCost(model, usage.promptTokenCount, usage.candidatesTokenCount)
271 const duration = endTime - startTime
272
273 return {
274 ...state,
275 tokens: {
276 input: state.tokens.input + usage.promptTokenCount,
277 output: state.tokens.output + usage.candidatesTokenCount,
278 total: state.tokens.total + usage.totalTokenCount,
279 },
280 cost: {
281 input: state.cost.input + cost.input,
282 output: state.cost.output + cost.output,
283 total: state.cost.total + cost.total,
284 pricing: cost.pricing, // Use latest pricing
285 },
286 modelTime: state.modelTime + duration,
287 timeSegments: [
288 ...state.timeSegments,
289 {
290 type: 'model',
291 name: model,
292 startTime,
293 endTime,
294 duration,
295 },
296 ],
297 iterationCount: state.iterationCount + 1,
298 }
299}
300
301/**
302 * Builds config for next iteration

Callers 1

executeGeminiRequestFunction · 0.85

Calls 2

convertUsageMetadataFunction · 0.90
calculateCostFunction · 0.90

Tested by

no test coverage detected