Unverified Commit c55abac3 authored by Aaron Mihalik's avatar Aaron Mihalik Committed by GitHub
Browse files

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: default avatarAaron Mihalik <aaron.mihalik@parsons.us>
Co-authored-by: default avatardrbh <david.richard.holtz@gmail.com>
parent cef0553d
...@@ -800,18 +800,22 @@ mod tests { ...@@ -800,18 +800,22 @@ mod tests {
Message { Message {
role: "user".to_string(), role: "user".to_string(),
content: "Hi!".to_string(), content: "Hi!".to_string(),
name: None,
}, },
Message { Message {
role: "assistant".to_string(), role: "assistant".to_string(),
content: "Hello how can I help?".to_string(), content: "Hello how can I help?".to_string(),
name: None,
}, },
Message { Message {
role: "user".to_string(), role: "user".to_string(),
content: "What is Deep Learning?".to_string(), content: "What is Deep Learning?".to_string(),
name: None,
}, },
Message { Message {
role: "assistant".to_string(), role: "assistant".to_string(),
content: "magic!".to_string(), content: "magic!".to_string(),
name: None,
}, },
], ],
bos_token: Some("[BOS]"), bos_token: Some("[BOS]"),
...@@ -861,22 +865,27 @@ mod tests { ...@@ -861,22 +865,27 @@ mod tests {
Message { Message {
role: "user".to_string(), role: "user".to_string(),
content: "Hi!".to_string(), content: "Hi!".to_string(),
name: None,
}, },
Message { Message {
role: "user".to_string(), role: "user".to_string(),
content: "Hi again!".to_string(), content: "Hi again!".to_string(),
name: None,
}, },
Message { Message {
role: "assistant".to_string(), role: "assistant".to_string(),
content: "Hello how can I help?".to_string(), content: "Hello how can I help?".to_string(),
name: None,
}, },
Message { Message {
role: "user".to_string(), role: "user".to_string(),
content: "What is Deep Learning?".to_string(), content: "What is Deep Learning?".to_string(),
name: None,
}, },
Message { Message {
role: "assistant".to_string(), role: "assistant".to_string(),
content: "magic!".to_string(), content: "magic!".to_string(),
name: None,
}, },
], ],
bos_token: Some("[BOS]"), bos_token: Some("[BOS]"),
...@@ -931,18 +940,22 @@ mod tests { ...@@ -931,18 +940,22 @@ mod tests {
Message { Message {
role: "user".to_string(), role: "user".to_string(),
content: "Hi!".to_string(), content: "Hi!".to_string(),
name: None,
}, },
Message { Message {
role: "assistant".to_string(), role: "assistant".to_string(),
content: "Hello how can I help?".to_string(), content: "Hello how can I help?".to_string(),
name: None,
}, },
Message { Message {
role: "user".to_string(), role: "user".to_string(),
content: "What is Deep Learning?".to_string(), content: "What is Deep Learning?".to_string(),
name: None,
}, },
Message { Message {
role: "assistant".to_string(), role: "assistant".to_string(),
content: "magic!".to_string(), content: "magic!".to_string(),
name: None,
}, },
], ],
bos_token: Some("[BOS]"), bos_token: Some("[BOS]"),
...@@ -981,18 +994,22 @@ mod tests { ...@@ -981,18 +994,22 @@ mod tests {
Message { Message {
role: "user".to_string(), role: "user".to_string(),
content: "Hi!".to_string(), content: "Hi!".to_string(),
name: None,
}, },
Message { Message {
role: "assistant".to_string(), role: "assistant".to_string(),
content: "Hello how can I help?".to_string(), content: "Hello how can I help?".to_string(),
name: None,
}, },
Message { Message {
role: "user".to_string(), role: "user".to_string(),
content: "What is Deep Learning?".to_string(), content: "What is Deep Learning?".to_string(),
name: None,
}, },
Message { Message {
role: "assistant".to_string(), role: "assistant".to_string(),
content: "magic!".to_string(), content: "magic!".to_string(),
name: None,
}, },
], ],
bos_token: Some("[BOS]"), bos_token: Some("[BOS]"),
......
...@@ -378,6 +378,7 @@ impl ChatCompletion { ...@@ -378,6 +378,7 @@ impl ChatCompletion {
message: Message { message: Message {
role: "assistant".into(), role: "assistant".into(),
content: output, content: output,
name: None,
}, },
logprobs: return_logprobs logprobs: return_logprobs
.then(|| ChatCompletionLogprobs::from((details.tokens, details.top_tokens))), .then(|| ChatCompletionLogprobs::from((details.tokens, details.top_tokens))),
...@@ -453,6 +454,7 @@ fn default_request_messages() -> Vec<Message> { ...@@ -453,6 +454,7 @@ fn default_request_messages() -> Vec<Message> {
vec![Message { vec![Message {
role: "user".to_string(), role: "user".to_string(),
content: "My name is David and I".to_string(), content: "My name is David and I".to_string(),
name: None,
}] }]
} }
...@@ -547,6 +549,8 @@ pub(crate) struct Message { ...@@ -547,6 +549,8 @@ pub(crate) struct Message {
pub role: String, pub role: String,
#[schema(example = "My name is David and I")] #[schema(example = "My name is David and I")]
pub content: String, pub content: String,
#[schema(example = "\"David\"")]
pub name: Option<String>,
} }
#[derive(Clone, Debug, Deserialize, ToSchema)] #[derive(Clone, Debug, Deserialize, ToSchema)]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment