Skip to content

Commit c55abac

Browse files
amihalikAaron Mihalikdrbh
authored
Added name field to OpenAI compatible API Messages (#1563)
# What does this PR do? Literally just adds the name field to the Message class. I verified this change by building a new docker container (using the `Dockerfile` in the repo) and trialing with a `chat_template` that uses the `name` field. Here's the previous behavior: Input messages: ``` { "messages": [ {"role": "system", "content": "You are a succinct but helpful AI Assistant listening to a chat server. Address everyone by @<username>"}, {"role": "user", "name": "Aaron", "content": "Hello There!"}, {"role": "assistant", "content": " Hello @aaron! How can I assist you today?"}, {"role": "user", "name": "Sally", "content": "Hiya everyone. Is @aaron is this room?"} ], "model": "meta-llama/Llama-2-7b-chat-hf" } ``` Response before the modification: ``` Hello @aaron! Yes, you are in the chat room. How can I assist you today? 😊 Hiya everyone! *waves* It's great to see you all here. Is there something on your mind that you'd like to talk about or ask? I'm here to listen and help in any way I can. 🤖 ``` Response after my modification: ``` Hello @sally! Yes, @aaron is currently in the chat room. How may I assist you today? ``` Fixes #1558 ## Before submitting - [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case). - [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests), Pull Request section? - [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link to it if that's the case. - [ ] Did you make sure to update the documentation with your changes? Here are the [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation). - [ ] Did you write any new necessary tests? ## Who can review? @Narsil --------- Co-authored-by: Aaron Mihalik <[email protected]> Co-authored-by: drbh <[email protected]>
1 parent cef0553 commit c55abac

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

router/src/infer.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,18 +800,22 @@ mod tests {
800800
Message {
801801
role: "user".to_string(),
802802
content: "Hi!".to_string(),
803+
name: None,
803804
},
804805
Message {
805806
role: "assistant".to_string(),
806807
content: "Hello how can I help?".to_string(),
808+
name: None,
807809
},
808810
Message {
809811
role: "user".to_string(),
810812
content: "What is Deep Learning?".to_string(),
813+
name: None,
811814
},
812815
Message {
813816
role: "assistant".to_string(),
814817
content: "magic!".to_string(),
818+
name: None,
815819
},
816820
],
817821
bos_token: Some("[BOS]"),
@@ -861,22 +865,27 @@ mod tests {
861865
Message {
862866
role: "user".to_string(),
863867
content: "Hi!".to_string(),
868+
name: None,
864869
},
865870
Message {
866871
role: "user".to_string(),
867872
content: "Hi again!".to_string(),
873+
name: None,
868874
},
869875
Message {
870876
role: "assistant".to_string(),
871877
content: "Hello how can I help?".to_string(),
878+
name: None,
872879
},
873880
Message {
874881
role: "user".to_string(),
875882
content: "What is Deep Learning?".to_string(),
883+
name: None,
876884
},
877885
Message {
878886
role: "assistant".to_string(),
879887
content: "magic!".to_string(),
888+
name: None,
880889
},
881890
],
882891
bos_token: Some("[BOS]"),
@@ -931,18 +940,22 @@ mod tests {
931940
Message {
932941
role: "user".to_string(),
933942
content: "Hi!".to_string(),
943+
name: None,
934944
},
935945
Message {
936946
role: "assistant".to_string(),
937947
content: "Hello how can I help?".to_string(),
948+
name: None,
938949
},
939950
Message {
940951
role: "user".to_string(),
941952
content: "What is Deep Learning?".to_string(),
953+
name: None,
942954
},
943955
Message {
944956
role: "assistant".to_string(),
945957
content: "magic!".to_string(),
958+
name: None,
946959
},
947960
],
948961
bos_token: Some("[BOS]"),
@@ -981,18 +994,22 @@ mod tests {
981994
Message {
982995
role: "user".to_string(),
983996
content: "Hi!".to_string(),
997+
name: None,
984998
},
985999
Message {
9861000
role: "assistant".to_string(),
9871001
content: "Hello how can I help?".to_string(),
1002+
name: None,
9881003
},
9891004
Message {
9901005
role: "user".to_string(),
9911006
content: "What is Deep Learning?".to_string(),
1007+
name: None,
9921008
},
9931009
Message {
9941010
role: "assistant".to_string(),
9951011
content: "magic!".to_string(),
1012+
name: None,
9961013
},
9971014
],
9981015
bos_token: Some("[BOS]"),

router/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ impl ChatCompletion {
378378
message: Message {
379379
role: "assistant".into(),
380380
content: output,
381+
name: None,
381382
},
382383
logprobs: return_logprobs
383384
.then(|| ChatCompletionLogprobs::from((details.tokens, details.top_tokens))),
@@ -453,6 +454,7 @@ fn default_request_messages() -> Vec<Message> {
453454
vec![Message {
454455
role: "user".to_string(),
455456
content: "My name is David and I".to_string(),
457+
name: None,
456458
}]
457459
}
458460

@@ -547,6 +549,8 @@ pub(crate) struct Message {
547549
pub role: String,
548550
#[schema(example = "My name is David and I")]
549551
pub content: String,
552+
#[schema(example = "\"David\"")]
553+
pub name: Option<String>,
550554
}
551555

552556
#[derive(Clone, Debug, Deserialize, ToSchema)]

0 commit comments

Comments
 (0)