Skip to content

Commit a6e1865

Browse files
nicknaclaude
andcommitted
feat: update ElevenLabsClient to use configuration-based defaults
- Updated constructor to accept ProviderDefaultModels parameter - Replaced hardcoded model defaults with configuration lookups - Added GetDefaultTextToSpeechModel() and GetDefaultRealtimeModel() helper methods - Updated LLMClientFactory to pass configuration to ElevenLabsClient - Maintains backward compatibility with fallback to original defaults 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 5c64c4d commit a6e1865

3 files changed

Lines changed: 68 additions & 13 deletions

File tree

ConduitLLM.Providers/ElevenLabsClient.cs

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ public ElevenLabsClient(
4040
ProviderCredentials credentials,
4141
string providerModelId,
4242
ILogger<ElevenLabsClient> logger,
43-
IHttpClientFactory? httpClientFactory = null)
44-
: base(credentials, providerModelId, logger, httpClientFactory, "ElevenLabs")
43+
IHttpClientFactory? httpClientFactory = null,
44+
ProviderDefaultModels? defaultModels = null)
45+
: base(credentials, providerModelId, logger, httpClientFactory, "ElevenLabs", defaultModels)
4546
{
4647
var translatorLogger = logger as ILogger<ElevenLabsRealtimeTranslator>
4748
?? Microsoft.Extensions.Logging.Abstractions.NullLoggerFactory.Instance.CreateLogger<ElevenLabsRealtimeTranslator>();
@@ -92,7 +93,7 @@ public async Task<TextToSpeechResponse> CreateSpeechAsync(
9293

9394
// ElevenLabs uses voice IDs instead of voice names
9495
var voiceId = request.Voice ?? "21m00Tcm4TlvDq8ikWAM"; // Default voice ID
95-
var model = request.Model ?? "eleven_monolingual_v1";
96+
var model = request.Model ?? GetDefaultTextToSpeechModel();
9697

9798
var requestUrl = $"{API_BASE_URL}/text-to-speech/{voiceId}";
9899

@@ -149,7 +150,7 @@ public async IAsyncEnumerable<AudioChunk> StreamSpeechAsync(
149150
using var httpClient = CreateHttpClient(effectiveApiKey);
150151

151152
var voiceId = request.Voice ?? "21m00Tcm4TlvDq8ikWAM";
152-
var model = request.Model ?? "eleven_monolingual_v1";
153+
var model = request.Model ?? GetDefaultTextToSpeechModel();
153154

154155
var requestUrl = $"{API_BASE_URL}/text-to-speech/{voiceId}/stream";
155156

@@ -378,6 +379,12 @@ public async Task<RealtimeSession> CreateSessionAsync(
378379

379380
await clientWebSocket.ConnectAsync(wsUri, cancellationToken);
380381

382+
// Ensure model is set to default if not provided
383+
if (string.IsNullOrEmpty(config.Model))
384+
{
385+
config.Model = GetDefaultRealtimeModel();
386+
}
387+
381388
var session = new ElevenLabsRealtimeSession(
382389
clientWebSocket,
383390
_translator,
@@ -506,6 +513,52 @@ private class ElevenLabsVoiceLabels
506513
public string? Language { get; set; }
507514
public string? Gender { get; set; }
508515
}
516+
517+
#region Configuration Helpers
518+
519+
/// <summary>
520+
/// Gets the default text-to-speech model from configuration or falls back to eleven_monolingual_v1.
521+
/// </summary>
522+
private string GetDefaultTextToSpeechModel()
523+
{
524+
// Check provider-specific override first
525+
var providerOverride = DefaultModels?.Audio?.ProviderOverrides
526+
?.GetValueOrDefault(ProviderName.ToLowerInvariant())?.TextToSpeechModel;
527+
528+
if (!string.IsNullOrWhiteSpace(providerOverride))
529+
return providerOverride;
530+
531+
// Check global default
532+
var globalDefault = DefaultModels?.Audio?.DefaultTextToSpeechModel;
533+
if (!string.IsNullOrWhiteSpace(globalDefault))
534+
return globalDefault;
535+
536+
// Fallback to hardcoded default for backward compatibility
537+
return "eleven_monolingual_v1";
538+
}
539+
540+
/// <summary>
541+
/// Gets the default realtime model from configuration or falls back to eleven_conversational_v1.
542+
/// </summary>
543+
private string GetDefaultRealtimeModel()
544+
{
545+
// Check provider-specific override first
546+
var providerOverride = DefaultModels?.Realtime?.ProviderOverrides
547+
?.GetValueOrDefault(ProviderName.ToLowerInvariant());
548+
549+
if (!string.IsNullOrWhiteSpace(providerOverride))
550+
return providerOverride;
551+
552+
// Check global default
553+
var globalDefault = DefaultModels?.Realtime?.DefaultRealtimeModel;
554+
if (!string.IsNullOrWhiteSpace(globalDefault))
555+
return globalDefault;
556+
557+
// Fallback to hardcoded default for backward compatibility
558+
return "eleven_conversational_v1";
559+
}
560+
561+
#endregion
509562
}
510563

511564
/// <summary>
@@ -545,7 +598,7 @@ public async Task ConfigureAsync(RealtimeSessionConfig config, CancellationToken
545598
{
546599
["voice_id"] = config.Voice ?? "21m00Tcm4TlvDq8ikWAM",
547600
["language"] = config.Language ?? "en",
548-
["model_id"] = config.Model ?? "eleven_conversational_v1",
601+
["model_id"] = config.Model ?? "eleven_conversational_v1", // Model should be set in CreateSessionAsync
549602
["voice_settings"] = new Dictionary<string, object>
550603
{
551604
["stability"] = 0.5,

ConduitLLM.Providers/LLMClientFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ private ILLMClient CreateClientForProvider(string providerName, ProviderCredenti
177177
case "elevenlabs":
178178
case "eleven-labs":
179179
var elevenLabsLogger = _loggerFactory.CreateLogger<ElevenLabsClient>();
180-
return new ElevenLabsClient(credentials, modelId, elevenLabsLogger, _httpClientFactory);
180+
return new ElevenLabsClient(credentials, modelId, elevenLabsLogger, _httpClientFactory, defaultModels);
181181

182182
default:
183183
throw new UnsupportedProviderException($"Provider '{normalizedProviderName}' is not currently supported by ConduitLLM.");

docs/HARDCODED-MODELS-PROGRESS.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,21 @@
2828
- Replaced `"gpt-4o-realtime-preview"``GetDefaultRealtimeModel()`
2929
- Added configuration helper methods with fallbacks
3030

31+
2. **ElevenLabsClient** ✅ COMPLETE
32+
- Updated constructor to accept ProviderDefaultModels
33+
- Replaced `"eleven_monolingual_v1"``GetDefaultTextToSpeechModel()`
34+
- Replaced `"eleven_conversational_v1"``GetDefaultRealtimeModel()`
35+
- Added configuration helper methods with fallbacks
36+
- Updated LLMClientFactory to pass configuration
37+
3138
## Remaining Work
3239

3340
### Phase 2: Provider Updates (Continued)
3441

35-
1. **Update all provider constructors** (17 providers)
42+
1. **Update remaining provider constructors** (15 providers remaining)
3643
- Each needs to accept ProviderDefaultModels parameter
3744
- Pass it to base class constructor
38-
- Currently only OpenAIClient is updated
39-
40-
2. **ElevenLabsClient**
41-
- Replace `"eleven_monolingual_v1"` defaults
42-
- Replace `"eleven_conversational_v1"` defaults
43-
- Update constructor
45+
- OpenAIClient and ElevenLabsClient are complete
4446

4547
3. **VertexAIClient**
4648
- Move hardcoded model aliasing to configuration

0 commit comments

Comments
 (0)