mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-29 05:36:13 +01:00
🌊 feat: refine SDK usage logic in STT and TTS services, improve header handling
This commit is contained in:
parent
b7f4903acd
commit
ffa5f6f09b
7 changed files with 14 additions and 19 deletions
|
|
@ -214,12 +214,12 @@ class STTService {
|
|||
}
|
||||
|
||||
// TODO: Implement a better way to determine if the SDK should be used
|
||||
shouldUseSDK(provider, sttSchema) {
|
||||
if (provider !== STTProviders.OPENAI && provider !== STTProviders.AZURE_OPENAI) {
|
||||
shouldUseSDK(provider) {
|
||||
if (provider === STTProviders.DEEPGRAM) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return typeof sttSchema.url === 'string' && sttSchema.url.trim().length > 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ class TTSService {
|
|||
[TTSProviders.AZURE_OPENAI]: this.azureOpenAIProvider.bind(this),
|
||||
[TTSProviders.ELEVENLABS]: this.elevenLabsProvider.bind(this),
|
||||
[TTSProviders.LOCALAI]: this.localAIProvider.bind(this),
|
||||
[TTSProviders.ELEVENLABS]: this.elevenLabsProvider.bind(this),
|
||||
};
|
||||
|
||||
this.sdkStrategies = {
|
||||
|
|
@ -129,7 +128,9 @@ class TTSService {
|
|||
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${extractEnvVariable(ttsSchema?.apiKey)}`,
|
||||
Authorization: `${
|
||||
ttsSchema.apiKey ? 'Bearer ' + extractEnvVariable(ttsSchema.apiKey) : undefined
|
||||
}`,
|
||||
};
|
||||
|
||||
return [url, data, headers];
|
||||
|
|
@ -199,7 +200,7 @@ class TTSService {
|
|||
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'xi-api-key': extractEnvVariable(ttsSchema?.apiKey),
|
||||
'xi-api-key': ttsSchema.apiKey ? extractEnvVariable(ttsSchema.apiKey) : '',
|
||||
Accept: 'audio/mpeg',
|
||||
};
|
||||
|
||||
|
|
@ -229,13 +230,11 @@ class TTSService {
|
|||
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${extractEnvVariable(ttsSchema?.apiKey)}`,
|
||||
Authorization: `${
|
||||
ttsSchema.apiKey ? 'Bearer ' + extractEnvVariable(ttsSchema.apiKey) : undefined
|
||||
}`,
|
||||
};
|
||||
|
||||
if (extractEnvVariable(ttsSchema.apiKey) === '') {
|
||||
delete headers.Authorization;
|
||||
}
|
||||
|
||||
return [url, data, headers];
|
||||
}
|
||||
|
||||
|
|
@ -314,12 +313,12 @@ class TTSService {
|
|||
}
|
||||
|
||||
// TODO: Implement a better way to determine if the SDK should be used
|
||||
shouldUseSDK(provider, sttSchema) {
|
||||
shouldUseSDK(provider) {
|
||||
if (provider == TTSProviders.DEEPGRAM) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return typeof sttSchema.url === 'string' && sttSchema.url.trim().length > 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -335,7 +334,7 @@ class TTSService {
|
|||
* @throws {Error} If the provider is invalid or the request fails.
|
||||
*/
|
||||
async ttsRequest(provider, ttsSchema, { input, voice, stream = true }) {
|
||||
const useSDK = this.shouldUseSDK(provider, ttsSchema);
|
||||
const useSDK = this.shouldUseSDK(provider);
|
||||
const strategy = useSDK ? this.sdkStrategies[provider] : this.apiStrategies[provider];
|
||||
|
||||
if (!strategy) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue