@@ -1877,6 +1877,28 @@ async def _user_turn_completed_task(
18771877 transcript_confidence = info .transcript_confidence ,
18781878 )
18791879
1880+
1881+ metrics_report : llm .MetricsReport = {}
1882+ if self .stt :
1883+ metrics_report ["stt_metadata" ] = {
1884+ "model_name" : self .stt .model ,
1885+ "model_provider" : self .stt .provider ,
1886+ }
1887+ if info .started_speaking_at is not None :
1888+ metrics_report ["started_speaking_at" ] = info .started_speaking_at
1889+
1890+ if info .stopped_speaking_at is not None :
1891+ metrics_report ["stopped_speaking_at" ] = info .stopped_speaking_at
1892+
1893+ if info .transcription_delay is not None :
1894+ metrics_report ["transcription_delay" ] = info .transcription_delay
1895+
1896+ if info .end_of_turn_delay is not None :
1897+ metrics_report ["end_of_turn_delay" ] = info .end_of_turn_delay
1898+
1899+ if user_message is not None :
1900+ user_message .metrics = metrics_report
1901+
18801902 if isinstance (self .llm , llm .RealtimeModel ):
18811903 if self .llm .capabilities .turn_detection :
18821904 return
@@ -1936,6 +1958,7 @@ async def _user_turn_completed_task(
19361958 return
19371959
19381960 on_user_turn_completed_delay = time .perf_counter () - start_time
1961+ metrics_report ["on_user_turn_completed_delay" ] = on_user_turn_completed_delay
19391962
19401963 if isinstance (self .llm , llm .RealtimeModel ):
19411964 # ignore stt transcription for realtime model
@@ -1953,29 +1976,6 @@ async def _user_turn_completed_task(
19531976 self ._session ._conversation_item_added (user_message )
19541977 return
19551978
1956- metrics_report : llm .MetricsReport = {}
1957- if self .stt :
1958- metrics_report ["stt_metadata" ] = {
1959- "model_name" : self .stt .model ,
1960- "model_provider" : self .stt .provider ,
1961- }
1962- if info .started_speaking_at is not None :
1963- metrics_report ["started_speaking_at" ] = info .started_speaking_at
1964-
1965- if info .stopped_speaking_at is not None :
1966- metrics_report ["stopped_speaking_at" ] = info .stopped_speaking_at
1967-
1968- if info .transcription_delay is not None :
1969- metrics_report ["transcription_delay" ] = info .transcription_delay
1970-
1971- if info .end_of_turn_delay is not None :
1972- metrics_report ["end_of_turn_delay" ] = info .end_of_turn_delay
1973-
1974- metrics_report ["on_user_turn_completed_delay" ] = on_user_turn_completed_delay
1975-
1976- if user_message is not None :
1977- user_message .metrics = metrics_report
1978-
19791979 speech_handle : SpeechHandle | None = None
19801980 if preemptive := self ._preemptive_generation :
19811981 # make sure the on_user_turn_completed didn't change some request parameters
0 commit comments