Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dynamo
Commits
c13ea718
Commit
c13ea718
authored
Feb 27, 2025
by
Paul Hendricks
Committed by
GitHub
Feb 27, 2025
Browse files
refactor: rename ChatCompletionResponse to NvCreateChatCompletionResponse (#291)
parent
96866f43
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
18 additions
and
17 deletions
+18
-17
lib/llm/src/http/service/openai.rs
lib/llm/src/http/service/openai.rs
+2
-2
lib/llm/src/protocols/openai/chat_completions.rs
lib/llm/src/protocols/openai/chat_completions.rs
+1
-1
lib/llm/src/protocols/openai/chat_completions/aggregator.rs
lib/llm/src/protocols/openai/chat_completions/aggregator.rs
+7
-7
lib/llm/src/types.rs
lib/llm/src/types.rs
+3
-2
lib/llm/tests/aggregators.rs
lib/llm/tests/aggregators.rs
+5
-5
No files found.
lib/llm/src/http/service/openai.rs
View file @
c13ea718
...
...
@@ -41,7 +41,7 @@ use super::{
};
use
crate
::
protocols
::
openai
::{
chat_completions
::
ChatCompletionResponse
,
completions
::
CompletionResponse
,
chat_completions
::
NvCreate
ChatCompletionResponse
,
completions
::
CompletionResponse
,
};
use
crate
::
types
::{
openai
::{
chat_completions
::
NvCreateChatCompletionRequest
,
completions
::
CompletionRequest
},
...
...
@@ -272,7 +272,7 @@ async fn chat_completions(
.keep_alive
(
KeepAlive
::
default
())
.into_response
())
}
else
{
let
response
=
ChatCompletionResponse
::
from_annotated_stream
(
stream
.into
())
let
response
=
NvCreate
ChatCompletionResponse
::
from_annotated_stream
(
stream
.into
())
.await
.map_err
(|
e
|
{
tracing
::
error!
(
...
...
lib/llm/src/protocols/openai/chat_completions.rs
View file @
c13ea718
...
...
@@ -35,7 +35,7 @@ pub struct NvCreateChatCompletionRequest {
}
#[derive(Serialize,
Deserialize,
Validate,
Debug,
Clone)]
pub
struct
ChatCompletionResponse
{
pub
struct
NvCreate
ChatCompletionResponse
{
#[serde(flatten)]
pub
inner
:
async_openai
::
types
::
CreateChatCompletionResponse
,
}
...
...
lib/llm/src/protocols/openai/chat_completions/aggregator.rs
View file @
c13ea718
...
...
@@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use
super
::{
ChatCompletionResponse
,
ChatCompletionResponse
Delta
};
use
super
::{
ChatCompletionResponse
Delta
,
NvCreate
ChatCompletionResponse
};
use
crate
::
protocols
::{
codec
::{
Message
,
SseCodecError
},
convert_sse_stream
,
Annotated
,
...
...
@@ -69,7 +69,7 @@ impl DeltaAggregator {
/// Aggregates a stream of [`ChatCompletionResponseDelta`]s into a single [`ChatCompletionResponse`].
pub
async
fn
apply
(
stream
:
DataStream
<
Annotated
<
ChatCompletionResponseDelta
>>
,
)
->
Result
<
ChatCompletionResponse
,
String
>
{
)
->
Result
<
NvCreate
ChatCompletionResponse
,
String
>
{
let
aggregator
=
stream
.fold
(
DeltaAggregator
::
new
(),
|
mut
aggregator
,
delta
|
async
move
{
// these are cheap to move so we do it every time since we are consuming the delta
...
...
@@ -153,7 +153,7 @@ impl DeltaAggregator {
service_tier
:
aggregator
.service_tier
,
};
let
response
=
ChatCompletionResponse
{
inner
};
let
response
=
NvCreate
ChatCompletionResponse
{
inner
};
Ok
(
response
)
}
...
...
@@ -180,17 +180,17 @@ impl From<DeltaChoice> for async_openai::types::ChatChoice {
}
}
impl
ChatCompletionResponse
{
impl
NvCreate
ChatCompletionResponse
{
pub
async
fn
from_sse_stream
(
stream
:
DataStream
<
Result
<
Message
,
SseCodecError
>>
,
)
->
Result
<
ChatCompletionResponse
,
String
>
{
)
->
Result
<
NvCreate
ChatCompletionResponse
,
String
>
{
let
stream
=
convert_sse_stream
::
<
ChatCompletionResponseDelta
>
(
stream
);
ChatCompletionResponse
::
from_annotated_stream
(
stream
)
.await
NvCreate
ChatCompletionResponse
::
from_annotated_stream
(
stream
)
.await
}
pub
async
fn
from_annotated_stream
(
stream
:
DataStream
<
Annotated
<
ChatCompletionResponseDelta
>>
,
)
->
Result
<
ChatCompletionResponse
,
String
>
{
)
->
Result
<
NvCreate
ChatCompletionResponse
,
String
>
{
DeltaAggregator
::
apply
(
stream
)
.await
}
}
...
...
lib/llm/src/types.rs
View file @
c13ea718
...
...
@@ -38,12 +38,13 @@ pub mod openai {
use
super
::
*
;
pub
use
protocols
::
openai
::
chat_completions
::{
ChatCompletionResponse
,
ChatCompletionResponseDelta
,
NvCreateChatCompletionRequest
,
ChatCompletionResponseDelta
,
NvCreateChatCompletionRequest
,
NvCreateChatCompletionResponse
,
};
/// A [`UnaryEngine`] implementation for the OpenAI Chat Completions API
pub
type
OpenAIChatCompletionsUnaryEngine
=
UnaryEngine
<
NvCreateChatCompletionRequest
,
ChatCompletionResponse
>
;
UnaryEngine
<
NvCreateChatCompletionRequest
,
NvCreate
ChatCompletionResponse
>
;
/// A [`ServerStreamingEngine`] implementation for the OpenAI Chat Completions API
pub
type
OpenAIChatCompletionsStreamingEngine
=
ServerStreamingEngine
<
...
...
lib/llm/tests/aggregators.rs
View file @
c13ea718
...
...
@@ -16,7 +16,7 @@
use
futures
::
StreamExt
;
use
triton_distributed_llm
::
protocols
::{
codec
::{
create_message_stream
,
Message
,
SseCodecError
},
openai
::{
chat_completions
::
ChatCompletionResponse
,
completions
::
CompletionResponse
},
openai
::{
chat_completions
::
NvCreate
ChatCompletionResponse
,
completions
::
CompletionResponse
},
ContentProvider
,
DataStream
,
};
...
...
@@ -34,7 +34,7 @@ async fn test_openai_chat_stream() {
// note: we are only taking the first 16 messages to keep the size of the response small
let
stream
=
create_message_stream
(
&
data
)
.take
(
16
);
let
result
=
ChatCompletionResponse
::
from_sse_stream
(
Box
::
pin
(
stream
))
let
result
=
NvCreate
ChatCompletionResponse
::
from_sse_stream
(
Box
::
pin
(
stream
))
.await
.unwrap
();
...
...
@@ -57,7 +57,7 @@ async fn test_openai_chat_stream() {
#[tokio::test]
async
fn
test_openai_chat_edge_case_multi_line_data
()
{
let
stream
=
create_stream
(
CHAT_ROOT_PATH
,
"edge_cases/valid-multi-line-data"
);
let
result
=
ChatCompletionResponse
::
from_sse_stream
(
Box
::
pin
(
stream
))
let
result
=
NvCreate
ChatCompletionResponse
::
from_sse_stream
(
Box
::
pin
(
stream
))
.await
.unwrap
();
...
...
@@ -78,7 +78,7 @@ async fn test_openai_chat_edge_case_multi_line_data() {
#[tokio::test]
async
fn
test_openai_chat_edge_case_comments_per_response
()
{
let
stream
=
create_stream
(
CHAT_ROOT_PATH
,
"edge_cases/valid-comments_per_response"
);
let
result
=
ChatCompletionResponse
::
from_sse_stream
(
Box
::
pin
(
stream
))
let
result
=
NvCreate
ChatCompletionResponse
::
from_sse_stream
(
Box
::
pin
(
stream
))
.await
.unwrap
();
...
...
@@ -99,7 +99,7 @@ async fn test_openai_chat_edge_case_comments_per_response() {
#[tokio::test]
async
fn
test_openai_chat_edge_case_invalid_deserialize_error
()
{
let
stream
=
create_stream
(
CHAT_ROOT_PATH
,
"edge_cases/invalid-deserialize_error"
);
let
result
=
ChatCompletionResponse
::
from_sse_stream
(
Box
::
pin
(
stream
))
.await
;
let
result
=
NvCreate
ChatCompletionResponse
::
from_sse_stream
(
Box
::
pin
(
stream
))
.await
;
assert
!
(
result
.is_err
());
// insta::assert_debug_snapshot!(result);
...
...
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