@@ -36,7 +36,6 @@ export class _LLMGenerationData {
3636 generatedText : string = '' ;
3737 generatedToolCalls : FunctionCall [ ] ;
3838 id : string ;
39- // Time to first token in seconds (for TTFT span attribute)
4039 ttft ?: number ;
4140
4241 constructor (
@@ -382,16 +381,14 @@ export function updateInstructions(options: {
382381 }
383382}
384383
385- // Ref: python livekit-agents/livekit/agents/voice/generation.py - lines 3-7 (diff)
386- // Added model and provider parameters to generation functions
387384export function performLLMInference (
388385 node : LLMNode ,
389386 chatCtx : ChatContext ,
390387 toolCtx : ToolContext ,
391388 modelSettings : ModelSettings ,
392389 controller : AbortController ,
393- model ?: string , // Ref: line 5 (model: str | None = None)
394- provider ?: string , // Ref: line 6 (provider: str | None = None)
390+ model ?: string ,
391+ provider ?: string ,
395392) : [ Task < void > , _LLMGenerationData ] {
396393 const textStream = new IdentityTransform < string > ( ) ;
397394 const toolCallStream = new IdentityTransform < FunctionCall > ( ) ;
@@ -407,20 +404,15 @@ export function performLLMInference(
407404 ) ;
408405 span . setAttribute ( traceTypes . ATTR_FUNCTION_TOOLS , JSON . stringify ( Object . keys ( toolCtx ) ) ) ;
409406
410- // Ref: python livekit-agents/livekit/agents/voice/generation.py - lines 36-48 (diff)
411- // Set model/provider attributes on the span
412407 if ( model ) {
413- // Ref: lines 44-45
414408 span . setAttribute ( traceTypes . ATTR_GEN_AI_REQUEST_MODEL , model ) ;
415409 }
416410 if ( provider ) {
417- // Ref: lines 46-47
418411 span . setAttribute ( traceTypes . ATTR_GEN_AI_PROVIDER_NAME , provider ) ;
419412 }
420413
421414 let llmStreamReader : ReadableStreamDefaultReader < string | ChatChunk > | null = null ;
422415 let llmStream : ReadableStream < string | ChatChunk > | null = null ;
423- // Track start time for TTFT calculation
424416 const startTime = performance . now ( ) / 1000 ; // Convert to seconds
425417 let firstTokenReceived = false ;
426418
@@ -445,7 +437,6 @@ export function performLLMInference(
445437 const { done, value : chunk } = result ;
446438 if ( done ) break ;
447439
448- // Track time to first token
449440 if ( ! firstTokenReceived ) {
450441 firstTokenReceived = true ;
451442 data . ttft = performance . now ( ) / 1000 - startTime ;
@@ -521,35 +512,28 @@ export function performLLMInference(
521512 ] ;
522513}
523514
524- // Ref: python livekit-agents/livekit/agents/voice/generation.py - lines 77-82 (diff)
525- // Added model and provider parameters for TTS generation
526515export function performTTSInference (
527516 node : TTSNode ,
528517 text : ReadableStream < string > ,
529518 modelSettings : ModelSettings ,
530519 controller : AbortController ,
531- model ?: string , // Ref: line 79 (model: str | None = None)
532- provider ?: string , // Ref: line 80 (provider: str | None = None)
520+ model ?: string ,
521+ provider ?: string ,
533522) : [ Task < void > , ReadableStream < AudioFrame > ] {
534523 const audioStream = new IdentityTransform < AudioFrame > ( ) ;
535524 const outputWriter = audioStream . writable . getWriter ( ) ;
536525 const audioOutputStream = audioStream . readable ;
537526
538527 const _performTTSInferenceImpl = async ( signal : AbortSignal , span : Span ) => {
539- // Ref: python livekit-agents/livekit/agents/voice/generation.py - lines 77-82 (diff)
540- // Set model/provider attributes on the span
541528 if ( model ) {
542- // Ref: lines 79-80
543529 span . setAttribute ( traceTypes . ATTR_GEN_AI_REQUEST_MODEL , model ) ;
544530 }
545531 if ( provider ) {
546- // Ref: lines 81-82
547532 span . setAttribute ( traceTypes . ATTR_GEN_AI_PROVIDER_NAME , provider ) ;
548533 }
549534
550535 let ttsStreamReader : ReadableStreamDefaultReader < AudioFrame > | null = null ;
551536 let ttsStream : ReadableStream < AudioFrame > | null = null ;
552- // Track start time for TTFB calculation
553537 const startTime = performance . now ( ) / 1000 ; // Convert to seconds
554538 let firstByteReceived = false ;
555539
@@ -570,7 +554,6 @@ export function performTTSInference(
570554 break ;
571555 }
572556
573- // Track time to first byte and set span attribute
574557 if ( ! firstByteReceived ) {
575558 firstByteReceived = true ;
576559 const ttfb = performance . now ( ) / 1000 - startTime ;
@@ -663,7 +646,6 @@ export function performTextForwarding(
663646
664647export interface _AudioOut {
665648 audio : Array < AudioFrame > ;
666- /** Future that will be set with the timestamp of the first frame's capture */
667649 firstFrameFut : Future < number > ;
668650}
669651
@@ -751,7 +733,6 @@ export function performAudioForwarding(
751733 ] ;
752734}
753735
754- // function_tool span is already implemented in tracableToolExecution below (line ~796)
755736export function performToolExecutions ( {
756737 session,
757738 speechHandle,
0 commit comments