mirror of
https://github.com/huggingface/text-generation-inference.git
synced 2025-09-11 12:24:53 +00:00
feat: accept variable content in chat request api
This commit is contained in:
parent
eade737714
commit
a480273047
1436
router/src/infer.rs
1436
router/src/infer.rs
File diff suppressed because it is too large
Load Diff
@ -525,7 +525,7 @@ impl ChatCompletion {
|
|||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
model: String,
|
model: String,
|
||||||
system_fingerprint: String,
|
system_fingerprint: String,
|
||||||
output: Option<String>,
|
_output: Option<String>,
|
||||||
created: u64,
|
created: u64,
|
||||||
details: Details,
|
details: Details,
|
||||||
return_logprobs: bool,
|
return_logprobs: bool,
|
||||||
@ -541,7 +541,7 @@ impl ChatCompletion {
|
|||||||
index: 0,
|
index: 0,
|
||||||
message: Message {
|
message: Message {
|
||||||
role: "assistant".into(),
|
role: "assistant".into(),
|
||||||
content: output,
|
content: None,
|
||||||
name: None,
|
name: None,
|
||||||
tool_calls,
|
tool_calls,
|
||||||
},
|
},
|
||||||
@ -867,9 +867,18 @@ pub(crate) struct Tool {
|
|||||||
pub function: FunctionDefinition,
|
pub function: FunctionDefinition,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// a serializeable version of Message
|
||||||
|
#[derive(Clone, Serialize, Deserialize, Default)]
|
||||||
|
pub(crate) struct SerializedMessage {
|
||||||
|
role: String,
|
||||||
|
content: String,
|
||||||
|
name: Option<String>,
|
||||||
|
tool_calls: Option<Vec<ToolCall>>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Serialize, Deserialize, Default)]
|
#[derive(Clone, Serialize, Deserialize, Default)]
|
||||||
pub(crate) struct ChatTemplateInputs<'a> {
|
pub(crate) struct ChatTemplateInputs<'a> {
|
||||||
messages: Vec<Message>,
|
messages: Vec<SerializedMessage>,
|
||||||
bos_token: Option<&'a str>,
|
bos_token: Option<&'a str>,
|
||||||
eos_token: Option<&'a str>,
|
eos_token: Option<&'a str>,
|
||||||
add_generation_prompt: bool,
|
add_generation_prompt: bool,
|
||||||
@ -884,13 +893,34 @@ pub(crate) struct ToolCall {
|
|||||||
pub function: FunctionDefinition,
|
pub function: FunctionDefinition,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Deserialize, ToSchema, Serialize)]
|
#[derive(Clone, Deserialize, Serialize, ToSchema, Default, Debug)]
|
||||||
|
pub(crate) struct Text {
|
||||||
|
#[serde(default)]
|
||||||
|
pub text: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Deserialize, Serialize, ToSchema, Default, Debug)]
|
||||||
|
pub(crate) struct ImageUrl {
|
||||||
|
#[serde(default)]
|
||||||
|
pub url: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Deserialize, Serialize, ToSchema, Default, Debug)]
|
||||||
|
pub(crate) struct Content {
|
||||||
|
pub r#type: String,
|
||||||
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
|
pub text: Option<String>,
|
||||||
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
|
pub image_url: Option<ImageUrl>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Deserialize, ToSchema, Serialize, Debug)]
|
||||||
pub(crate) struct Message {
|
pub(crate) struct Message {
|
||||||
#[schema(example = "user")]
|
#[schema(example = "user")]
|
||||||
pub role: String,
|
pub role: String,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
#[schema(example = "My name is David and I")]
|
#[schema(example = "My name is David and I")]
|
||||||
pub content: Option<String>,
|
pub content: Option<Vec<Content>>,
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
#[schema(example = "\"David\"")]
|
#[schema(example = "\"David\"")]
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
|
Loading…
Reference in New Issue
Block a user