Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/AI/OllamaClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,13 @@ public async Task<string> ChatAsync(string message, CancellationToken cancellati
var responseContent = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<OllamaChatResponse>(responseContent);

// Check if deserialization was successful
if (result == null)
{
System.Diagnostics.Debug.WriteLine("Ollama chat error: Failed to deserialize response");
return null;
}

// Track token usage
LastPromptTokens = result.PromptEvalCount;
LastCompletionTokens = result.EvalCount;
Expand Down Expand Up @@ -436,7 +443,10 @@ public async Task<string> ChatAsync(string message, CancellationToken cancellati
}
}
}
else if (result?.Message?.Content != null)

// Fallback: If tool calls failed, returned no content, or follow-up request failed,
// use the original response content if available
if (result?.Message?.Content != null)
{
string cleanedResponse = CleanResponse(result.Message.Content);

Expand All @@ -446,6 +456,9 @@ public async Task<string> ChatAsync(string message, CancellationToken cancellati

return cleanedResponse;
}

// No content available in response
System.Diagnostics.Debug.WriteLine("Ollama chat: Response received but no content available");
}
else
{
Expand Down
Loading