-
Notifications
You must be signed in to change notification settings - Fork 184
OnnxRuntimeGenAIChatClientOptions support DeepSeek-r1-Distill-14b #1380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@williamlzw I'm search the deepseek template for a while , and now I find that there is a and it's complex and this is the define (with indent)
|
this is ported version , I'm not sure about the tool part PromptFormatter = static (chatMessages, context) =>
{
string systemPrompt;
bool add_generation_prompt = true, isFirst = false, isTool = false, isOutputFirst = true;
systemPrompt = string.Join("\n", chatMessages.Where(x => x.Role == ChatRole.System).Select(x=>x.Text));
var sb = new StringBuilder();
sb.Append("<|begin▁of▁sentence|>");
sb.Append(systemPrompt);
foreach(var x in chatMessages)
{
if(x.Role == ChatRole.User)
{
isTool = false;
sb.Append($"<|User|>{x.Text}");
}
if(x.Role == ChatRole.Assistant && string.IsNullOrWhiteSpace(x.Text))
{
isTool = false;
foreach(var tool in x.Contents.OfType<FunctionCallContent>())
{
if(!isFirst)
{
sb.Append($"<|Assistant|><|tool▁calls▁begin|><|tool▁call▁begin|>functionCall<|tool▁sep|>{tool.Name}\n```json\n{JsonSerializer.Serialize(tool.Arguments)}\n```<|tool▁call▁end|>");
isFirst = true;
}
else
{
sb.Append($@"\n<|tool▁call▁begin|>functionCall<|tool▁sep|>{tool.Name}\n```json\n{JsonSerializer.Serialize(tool.Arguments)}\n```<|tool▁call▁end|><|tool▁calls▁end|><|end▁of▁sentence|>");
}
}
}
if(x.Role == ChatRole.Assistant && !string.IsNullOrWhiteSpace(x.Text))
{
if (isTool)
{
sb.Append($"<|tool▁outputs▁end|>{x.Text}<|end▁of▁sentence|>");
isTool = false;
}
else
{
var content = string.Join("",x.Text.Split("</think>")[^1..]);
sb.Append($"<|Assistant|>{content}<|end▁of▁sentence|>");
}
}
if(x.Role == ChatRole.Tool)
{
var toolContent = x.Contents.OfType<FunctionResultContent>().FirstOrDefault();
isTool = true;
if (isOutputFirst)
{
sb.Append($"<|tool▁outputs▁begin|><|tool▁output▁begin|>{JsonSerializer.Serialize(toolContent?.Result)}<|tool▁output▁end|>");
isOutputFirst = false;
}
else
{
sb.Append($"\n<|tool▁output▁begin|>{JsonSerializer.Serialize(toolContent?.Result)}<|tool▁output▁end|>");
}
}
}
if (isTool)
{
sb.Append("<|tool▁outputs▁end|>");
}
if(add_generation_prompt && !isTool)
{
sb.Append("<|Assistant|>");
}
return sb.ToString();
}, |
Thanks. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am not sure if the OnnxRuntimeGenAIChatClientOptions of the following deepseek model is correct. The value of message.Role.Value is fixed to "user". The user prompt tag of this deepseek model is < | User | >.
model:https://huggingface.co/onnxruntime/DeepSeek-R1-Distill-ONNX/tree/main/deepseek-r1-distill-qwen-14B/gpu/gpu-int4-rtn-block-32
The text was updated successfully, but these errors were encountered: