microsoft / microsoft/semantic-kernel
NET: How to disable think mode when calling the ollama model
Open
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 28.6k
- Forks
- 4.8k
- Avg merge
- 14h 13m
- Merged PRs (30d)
- 18
Description
Microsoft.SemanticKernel:
public static async Task Main()
{
Console.OutputEncoding = System.Text.Encoding.UTF8;
var builder = Kernel.CreateBuilder();
var modelId = "gemma4:e4b-it-q4_K_M";
var endpoint = new Uri("http://localhost:11434");
builder.Services.AddOllamaChatCompletion(modelId, endpoint);
var kernel = builder.Build();
var chatCompletionService = kernel.GetRequiredService<IChatCompletionService>();
string prompt = "c#写一个计算当前月天数的方法";
var executionSettings = new OllamaPromptExecutionSettings
{
FunctionChoiceBehavior = FunctionChoiceBehavior.Auto(autoInvoke: false),
};
var response = await chatCompletionService.GetChatMessageContentAsync(prompt, kernel: kernel, executionSettings: executionSettings);
Console.Write(response.Content);
}
How to disable think mode when calling the ollama model?
It is recommended to add a method like chatOptions.AddOllamaOption(OllamaOption.Think, false);
Microsoft.Extensions.AI:
public async static Task Main()
{
OllamaApiClient ollamaClient = new OllamaApiClient(new Uri("http://localhost:11434/"), "gemma4:e4b-it-q4_K_M");
// 3. 调用 Ollama API
var client = new Microsoft.Extensions.AI.ChatClientBuilder(ollamaClient)
.UseFunctionInvocation()
.Build();
ChatOptions chatOptions = new()
{
Tools = [AIFunctionFactory.Create(QueryDateTime), AIFunctionFactory.Create(SaveFile), AIFunctionFactory.Create(ReadFile)],
};
chatOptions.AddOllamaOption(OllamaOption.Think, false);//Disable think
await foreach (var res in client.GetStreamingResponseAsync("c#写一个计算当前月天数的方法", chatOptions))//,
{
Console.Write(res.Text);
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Ollama chat-completion integration used by Microsoft.SemanticKernel and the OllamaPromptExecutionSettings shown in the report. Compare its options with the Microsoft.Extensions.AI example, then verify that callers can set the Ollama think option to false and that the model request disables thinking.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, ollama
- Domain
- ai
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100