using System.Text.Json.Serialization;
namespace GermanApp.Application.Models;
///
/// Request model for Mistral completion API.
/// Used for text generation (stories, feedback, etc.).
///
///
/// See: https://docs.mistral.ai/api/#operation/createCompletion
///
public record MistralRequest
{
///
/// ID of the model to use.
///
public string Model { get; init; } = "mistral-medium";
///
/// The prompt(s) to generate completions for.
///
public string Prompt { get; init; } = string.Empty;
///
/// The maximum number of tokens to generate in the completion.
/// Default: 256, Max: 2048 for mistral-medium
///
public int? MaxTokens { get; init; } = 512;
///
/// What sampling temperature to use.
/// Higher values means the model will take more risks. Try 0.9 for more creative applications, and 0 for ones with a well-defined answer.
/// Default: 0.7
///
public double? Temperature { get; init; } = 0.7;
///
/// Nucleus sampling, where the model considers the results of the tokens with top_p probability mass.
/// So 0.1 means only the tokens comprising the top 10% probability mass are considered.
/// Default: 1.0
///
public double? TopP { get; init; } = 1.0;
///
/// How many completions to generate for each prompt.
/// Default: 1
///
public int? N { get; init; } = 1;
///
/// Whether to stream partial responses.
/// Not supported by this connector (use streaming endpoint separately if needed).
///
public bool? Stream { get; init; } = false;
///
/// Whether to echo the prompt in the response.
/// Default: false
///
public bool? Echo { get; init; } = false;
///
/// Up to 4 sequences where the API will stop generating further tokens.
///
public IReadOnlyList? Stop { get; init; }
///
/// Number between -2.0 and 2.0. Positive values penalize new tokens based on their frequency in the text so far.
///
public double? FrequencyPenalty { get; init; }
///
/// Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far.
///
public double? PresencePenalty { get; init; }
///
/// User identifier for tracking usage.
///
public string? User { get; init; }
///
/// Factory method to create a completion request with default settings.
///
public static MistralRequest CreateCompletion(string prompt, string model = "mistral-medium", int maxTokens = 512)
{
return new MistralRequest
{
Model = model,
Prompt = prompt,
MaxTokens = maxTokens,
Temperature = 0.7,
TopP = 1.0,
N = 1,
Stream = false,
Echo = false
};
}
}
///
/// Request model for Mistral chat completion API.
/// Used for conversational text generation.
///
///
/// See: https://docs.mistral.ai/api/#operation/createChatCompletion
///
public record MistralChatRequest
{
///
/// ID of the model to use.
///
[JsonPropertyName("model")]
public string Model { get; init; } = "mistral-small-latest";
///
/// A list of messages comprising the conversation so far.
///
[JsonPropertyName("messages")]
public IReadOnlyList Messages { get; init; } = new List();
///
/// The maximum number of tokens to generate in the completion.
///
[JsonPropertyName("max_tokens")]
public int? MaxTokens { get; init; }
///
/// What sampling temperature to use.
///
[JsonPropertyName("temperature")]
public double? Temperature { get; init; }
///
/// Factory method to create a chat request.
///
public static MistralChatRequest CreateChat(IReadOnlyList messages, string model = "mistral-small-latest", int maxTokens = 512)
{
return new MistralChatRequest
{
Model = model,
Messages = messages,
MaxTokens = maxTokens,
Temperature = 0.7
};
}
}
///
/// Represents a message in a Mistral chat conversation.
///
public record MistralMessage
{
///
/// The role of the message author.
///
[JsonPropertyName("role")]
public string Role { get; init; } = string.Empty;
///
/// The content of the message.
///
[JsonPropertyName("content")]
public string Content { get; init; } = string.Empty;
///
/// Factory method to create a user message.
///
public static MistralMessage User(string content) => new() { Role = "user", Content = content };
///
/// Factory method to create an assistant message.
///
public static MistralMessage Assistant(string content) => new() { Role = "assistant", Content = content };
///
/// Factory method to create a system message.
///
public static MistralMessage System(string content) => new() { Role = "system", Content = content };
}
///
/// Model information from Mistral API.
///
public record MistralModel
{
///
/// The model identifier.
///
public string Id { get; init; } = string.Empty;
///
/// The model object type.
///
public string Object { get; init; } = string.Empty;
///
/// When the model was created.
///
public long Created { get; init; }
///
/// The model's description.
///
public string Description { get; init; } = string.Empty;
}