summaryrefslogtreecommitdiff
path: root/src/Agent.Core/Ollama
diff options
context:
space:
mode:
Diffstat (limited to 'src/Agent.Core/Ollama')
-rw-r--r--src/Agent.Core/Ollama/OllamaClient.cs5
-rw-r--r--src/Agent.Core/Ollama/OllamaModels.cs7
-rw-r--r--src/Agent.Core/Ollama/OllamaSettings.cs2
3 files changed, 8 insertions, 6 deletions
diff --git a/src/Agent.Core/Ollama/OllamaClient.cs b/src/Agent.Core/Ollama/OllamaClient.cs
index 428bca9..fea5dfb 100644
--- a/src/Agent.Core/Ollama/OllamaClient.cs
+++ b/src/Agent.Core/Ollama/OllamaClient.cs
@@ -57,7 +57,7 @@ public sealed class OllamaClient : IOllamaClient
Model = _settings.Model,
Messages = messages,
Stream = false,
- Think = thinkOverride ?? _settings.Think,
+ Think = thinkOverride is null ? _settings.Think : thinkOverride.Value,
KeepAlive = _settings.KeepAlive,
Options = options,
Tools = tools?.Select(static tool => new OllamaToolDefinition("function", new OllamaFunctionDefinition(tool.Name, tool.Description, tool.Parameters))).ToArray(),
@@ -85,7 +85,8 @@ public sealed class OllamaClient : IOllamaClient
?? throw new OllamaException("Ollama returned an empty response.", false);
if (!string.IsNullOrWhiteSpace(result.Error)) throw new OllamaException(result.Error, false);
if (result.Message is null) throw new OllamaException("Ollama response has no message.", false);
- return new OllamaResult(result.Message.Content, result.PromptEvalCount, result.EvalCount, result.Message.ToolCalls ?? [], result.PromptEvalCount);
+ return new OllamaResult(result.Message.Content, result.PromptEvalCount, result.EvalCount,
+ result.Message.ToolCalls ?? [], result.PromptEvalCount, result.Message.Thinking);
}
catch (Exception ex) when (ex is HttpRequestException or TaskCanceledException && !cancellationToken.IsCancellationRequested)
{
diff --git a/src/Agent.Core/Ollama/OllamaModels.cs b/src/Agent.Core/Ollama/OllamaModels.cs
index f6ff092..9e6103e 100644
--- a/src/Agent.Core/Ollama/OllamaModels.cs
+++ b/src/Agent.Core/Ollama/OllamaModels.cs
@@ -9,7 +9,8 @@ public sealed record OllamaMessage(
[property: JsonPropertyName("content")] string Content,
[property: JsonPropertyName("images"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] IReadOnlyList<string>? Images = null,
[property: JsonPropertyName("tool_name"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] string? ToolName = null,
- [property: JsonPropertyName("tool_calls"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] IReadOnlyList<OllamaToolCall>? ToolCalls = null);
+ [property: JsonPropertyName("tool_calls"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] IReadOnlyList<OllamaToolCall>? ToolCalls = null,
+ [property: JsonPropertyName("thinking"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] string? Thinking = null);
public sealed record OllamaToolCall([property: JsonPropertyName("function")] OllamaFunctionCall Function);
public sealed record OllamaFunctionCall(
@@ -29,7 +30,7 @@ public sealed class OllamaChatRequest
[JsonPropertyName("model")] public required string Model { get; init; }
[JsonPropertyName("messages")] public required IReadOnlyList<OllamaMessage> Messages { get; init; }
[JsonPropertyName("stream")] public bool Stream { get; init; }
- [JsonPropertyName("think")] public bool Think { get; init; }
+ [JsonPropertyName("think")] public required object Think { get; init; }
[JsonPropertyName("keep_alive")] public required string KeepAlive { get; init; }
[JsonPropertyName("options")] public required IReadOnlyDictionary<string, System.Text.Json.JsonElement> Options { get; init; }
[JsonPropertyName("tools"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public IReadOnlyList<OllamaToolDefinition>? Tools { get; init; }
@@ -44,4 +45,4 @@ public sealed class OllamaChatResponse
[JsonPropertyName("error")] public string? Error { get; init; }
}
-public sealed record OllamaResult(string Content, long InputTokens, long OutputTokens, IReadOnlyList<OllamaToolCall>? ToolCalls = null, long PromptEvalCount = 0);
+public sealed record OllamaResult(string Content, long InputTokens, long OutputTokens, IReadOnlyList<OllamaToolCall>? ToolCalls = null, long PromptEvalCount = 0, string? Thinking = null);
diff --git a/src/Agent.Core/Ollama/OllamaSettings.cs b/src/Agent.Core/Ollama/OllamaSettings.cs
index 94ab3ef..9f33208 100644
--- a/src/Agent.Core/Ollama/OllamaSettings.cs
+++ b/src/Agent.Core/Ollama/OllamaSettings.cs
@@ -5,6 +5,6 @@ namespace Agent.Core.Ollama;
public sealed record OllamaSettings(
Uri Endpoint,
string Model,
- bool Think,
+ object Think,
string KeepAlive,
IReadOnlyDictionary<string, JsonElement> Options);