mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-05-21 09:32:16 +00:00
Chat requests have now been refactored to use ChatCompletionAPIRequest instead of individual ChatRequests that only differ in 1 or 2 API parameters.
This commit is contained in:
parent
42f4f46523
commit
f0f040a491
@ -1,23 +0,0 @@
|
|||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace AIStudio.Provider.Groq;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The Groq chat request model.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="Model">Which model to use for chat completion.</param>
|
|
||||||
/// <param name="Messages">The chat messages.</param>
|
|
||||||
/// <param name="Stream">Whether to stream the chat completion.</param>
|
|
||||||
/// <param name="Seed">The seed for the chat completion.</param>
|
|
||||||
public readonly record struct ChatRequest(
|
|
||||||
string Model,
|
|
||||||
IList<IMessageBase> Messages,
|
|
||||||
bool Stream,
|
|
||||||
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
|
||||||
int? Seed
|
|
||||||
)
|
|
||||||
{
|
|
||||||
// Attention: The "required" modifier is not supported for [JsonExtensionData].
|
|
||||||
[JsonExtensionData]
|
|
||||||
public IDictionary<string, object> AdditionalApiParameters { get; init; } = new Dictionary<string, object>();
|
|
||||||
}
|
|
||||||
@ -22,19 +22,20 @@ public class ProviderGroq() : BaseProvider(LLMProviders.GROQ, "https://api.groq.
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override async IAsyncEnumerable<ContentStreamChunk> StreamChatCompletion(Model chatModel, ChatThread chatThread, SettingsManager settingsManager, [EnumeratorCancellation] CancellationToken token = default)
|
public override async IAsyncEnumerable<ContentStreamChunk> StreamChatCompletion(Model chatModel, ChatThread chatThread, SettingsManager settingsManager, [EnumeratorCancellation] CancellationToken token = default)
|
||||||
{
|
{
|
||||||
await foreach (var content in this.StreamOpenAICompatibleChatCompletion<ChatRequest, ChatCompletionDeltaStreamLine, ChatCompletionAnnotationStreamLine>(
|
await foreach (var content in this.StreamOpenAICompatibleChatCompletion<ChatCompletionAPIRequest, ChatCompletionDeltaStreamLine, ChatCompletionAnnotationStreamLine>(
|
||||||
"Groq",
|
"Groq",
|
||||||
chatModel,
|
chatModel,
|
||||||
chatThread,
|
chatThread,
|
||||||
settingsManager,
|
settingsManager,
|
||||||
async (systemPrompt, apiParameters) =>
|
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:
|
// Build the list of messages:
|
||||||
var messages = await chatThread.Blocks.BuildMessagesUsingNestedImageUrlAsync(this.Provider, chatModel);
|
var messages = await chatThread.Blocks.BuildMessagesUsingNestedImageUrlAsync(this.Provider, chatModel);
|
||||||
|
|
||||||
return new ChatRequest
|
return new ChatCompletionAPIRequest
|
||||||
{
|
{
|
||||||
Model = chatModel.Id,
|
Model = chatModel.Id,
|
||||||
|
|
||||||
@ -45,7 +46,6 @@ public class ProviderGroq() : BaseProvider(LLMProviders.GROQ, "https://api.groq.
|
|||||||
|
|
||||||
// Right now, we only support streaming completions:
|
// Right now, we only support streaming completions:
|
||||||
Stream = true,
|
Stream = true,
|
||||||
Seed = seed,
|
|
||||||
AdditionalApiParameters = apiParameters
|
AdditionalApiParameters = apiParameters
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,25 +0,0 @@
|
|||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace AIStudio.Provider.Mistral;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The OpenAI chat request model.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="Model">Which model to use for chat completion.</param>
|
|
||||||
/// <param name="Messages">The chat messages.</param>
|
|
||||||
/// <param name="Stream">Whether to stream the chat completion.</param>
|
|
||||||
/// <param name="RandomSeed">The seed for the chat completion.</param>
|
|
||||||
/// <param name="SafePrompt">Whether to inject a safety prompt before all conversations.</param>
|
|
||||||
public readonly record struct ChatRequest(
|
|
||||||
string Model,
|
|
||||||
IList<IMessageBase> 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<string, object> AdditionalApiParameters { get; init; } = new Dictionary<string, object>();
|
|
||||||
}
|
|
||||||
@ -20,20 +20,23 @@ public sealed class ProviderMistral() : BaseProvider(LLMProviders.MISTRAL, "http
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override async IAsyncEnumerable<ContentStreamChunk> StreamChatCompletion(Provider.Model chatModel, ChatThread chatThread, SettingsManager settingsManager, [EnumeratorCancellation] CancellationToken token = default)
|
public override async IAsyncEnumerable<ContentStreamChunk> StreamChatCompletion(Provider.Model chatModel, ChatThread chatThread, SettingsManager settingsManager, [EnumeratorCancellation] CancellationToken token = default)
|
||||||
{
|
{
|
||||||
await foreach (var content in this.StreamOpenAICompatibleChatCompletion<ChatRequest, ChatCompletionDeltaStreamLine, NoChatCompletionAnnotationStreamLine>(
|
await foreach (var content in this.StreamOpenAICompatibleChatCompletion<ChatCompletionAPIRequest, ChatCompletionDeltaStreamLine, NoChatCompletionAnnotationStreamLine>(
|
||||||
"Mistral",
|
"Mistral",
|
||||||
chatModel,
|
chatModel,
|
||||||
chatThread,
|
chatThread,
|
||||||
settingsManager,
|
settingsManager,
|
||||||
async (systemPrompt, apiParameters) =>
|
async (systemPrompt, apiParameters) =>
|
||||||
{
|
{
|
||||||
var safePrompt = TryPopBoolParameter(apiParameters, "safe_prompt", out var parsedSafePrompt) && parsedSafePrompt;
|
if (TryPopBoolParameter(apiParameters, "safe_prompt", out var parsedSafePrompt))
|
||||||
var randomSeed = TryPopIntParameter(apiParameters, "random_seed", out var parsedRandomSeed) ? parsedRandomSeed : (int?)null;
|
apiParameters["safe_prompt"] = parsedSafePrompt;
|
||||||
|
|
||||||
|
if (TryPopIntParameter(apiParameters, "random_seed", out var parsedRandomSeed))
|
||||||
|
apiParameters["random_seed"] = parsedRandomSeed;
|
||||||
|
|
||||||
// Build the list of messages:
|
// Build the list of messages:
|
||||||
var messages = await chatThread.Blocks.BuildMessagesUsingDirectImageUrlAsync(this.Provider, chatModel);
|
var messages = await chatThread.Blocks.BuildMessagesUsingDirectImageUrlAsync(this.Provider, chatModel);
|
||||||
|
|
||||||
return new ChatRequest
|
return new ChatCompletionAPIRequest
|
||||||
{
|
{
|
||||||
Model = chatModel.Id,
|
Model = chatModel.Id,
|
||||||
|
|
||||||
@ -44,8 +47,6 @@ public sealed class ProviderMistral() : BaseProvider(LLMProviders.MISTRAL, "http
|
|||||||
|
|
||||||
// Right now, we only support streaming completions:
|
// Right now, we only support streaming completions:
|
||||||
Stream = true,
|
Stream = true,
|
||||||
RandomSeed = randomSeed,
|
|
||||||
SafePrompt = safePrompt,
|
|
||||||
AdditionalApiParameters = apiParameters
|
AdditionalApiParameters = apiParameters
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user