using System.Text.Json.Serialization;
|
|
namespace Moli.Desktop.Llm;
|
|
public sealed record LlmSettingsDocument
|
{
|
public int SchemaVersion { get; init; } = 1;
|
public string? DefaultModel { get; init; }
|
public List<LlmModelConfig> Models { get; init; } = [];
|
}
|
|
public sealed record LlmModelConfig
|
{
|
public required string Id { get; init; }
|
public required string Label { get; init; }
|
public required string Provider { get; init; }
|
public required string Endpoint { get; init; }
|
public string? AuthRef { get; init; }
|
public required string ApiModel { get; init; }
|
public bool SupportsStreaming { get; init; } = true;
|
public bool Enabled { get; init; }
|
public LlmRequestDefaults RequestDefaults { get; init; } = new();
|
}
|
|
public sealed record LlmRequestDefaults
|
{
|
public double Temperature { get; init; } = 0.7;
|
public int MaxTokens { get; init; } = 2048;
|
public int TimeoutMs { get; init; } = 60000;
|
}
|
|
public sealed record LlmModelSummary
|
{
|
public required string Id { get; init; }
|
public required string Label { get; init; }
|
public required string Provider { get; init; }
|
public bool SupportsStreaming { get; init; }
|
public bool Enabled { get; init; }
|
}
|
|
public sealed record LlmChatRequest
|
{
|
public required string RequestId { get; init; }
|
public required string PluginId { get; init; }
|
public required string InstanceId { get; init; }
|
public required string ModelId { get; init; }
|
public required IReadOnlyList<LlmMessage> Messages { get; init; }
|
public LlmRequestOptions Options { get; init; } = new();
|
}
|
|
public sealed record LlmMessage
|
{
|
public required string Role { get; init; }
|
public required string Content { get; init; }
|
}
|
|
public sealed record LlmRequestOptions
|
{
|
public double? Temperature { get; init; }
|
public int? MaxTokens { get; init; }
|
public int? TimeoutMs { get; init; }
|
}
|
|
public sealed record LlmProviderRequest
|
{
|
public required string RequestId { get; init; }
|
public required LlmModelConfig Model { get; init; }
|
public required IReadOnlyList<LlmMessage> Messages { get; init; }
|
public required LlmRequestOptions Options { get; init; }
|
public string? ApiKey { get; init; }
|
}
|
|
[JsonPolymorphic(TypeDiscriminatorPropertyName = "kind")]
|
[JsonDerivedType(typeof(LlmDeltaEvent), "delta")]
|
[JsonDerivedType(typeof(LlmCompletedEvent), "completed")]
|
[JsonDerivedType(typeof(LlmErrorEvent), "error")]
|
public abstract record LlmStreamEvent
|
{
|
public required string RequestId { get; init; }
|
}
|
|
public sealed record LlmDeltaEvent : LlmStreamEvent
|
{
|
public required string Delta { get; init; }
|
}
|
|
public sealed record LlmCompletedEvent : LlmStreamEvent
|
{
|
public LlmUsage? Usage { get; init; }
|
}
|
|
public sealed record LlmErrorEvent : LlmStreamEvent
|
{
|
public required string Code { get; init; }
|
public required string Message { get; init; }
|
}
|
|
public sealed record LlmUsage
|
{
|
public int? InputTokens { get; init; }
|
public int? OutputTokens { get; init; }
|
}
|
|
public sealed record LlmProviderChunk
|
{
|
public string? Delta { get; init; }
|
public bool IsCompleted { get; init; }
|
public LlmUsage? Usage { get; init; }
|
}
|
|
public static class LlmErrorCodes
|
{
|
public const string ModelNotFound = "LlmModelNotFound";
|
public const string ProviderUnsupported = "LlmProviderUnsupported";
|
public const string CredentialMissing = "LlmCredentialMissing";
|
public const string EndpointUnavailable = "LlmEndpointUnavailable";
|
public const string Unauthorized = "LlmUnauthorized";
|
public const string RateLimited = "LlmRateLimited";
|
public const string Timeout = "LlmTimeout";
|
public const string StreamParseFailed = "LlmStreamParseFailed";
|
public const string RequestInvalid = "LlmRequestInvalid";
|
}
|