fix(backend/config): Skip AI service validation when configs are not set

- MistralConnector, TtsService, VoskService: Skip validation when required config values are empty
- ValidateAiConfigurations: Only validate if config values are set
- Prevents startup crashes in Docker when AI service environment variables are not provided
- Allows backend to start without Mistral/Coqui/Vosk configurations

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Lasse Rune Hansen 2026-06-14 07:54:23 +02:00
parent de85cdec7c
commit fa1237026a
4 changed files with 30 additions and 16 deletions

View file

@ -31,9 +31,12 @@ public class MistralConnector : IMistralConnector
_logger = logger;
_cache = cache;
// Skip validation and initialization during EF migrations
// Skip validation and initialization during EF migrations or when configs are not set
// (In Docker, AI configs may be set via environment variables or may be optional)
bool isEfDesignTime = Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_EF") == "true";
if (!isEfDesignTime)
bool hasApiKey = !string.IsNullOrWhiteSpace(_config?.ApiKey);
if (!isEfDesignTime && hasApiKey)
{
_config.Validate();

View file

@ -25,9 +25,11 @@ public class TtsService : ITtsService
_config = config.Value;
_logger = logger;
// Skip validation during EF migrations
// Skip validation during EF migrations or when configs are not set
bool isEfDesignTime = Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_EF") == "true";
if (!isEfDesignTime)
bool hasPythonPath = !string.IsNullOrWhiteSpace(_config?.PythonPath);
if (!isEfDesignTime && hasPythonPath)
{
ValidateConfiguration();
// Ensure audio storage directory exists

View file

@ -25,9 +25,11 @@ public class VoskService : IVoskService
_config = config.Value;
_logger = logger;
// Skip validation during EF migrations
// Skip validation during EF migrations or when configs are not set
bool isEfDesignTime = Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_EF") == "true";
if (!isEfDesignTime)
bool hasModelPath = !string.IsNullOrWhiteSpace(_config?.ModelPath);
if (!isEfDesignTime && hasModelPath)
{
ValidateModelPath();
}

View file

@ -337,25 +337,32 @@ try
// Helper method to validate AI service configurations
static void ValidateAiConfigurations(IConfiguration configuration)
{
// Skip validation during EF migrations and Docker startup
// (In Docker, AI service configs may not be fully set)
if (Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_EF") == "true" ||
Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER") == "true")
// Skip validation during EF migrations
if (Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_EF") == "true")
{
return;
}
// Validate Mistral configuration
// Validate Mistral configuration (only if API key is set)
var mistralConfig = configuration.GetSection("Mistral").Get<MistralConfig>() ?? new MistralConfig();
if (!string.IsNullOrWhiteSpace(mistralConfig.ApiKey))
{
mistralConfig.Validate();
}
// Validate Vosk configuration
// Validate Vosk configuration (only if model path is set)
var voskConfig = configuration.GetSection("Vosk").Get<VoskConfig>() ?? new VoskConfig();
if (!string.IsNullOrWhiteSpace(voskConfig.ModelPath))
{
voskConfig.Validate();
}
// Validate Coqui configuration
// Validate Coqui configuration (only if Python path is set)
var coquiConfig = configuration.GetSection("Coqui").Get<CoquiConfig>() ?? new CoquiConfig();
if (!string.IsNullOrWhiteSpace(coquiConfig.PythonPath))
{
coquiConfig.Validate();
}
Log.Information("All AI service configurations validated successfully");
}