MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / handleFireworksNonStream

Function handleFireworksNonStream

web/src/llm-api/fireworks.ts:254–342  ·  view source on GitHub ↗
({
  body,
  userId,
  stripeCustomerId,
  agentId,
  fetch,
  logger,
  insertMessageBigquery,
}: {
  body: ChatCompletionRequestBody
  userId: string
  stripeCustomerId?: string | null
  agentId: string
  fetch: typeof globalThis.fetch
  logger: Logger
  insertMessageBigquery: InsertMessageBigqueryFn
})

Source from the content-addressed store, hash-verified

252}
253
254export async function handleFireworksNonStream({
255 body,
256 userId,
257 stripeCustomerId,
258 agentId,
259 fetch,
260 logger,
261 insertMessageBigquery,
262}: {
263 body: ChatCompletionRequestBody
264 userId: string
265 stripeCustomerId?: string | null
266 agentId: string
267 fetch: typeof globalThis.fetch
268 logger: Logger
269 insertMessageBigquery: InsertMessageBigqueryFn
270}) {
271 const originalModel = body.model
272 const startTime = new Date()
273 const { clientId, clientRequestId, costMode } = extractRequestMetadata({
274 body,
275 logger,
276 })
277 const auditRequest = createRequestAuditRecord(body)
278
279 const response = await createFireworksRequestWithFallback({
280 body,
281 originalModel,
282 fetch,
283 logger,
284 sessionId: userId,
285 })
286
287 if (!response.ok) {
288 throw await parseFireworksError(response)
289 }
290
291 const data = await response.json()
292 const content = data.choices?.[0]?.message?.content ?? ''
293 const reasoningText =
294 data.choices?.[0]?.message?.reasoning_content ??
295 data.choices?.[0]?.message?.reasoning ??
296 ''
297 const usageData = extractUsageAndCost(data.usage, originalModel)
298
299 insertMessageToBigQuery({
300 messageId: data.id,
301 userId,
302 startTime,
303 request: auditRequest,
304 reasoningText,
305 responseText: content,
306 usageData,
307 logger,
308 insertMessageBigquery,
309 }).catch((error) => {
310 logger.error({ error }, 'Failed to insert message into BigQuery')
311 })

Callers 1

postChatCompletionsFunction · 0.90

Calls 8

extractRequestMetadataFunction · 0.90
insertMessageToBigQueryFunction · 0.90
consumeCreditsForMessageFunction · 0.90
createRequestAuditRecordFunction · 0.85
parseFireworksErrorFunction · 0.85
extractUsageAndCostFunction · 0.70
creditsToFakeCostFunction · 0.70

Tested by

no test coverage detected