stash save

This commit is contained in:
jhqxxx
2025-12-10 12:57:24 +08:00
parent 515d6da852
commit 3eb983b5bb
4 changed files with 89 additions and 10 deletions
+1
View File
@@ -102,6 +102,7 @@ impl<'a> ChatTemplate<'a> {
pub fn apply_chat_template(&self, messages: &ChatCompletionParameters) -> Result<String> {
let context = context! {
messages => &messages.messages,
tools => &messages.tools.as_ref(),
add_generation_prompt => true,
};
let template = self
+22
View File
@@ -171,6 +171,8 @@ impl<'a> GenerateModel for Qwen3VLGenerateModel<'a> {
let image_grid_thw = image_grid_thw.as_ref();
let mut pixel_values_video = pixel_values_video.as_ref();
let video_grid_thw = video_grid_thw.as_ref();
let mut tool_call_id = None;
let mut tool_call_content = String::new();
for _ in 0..sample_len {
let logits = self.qwen3_vl.forward(
&input_ids,
@@ -203,8 +205,28 @@ impl<'a> GenerateModel for Qwen3VLGenerateModel<'a> {
continue;
}
error_tokens.clear();
if decoded_token.as_str() == "<tool_call>" {
tool_call_id = Some(uuid::Uuid::new_v4().to_string());
continue;
} else {
if decoded_token.as_str() == "</tool_call>" {
let chunk = build_completion_chunk_response(decoded_token, &self.model_name, tool_call_id.clone(), Some(tool_call_content.clone()));
tool_call_id = None;
tool_call_content = String::new();
yield Ok(chunk);
}
else {
if tool_call_id.is_some() {
tool_call_content.push_str(&decoded_token);
continue;
}
else {
let chunk = build_completion_chunk_response(decoded_token, &self.model_name, None, None);
yield Ok(chunk);
}
}
}
if next_token == self.eos_token_id1 || next_token == self.eos_token_id2 {
break;
}
+30 -2
View File
@@ -19,11 +19,39 @@ fn gelab_zero_generate() -> Result<()> {
"content": [
{
"type": "text",
"text": "Hello, GELab-Zero!"
"text": "Hello, GELab-Zero!, 现在几点了"
}
]
}
]
],
"tools": [
{
"type": "function",
"function": {
"name": "get_current_time",
"description": "当你想知道现在的时间时非常有用。",
"parameters": {}
}
},
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "当你想查询指定城市的天气时非常有用。",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "城市或县区,比如北京市、杭州市、余杭区等。"
}
},
"required": ["location"]
}
}
}
],
"tool_choice": null
}
"#;
let mes: ChatCompletionParameters = serde_json::from_str(message)?;
+34 -6
View File
@@ -19,15 +19,15 @@ fn qwen3vl_generate() -> Result<()> {
"role": "user",
"content": [
{
"type": "video",
"video_url":
"type": "image",
"image_url":
{
"url": "./assets/video/video_test.mp4"
"url": "file://./assets/img/ocr_test1.png"
}
},
{
"type": "text",
"text": "视频里发生了什么"
"text": "请分析图片并提取所有可见文本内容,按从左到右、从上到下的布局,返回纯文本"
}
]
}
@@ -70,11 +70,39 @@ async fn qwen3vl_stream() -> Result<()> {
},
{
"type": "text",
"text": "视频中发生了什么?"
"text": "视频中发生了什么?, 现在几点了"
}
]
}
]
],
"tools": [
{
"type": "function",
"function": {
"name": "get_current_time",
"description": "当你想知道现在的时间时非常有用。",
"parameters": {}
}
},
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "当你想查询指定城市的天气时非常有用。",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "城市或县区,比如北京市、杭州市、余杭区等。"
}
},
"required": ["location"]
}
}
}
],
"tool_choice": null
}
"#;
let mes: ChatCompletionParameters = serde_json::from_str(message)?;