Unverified Commit b051a213 authored by Hongkuan Zhou's avatar Hongkuan Zhou Committed by GitHub
Browse files

fix: remove LLMMetricAnnotation from response stream (#1499)


Signed-off-by: default avatarHongkuan Zhou <tedzhouhk@gmail.com>
parent fcfc21f2
...@@ -499,12 +499,19 @@ fn process_event_converter<T: Serialize>( ...@@ -499,12 +499,19 @@ fn process_event_converter<T: Serialize>(
annotated: EventConverter<T>, annotated: EventConverter<T>,
response_collector: &mut ResponseMetricCollector, response_collector: &mut ResponseMetricCollector,
) -> Result<Event, axum::Error> { ) -> Result<Event, axum::Error> {
let annotated = annotated.0; let mut annotated = annotated.0;
// update metrics // update metrics
if let Ok(Some(metrics)) = LLMMetricAnnotation::from_annotation(&annotated) { if let Ok(Some(metrics)) = LLMMetricAnnotation::from_annotation(&annotated) {
response_collector.observe_current_osl(metrics.output_tokens); response_collector.observe_current_osl(metrics.output_tokens);
response_collector.observe_response(metrics.input_tokens, metrics.chunk_tokens); response_collector.observe_response(metrics.input_tokens, metrics.chunk_tokens);
// Chomp the LLMMetricAnnotation so it's not returned in the response stream
// TODO: add a flag to control what is returned in the SSE stream
if annotated.event.as_deref() == Some(crate::preprocessor::ANNOTATION_LLM_METRICS) {
annotated.event = None;
annotated.comment = None;
}
} }
let mut event = Event::default(); let mut event = Event::default();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment