Skip to content

Commit 7624f93

Browse files
committed
fix: formatting
1 parent 9ba2b48 commit 7624f93

File tree

5 files changed

+36
-15
lines changed

5 files changed

+36
-15
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,10 @@ generated-values.yaml
9191
.build/
9292
**/.devcontainer/.env
9393
TensorRT-LLM
94+
95+
96+
# Ruler Generated Files
97+
/.cursor/instructions.md
98+
/.cursor/instructions.md.bak
99+
/CLAUDE.md
100+
/CLAUDE.md.bak

lib/llm/src/preprocessor.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,9 @@ impl OpenAIPreprocessor {
454454
);
455455

456456
// Check if this response has a finish_reason
457-
let has_finish_reason = response.data.as_ref()
457+
let has_finish_reason = response
458+
.data
459+
.as_ref()
458460
.map(|d| d.finish_reason.is_some())
459461
.unwrap_or(false);
460462

@@ -516,9 +518,10 @@ impl OpenAIPreprocessor {
516518
Some((response, inner))
517519
} else {
518520
// Stream has ended - check if we need to send a usage chunk
519-
if inner.response_generator.is_usage_enabled() &&
520-
inner.finish_reason_sent &&
521-
!inner.usage_chunk_sent {
521+
if inner.response_generator.is_usage_enabled()
522+
&& inner.finish_reason_sent
523+
&& !inner.usage_chunk_sent
524+
{
522525
inner.usage_chunk_sent = true;
523526

524527
// Create the final usage chunk

lib/llm/src/protocols/openai/chat_completions/delta.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ impl NvCreateChatCompletionRequest {
2020
/// * [`DeltaGenerator`] configured with model name and response options.
2121
pub fn response_generator(&self, request_id: String) -> DeltaGenerator {
2222
let options = DeltaGeneratorOptions {
23-
enable_usage: self.inner.stream_options
23+
enable_usage: self
24+
.inner
25+
.stream_options
2426
.as_ref()
2527
.map(|opts| opts.include_usage)
2628
.unwrap_or(false),
@@ -267,7 +269,7 @@ impl DeltaGenerator {
267269
model: self.model.clone(),
268270
system_fingerprint: self.system_fingerprint.clone(),
269271
choices,
270-
usage: None, // Always None for chunks with content/choices
272+
usage: None, // Always None for chunks with content/choices
271273
service_tier: self.service_tier.clone(),
272274
}
273275
}
@@ -287,7 +289,7 @@ impl DeltaGenerator {
287289
created: self.created,
288290
model: self.model.clone(),
289291
system_fingerprint: self.system_fingerprint.clone(),
290-
choices: vec![], // Empty choices for usage-only chunk
292+
choices: vec![], // Empty choices for usage-only chunk
291293
usage: Some(usage),
292294
service_tier: self.service_tier.clone(),
293295
}

lib/llm/src/protocols/openai/completions/delta.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ impl NvCreateCompletionRequest {
99
// inspect the request to extract options
1010
pub fn response_generator(&self, request_id: String) -> DeltaGenerator {
1111
let options = DeltaGeneratorOptions {
12-
enable_usage: self.inner.stream_options
12+
enable_usage: self
13+
.inner
14+
.stream_options
1315
.as_ref()
1416
.map(|opts| opts.include_usage)
1517
.unwrap_or(false),
@@ -161,7 +163,7 @@ impl DeltaGenerator {
161163
finish_reason,
162164
logprobs,
163165
}],
164-
usage: None, // Always None for chunks with content/choices
166+
usage: None, // Always None for chunks with content/choices
165167
};
166168

167169
NvCreateCompletionResponse { inner }
@@ -182,7 +184,7 @@ impl DeltaGenerator {
182184
created: self.created,
183185
model: self.model.clone(),
184186
system_fingerprint: self.system_fingerprint.clone(),
185-
choices: vec![], // Empty choices for usage-only chunk
187+
choices: vec![], // Empty choices for usage-only chunk
186188
usage: Some(usage),
187189
};
188190

lib/llm/tests/test_streaming_usage.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
use async_trait::async_trait;
45
use dynamo_async_openai::types::{
56
ChatCompletionRequestMessage, ChatCompletionRequestUserMessage,
67
ChatCompletionRequestUserMessageContent, ChatCompletionStreamOptions,
@@ -9,11 +10,10 @@ use dynamo_async_openai::types::{
910
use dynamo_llm::preprocessor::OpenAIPreprocessor;
1011
use dynamo_llm::protocols::common::llm_backend::{BackendOutput, FinishReason};
1112
use dynamo_llm::protocols::openai::chat_completions::NvCreateChatCompletionRequest;
12-
use async_trait::async_trait;
1313
use dynamo_runtime::engine::{AsyncEngineContext, AsyncEngineStream};
1414
use dynamo_runtime::protocols::annotated::Annotated;
15-
use futures::stream;
1615
use futures::StreamExt;
16+
use futures::stream;
1717
use std::pin::Pin;
1818
use std::sync::Arc;
1919
use std::sync::atomic::{AtomicBool, Ordering};
@@ -115,7 +115,11 @@ fn create_mock_backend_stream(
115115
},
116116
];
117117

118-
let stream = stream::iter(outputs.into_iter().map(|output| Annotated::from_data(output)));
118+
let stream = stream::iter(
119+
outputs
120+
.into_iter()
121+
.map(|output| Annotated::from_data(output)),
122+
);
119123

120124
use dynamo_runtime::engine::ResponseStream;
121125
ResponseStream::new(Box::pin(stream), ctx)
@@ -244,7 +248,10 @@ async fn test_streaming_with_usage_compliance() {
244248
usage.completion_tokens, 3,
245249
"Should have 3 completion tokens"
246250
);
247-
assert_eq!(usage.prompt_tokens, 0, "Should have 0 prompt tokens (not set in test)");
251+
assert_eq!(
252+
usage.prompt_tokens, 0,
253+
"Should have 0 prompt tokens (not set in test)"
254+
);
248255
assert_eq!(
249256
usage.total_tokens, 3,
250257
"Total tokens should be prompt + completion"
@@ -289,4 +296,4 @@ async fn test_streaming_with_usage_false() {
289296
);
290297
}
291298
}
292-
}
299+
}

0 commit comments

Comments
 (0)