Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/llm/src/http/service/openai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,12 +499,19 @@ fn process_event_converter<T: Serialize>(
annotated: EventConverter<T>,
response_collector: &mut ResponseMetricCollector,
) -> Result<Event, axum::Error> {
let annotated = annotated.0;
let mut annotated = annotated.0;

// update metrics
if let Ok(Some(metrics)) = LLMMetricAnnotation::from_annotation(&annotated) {
response_collector.observe_current_osl(metrics.output_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();
Expand Down
Loading