-
Notifications
You must be signed in to change notification settings - Fork 184
How to implement a multiple loop chat with memory(chat context) using onnx.genai and deepseek reasonning model #1312
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
Hi @John0King, Have a look at the snippet and see if that helps: https://onnxruntime.ai/docs/genai/howto/migrate.html#add-chat-mode-to-your-c-application-1 You don't need to re-create the generator each time around the loop and you only need to append the new prompt - the model takes care of the previous context. Let us know how that goes! |
@natke it desn't help , the reson I use I'm looking for a example on how to create a openAI compatible webapi. |
##the problem codeusing OnnxRuntimeGenAIChatClient client = new OnnxRuntimeGenAIChatClient(new OnnxRuntimeGenAIChatClientOptions
{
PromptFormatter = (prompt, context) =>
{
var sb = new StringBuilder();
sb.Append("");
sb.Append(string.Join("", prompt.Select(x => $"<|begin▁of▁sentence|><|{x.Role}|>{x.Text}<|end▁of▁sentence|>\n<|Assistant|>")));
sb.Append("");
return sb.ToString();
},
}, model, false);
List<ChatMessage> chatMessage = new List<ChatMessage>();
do
{
Console.WriteLine();
Console.WriteLine("Prompt:");
var prompt = Console.ReadLine();
if (prompt == "exit")
{
break;
}
chatMessage.Add(new ChatMessage(ChatRole.User, prompt));
List<ChatResponseUpdate> chatMessageUpdates = [];
await foreach (var x in client.GetStreamingResponseAsync(chatMessage, new ChatOptions
{
MaxOutputTokens = 4096,
AdditionalProperties = new() { { "max_length", 4096 } },
}))
{
chatMessageUpdates.Add(x);
Console.Write(x.ToString());
}
var resposne = chatMessageUpdates.ToChatResponse();
chatMessage.Add(resposne.Message);
Console.WriteLine();
}
while (true); |
I use follow code with the deepseek-r1-1b mode, but it not work well .
I start ask it 1+1=?
I continue ask it with "add 1 more" , and it start give me the result 2 only , and it lost the begin token
<think>
The text was updated successfully, but these errors were encountered: