using GermanApp.Application.Models;
namespace GermanApp.Domain.Interfaces;
///
/// Interface for Mistral API connector.
/// This is part of the Domain layer - defines the contract for communicating with Mistral API.
///
public interface IMistralConnector
{
///
/// Sends a completion request to Mistral API.
///
/// The completion request containing prompt and parameters
/// Cancellation token
/// Mistral API response containing generated text
/// Thrown when Mistral API request fails
Task CompleteAsync(MistralRequest request,
CancellationToken cancellationToken = default);
///
/// Sends a chat completion request to Mistral API.
///
/// The chat completion request containing messages and parameters
/// Cancellation token
/// Mistral API chat response containing generated message
/// Thrown when Mistral API request fails
Task ChatAsync(MistralChatRequest request,
CancellationToken cancellationToken = default);
///
/// Lists available models from Mistral API.
///
/// Cancellation token
/// List of available Mistral models
/// Thrown when Mistral API request fails
Task> ListModelsAsync(
CancellationToken cancellationToken = default);
///
/// Gets information about a specific model.
///
/// The model identifier
/// Cancellation token
/// Information about the specified model
/// Thrown when Mistral API request fails
Task GetModelAsync(string modelId,
CancellationToken cancellationToken = default);
}
///
/// Custom exception for AI service errors.
///
public class AiServiceException : Exception
{
///
/// Error code for categorizing AI service errors.
///
public AiErrorCode ErrorCode { get; }
///
/// Creates a new AI service exception.
///
public AiServiceException(string message, AiErrorCode errorCode = AiErrorCode.Unknown)
: base(message)
{
ErrorCode = errorCode;
}
///
/// Creates a new AI service exception with inner exception.
///
public AiServiceException(string message, Exception innerException,
AiErrorCode errorCode = AiErrorCode.Unknown)
: base(message, innerException)
{
ErrorCode = errorCode;
}
}
///
/// Error codes for AI service exceptions.
///
public enum AiErrorCode
{
/// Unknown or unspecified error
Unknown = 0,
/// API rate limit exceeded
RateLimited = 1,
/// Temporary API failure, may succeed on retry
Temporary = 2,
/// Request timeout
Timeout = 3,
/// Invalid API key or authentication error
AuthenticationError = 4,
/// Invalid request parameters
InvalidRequest = 5,
/// API returned invalid/empty response
InvalidResponse = 6,
/// Service is temporarily unavailable (circuit breaker open)
ServiceUnavailable = 7
}