From f0f040a491bb76149714bad8b5d15c59cd17b407 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Peer=20Sch=C3=BCtt?=
<20603780+peerschuett@users.noreply.github.com>
Date: Wed, 8 Apr 2026 15:04:35 +0200
Subject: [PATCH] Chat requests have now been refactored to use
ChatCompletionAPIRequest instead of individual ChatRequests that only differ
in 1 or 2 API parameters.
---
.../Provider/Groq/ChatRequest.cs | 23 -----------------
.../Provider/Groq/ProviderGroq.cs | 8 +++---
.../Provider/Mistral/ChatRequest.cs | 25 -------------------
.../Provider/Mistral/ProviderMistral.cs | 13 +++++-----
4 files changed, 11 insertions(+), 58 deletions(-)
delete mode 100644 app/MindWork AI Studio/Provider/Groq/ChatRequest.cs
delete mode 100644 app/MindWork AI Studio/Provider/Mistral/ChatRequest.cs
diff --git a/app/MindWork AI Studio/Provider/Groq/ChatRequest.cs b/app/MindWork AI Studio/Provider/Groq/ChatRequest.cs
deleted file mode 100644
index 07ddce22..00000000
--- a/app/MindWork AI Studio/Provider/Groq/ChatRequest.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-using System.Text.Json.Serialization;
-
-namespace AIStudio.Provider.Groq;
-
-///
-/// The Groq chat request model.
-///
-/// Which model to use for chat completion.
-/// The chat messages.
-/// Whether to stream the chat completion.
-/// The seed for the chat completion.
-public readonly record struct ChatRequest(
- string Model,
- IList Messages,
- bool Stream,
- [property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
- int? Seed
-)
-{
- // Attention: The "required" modifier is not supported for [JsonExtensionData].
- [JsonExtensionData]
- public IDictionary AdditionalApiParameters { get; init; } = new Dictionary();
-}
diff --git a/app/MindWork AI Studio/Provider/Groq/ProviderGroq.cs b/app/MindWork AI Studio/Provider/Groq/ProviderGroq.cs
index a3ca862d..d36951f0 100644
--- a/app/MindWork AI Studio/Provider/Groq/ProviderGroq.cs
+++ b/app/MindWork AI Studio/Provider/Groq/ProviderGroq.cs
@@ -22,19 +22,20 @@ public class ProviderGroq() : BaseProvider(LLMProviders.GROQ, "https://api.groq.
///
public override async IAsyncEnumerable StreamChatCompletion(Model chatModel, ChatThread chatThread, SettingsManager settingsManager, [EnumeratorCancellation] CancellationToken token = default)
{
- await foreach (var content in this.StreamOpenAICompatibleChatCompletion(
+ await foreach (var content in this.StreamOpenAICompatibleChatCompletion(
"Groq",
chatModel,
chatThread,
settingsManager,
async (systemPrompt, apiParameters) =>
{
- var seed = TryPopIntParameter(apiParameters, "seed", out var parsedSeed) ? parsedSeed : (int?)null;
+ if (TryPopIntParameter(apiParameters, "seed", out var parsedSeed))
+ apiParameters["seed"] = parsedSeed;
// Build the list of messages:
var messages = await chatThread.Blocks.BuildMessagesUsingNestedImageUrlAsync(this.Provider, chatModel);
- return new ChatRequest
+ return new ChatCompletionAPIRequest
{
Model = chatModel.Id,
@@ -45,7 +46,6 @@ public class ProviderGroq() : BaseProvider(LLMProviders.GROQ, "https://api.groq.
// Right now, we only support streaming completions:
Stream = true,
- Seed = seed,
AdditionalApiParameters = apiParameters
};
},
diff --git a/app/MindWork AI Studio/Provider/Mistral/ChatRequest.cs b/app/MindWork AI Studio/Provider/Mistral/ChatRequest.cs
deleted file mode 100644
index 1d42081f..00000000
--- a/app/MindWork AI Studio/Provider/Mistral/ChatRequest.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-using System.Text.Json.Serialization;
-
-namespace AIStudio.Provider.Mistral;
-
-///
-/// The OpenAI chat request model.
-///
-/// Which model to use for chat completion.
-/// The chat messages.
-/// Whether to stream the chat completion.
-/// The seed for the chat completion.
-/// Whether to inject a safety prompt before all conversations.
-public readonly record struct ChatRequest(
- string Model,
- IList Messages,
- bool Stream,
- [property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
- int? RandomSeed,
- bool SafePrompt = false
-)
-{
- // Attention: The "required" modifier is not supported for [JsonExtensionData].
- [JsonExtensionData]
- public IDictionary AdditionalApiParameters { get; init; } = new Dictionary();
-}
diff --git a/app/MindWork AI Studio/Provider/Mistral/ProviderMistral.cs b/app/MindWork AI Studio/Provider/Mistral/ProviderMistral.cs
index b40f6657..e4445300 100644
--- a/app/MindWork AI Studio/Provider/Mistral/ProviderMistral.cs
+++ b/app/MindWork AI Studio/Provider/Mistral/ProviderMistral.cs
@@ -20,20 +20,23 @@ public sealed class ProviderMistral() : BaseProvider(LLMProviders.MISTRAL, "http
///
public override async IAsyncEnumerable StreamChatCompletion(Provider.Model chatModel, ChatThread chatThread, SettingsManager settingsManager, [EnumeratorCancellation] CancellationToken token = default)
{
- await foreach (var content in this.StreamOpenAICompatibleChatCompletion(
+ await foreach (var content in this.StreamOpenAICompatibleChatCompletion(
"Mistral",
chatModel,
chatThread,
settingsManager,
async (systemPrompt, apiParameters) =>
{
- var safePrompt = TryPopBoolParameter(apiParameters, "safe_prompt", out var parsedSafePrompt) && parsedSafePrompt;
- var randomSeed = TryPopIntParameter(apiParameters, "random_seed", out var parsedRandomSeed) ? parsedRandomSeed : (int?)null;
+ if (TryPopBoolParameter(apiParameters, "safe_prompt", out var parsedSafePrompt))
+ apiParameters["safe_prompt"] = parsedSafePrompt;
+
+ if (TryPopIntParameter(apiParameters, "random_seed", out var parsedRandomSeed))
+ apiParameters["random_seed"] = parsedRandomSeed;
// Build the list of messages:
var messages = await chatThread.Blocks.BuildMessagesUsingDirectImageUrlAsync(this.Provider, chatModel);
- return new ChatRequest
+ return new ChatCompletionAPIRequest
{
Model = chatModel.Id,
@@ -44,8 +47,6 @@ public sealed class ProviderMistral() : BaseProvider(LLMProviders.MISTRAL, "http
// Right now, we only support streaming completions:
Stream = true,
- RandomSeed = randomSeed,
- SafePrompt = safePrompt,
AdditionalApiParameters = apiParameters
};
},