From 422791e8b9ed4f7e03a7509b5cf3bf1cb64b9ea4 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sun, 28 Dec 2025 20:47:31 +0100 Subject: [PATCH] Fixed Anthropic provider --- .../Provider/Anthropic/ChatRequest.cs | 5 ++++- .../Provider/Anthropic/ProviderAnthropic.cs | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/MindWork AI Studio/Provider/Anthropic/ChatRequest.cs b/app/MindWork AI Studio/Provider/Anthropic/ChatRequest.cs index 7489c503..d6df3990 100644 --- a/app/MindWork AI Studio/Provider/Anthropic/ChatRequest.cs +++ b/app/MindWork AI Studio/Provider/Anthropic/ChatRequest.cs @@ -9,11 +9,14 @@ namespace AIStudio.Provider.Anthropic; /// The chat messages. /// The maximum number of tokens to generate. /// Whether to stream the chat completion. +/// The system prompt for the chat completion. public readonly record struct ChatRequest( string Model, IList Messages, int MaxTokens, - bool Stream) + bool Stream, + string System +) { // Attention: The "required" modifier is not supported for [JsonExtensionData]. [JsonExtensionData] diff --git a/app/MindWork AI Studio/Provider/Anthropic/ProviderAnthropic.cs b/app/MindWork AI Studio/Provider/Anthropic/ProviderAnthropic.cs index d5fd9e15..f23b8d4d 100644 --- a/app/MindWork AI Studio/Provider/Anthropic/ProviderAnthropic.cs +++ b/app/MindWork AI Studio/Provider/Anthropic/ProviderAnthropic.cs @@ -27,18 +27,18 @@ public sealed class ProviderAnthropic() : BaseProvider(LLMProviders.ANTHROPIC, " if(!requestedSecret.Success) yield break; - // Prepare the system prompt: - var systemPrompt = new TextMessage - { - Role = "system", - Content = chatThread.PrepareSystemPrompt(settingsManager, chatThread), - }; - // Parse the API parameters: var apiParameters = this.ParseAdditionalApiParameters("system"); // Build the list of messages: - var messages = await chatThread.Blocks.BuildMessagesUsingStandardRoles(); + var messages = await chatThread.Blocks.BuildMessages(role => role switch + { + ChatRole.USER => "user", + ChatRole.AI => "assistant", + ChatRole.AGENT => "assistant", + + _ => "user", + }); // Prepare the Anthropic HTTP chat request: var chatRequest = JsonSerializer.Serialize(new ChatRequest @@ -46,8 +46,9 @@ public sealed class ProviderAnthropic() : BaseProvider(LLMProviders.ANTHROPIC, " Model = chatModel.Id, // Build the messages: - Messages = [systemPrompt, ..messages], + Messages = [..messages], + System = chatThread.PrepareSystemPrompt(settingsManager, chatThread), MaxTokens = apiParameters.TryGetValue("max_tokens", out var value) && value is int intValue ? intValue : 4_096, // Right now, we only support streaming completions: