Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
dynamo
Commits
c3ecaf6c
Unverified
Commit
c3ecaf6c
authored
Aug 13, 2025
by
Hongkuan Zhou
Committed by
GitHub
Aug 13, 2025
Browse files
feat: LLM metrics for non-streaming requests in frontend (#2427)
parent
72ec5f5c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
2 deletions
+20
-2
lib/llm/src/http/service/openai.rs
lib/llm/src/http/service/openai.rs
+20
-2
No files found.
lib/llm/src/http/service/openai.rs
View file @
c3ecaf6c
...
...
@@ -290,7 +290,11 @@ async fn completions(
Ok
(
sse_stream
.into_response
())
}
else
{
// TODO: report ISL/OSL for non-streaming requests
// Tap the stream to collect metrics for non-streaming requests without altering items
let
stream
=
stream
.inspect
(
move
|
response
|
{
process_metrics_only
(
response
,
&
mut
response_collector
);
});
let
response
=
NvCreateCompletionResponse
::
from_annotated_stream
(
stream
)
.await
.map_err
(|
e
|
{
...
...
@@ -515,7 +519,10 @@ async fn chat_completions(
Ok
(
sse_stream
.into_response
())
}
else
{
// TODO: report ISL/OSL for non-streaming requests
let
stream
=
stream
.inspect
(
move
|
response
|
{
process_metrics_only
(
response
,
&
mut
response_collector
);
});
let
response
=
NvCreateChatCompletionResponse
::
from_annotated_stream
(
stream
)
.await
.map_err
(|
e
|
{
...
...
@@ -911,6 +918,17 @@ impl<T> From<Annotated<T>> for EventConverter<T> {
}
}
fn
process_metrics_only
<
T
>
(
annotated
:
&
Annotated
<
T
>
,
response_collector
:
&
mut
ResponseMetricCollector
,
)
{
// 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
);
}
}
fn
process_event_converter
<
T
:
Serialize
>
(
annotated
:
EventConverter
<
T
>
,
response_collector
:
&
mut
ResponseMetricCollector
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment