Feature: Load balanced API keys and voice registration responses for Company 1
This commit is contained in:
@@ -6,6 +6,51 @@ class GeminiService
|
||||
{
|
||||
public const DEFAULT_MODEL = 'gemini-3.1-flash-lite';
|
||||
|
||||
/**
|
||||
* Get a random Gemini API key from a comma-separated list of keys
|
||||
*/
|
||||
public static function getGeminiApiKey(?string $configuredKey = null): string
|
||||
{
|
||||
$keySource = !empty($configuredKey) ? $configuredKey : getenv('GEMINI_API_KEY');
|
||||
if (empty($keySource)) {
|
||||
return '';
|
||||
}
|
||||
$keys = array_filter(array_map('trim', explode(',', $keySource)));
|
||||
if (empty($keys)) {
|
||||
return '';
|
||||
}
|
||||
return $keys[array_rand($keys)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a random ElevenLabs API key from a comma-separated list of keys
|
||||
*/
|
||||
public static function getElevenLabsApiKey(?string $configuredKey = null): ?string
|
||||
{
|
||||
$keySource = !empty($configuredKey) ? $configuredKey : getenv('ELEVENLABS_API_KEY');
|
||||
if (empty($keySource)) {
|
||||
return null;
|
||||
}
|
||||
$keys = array_filter(array_map('trim', explode(',', $keySource)));
|
||||
if (empty($keys)) {
|
||||
return null;
|
||||
}
|
||||
return $keys[array_rand($keys)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a random ElevenLabs Voice ID from a comma-separated list of Voice IDs
|
||||
*/
|
||||
public static function getElevenLabsVoiceId(?string $configuredVoiceId = null): string
|
||||
{
|
||||
$voiceIdSource = !empty($configuredVoiceId) ? $configuredVoiceId : (getenv('ELEVENLABS_VOICE_ID') ?: 'pNInz6obpgDQGcFmaJgB');
|
||||
$voiceIds = array_filter(array_map('trim', explode(',', $voiceIdSource)));
|
||||
if (empty($voiceIds)) {
|
||||
return 'pNInz6obpgDQGcFmaJgB';
|
||||
}
|
||||
return $voiceIds[array_rand($voiceIds)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Call Gemini API to generate a response
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user