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:
parent
de85cdec7c
commit
fa1237026a
4 changed files with 30 additions and 16 deletions
|
|
@ -31,9 +31,12 @@ public class MistralConnector : IMistralConnector
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_cache = cache;
|
_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";
|
bool isEfDesignTime = Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_EF") == "true";
|
||||||
if (!isEfDesignTime)
|
bool hasApiKey = !string.IsNullOrWhiteSpace(_config?.ApiKey);
|
||||||
|
|
||||||
|
if (!isEfDesignTime && hasApiKey)
|
||||||
{
|
{
|
||||||
_config.Validate();
|
_config.Validate();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,11 @@ public class TtsService : ITtsService
|
||||||
_config = config.Value;
|
_config = config.Value;
|
||||||
_logger = logger;
|
_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";
|
bool isEfDesignTime = Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_EF") == "true";
|
||||||
if (!isEfDesignTime)
|
bool hasPythonPath = !string.IsNullOrWhiteSpace(_config?.PythonPath);
|
||||||
|
|
||||||
|
if (!isEfDesignTime && hasPythonPath)
|
||||||
{
|
{
|
||||||
ValidateConfiguration();
|
ValidateConfiguration();
|
||||||
// Ensure audio storage directory exists
|
// Ensure audio storage directory exists
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,11 @@ public class VoskService : IVoskService
|
||||||
_config = config.Value;
|
_config = config.Value;
|
||||||
_logger = logger;
|
_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";
|
bool isEfDesignTime = Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_EF") == "true";
|
||||||
if (!isEfDesignTime)
|
bool hasModelPath = !string.IsNullOrWhiteSpace(_config?.ModelPath);
|
||||||
|
|
||||||
|
if (!isEfDesignTime && hasModelPath)
|
||||||
{
|
{
|
||||||
ValidateModelPath();
|
ValidateModelPath();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -337,25 +337,32 @@ try
|
||||||
// Helper method to validate AI service configurations
|
// Helper method to validate AI service configurations
|
||||||
static void ValidateAiConfigurations(IConfiguration configuration)
|
static void ValidateAiConfigurations(IConfiguration configuration)
|
||||||
{
|
{
|
||||||
// Skip validation during EF migrations and Docker startup
|
// Skip validation during EF migrations
|
||||||
// (In Docker, AI service configs may not be fully set)
|
if (Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_EF") == "true")
|
||||||
if (Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_EF") == "true" ||
|
|
||||||
Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER") == "true")
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate Mistral configuration
|
// Validate Mistral configuration (only if API key is set)
|
||||||
var mistralConfig = configuration.GetSection("Mistral").Get<MistralConfig>() ?? new MistralConfig();
|
var mistralConfig = configuration.GetSection("Mistral").Get<MistralConfig>() ?? new MistralConfig();
|
||||||
|
if (!string.IsNullOrWhiteSpace(mistralConfig.ApiKey))
|
||||||
|
{
|
||||||
mistralConfig.Validate();
|
mistralConfig.Validate();
|
||||||
|
}
|
||||||
|
|
||||||
// Validate Vosk configuration
|
// Validate Vosk configuration (only if model path is set)
|
||||||
var voskConfig = configuration.GetSection("Vosk").Get<VoskConfig>() ?? new VoskConfig();
|
var voskConfig = configuration.GetSection("Vosk").Get<VoskConfig>() ?? new VoskConfig();
|
||||||
|
if (!string.IsNullOrWhiteSpace(voskConfig.ModelPath))
|
||||||
|
{
|
||||||
voskConfig.Validate();
|
voskConfig.Validate();
|
||||||
|
}
|
||||||
|
|
||||||
// Validate Coqui configuration
|
// Validate Coqui configuration (only if Python path is set)
|
||||||
var coquiConfig = configuration.GetSection("Coqui").Get<CoquiConfig>() ?? new CoquiConfig();
|
var coquiConfig = configuration.GetSection("Coqui").Get<CoquiConfig>() ?? new CoquiConfig();
|
||||||
|
if (!string.IsNullOrWhiteSpace(coquiConfig.PythonPath))
|
||||||
|
{
|
||||||
coquiConfig.Validate();
|
coquiConfig.Validate();
|
||||||
|
}
|
||||||
|
|
||||||
Log.Information("All AI service configurations validated successfully");
|
Log.Information("All AI service configurations validated successfully");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue