mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-02-14 05:24:24 +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
|
// TODO: Implement a better way to determine if the SDK should be used
|
||||||
shouldUseSDK(provider, sttSchema) {
|
shouldUseSDK(provider) {
|
||||||
if (provider !== STTProviders.OPENAI && provider !== STTProviders.AZURE_OPENAI) {
|
if (provider === STTProviders.DEEPGRAM) {
|
||||||
return true;
|
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.AZURE_OPENAI]: this.azureOpenAIProvider.bind(this),
|
||||||
[TTSProviders.ELEVENLABS]: this.elevenLabsProvider.bind(this),
|
[TTSProviders.ELEVENLABS]: this.elevenLabsProvider.bind(this),
|
||||||
[TTSProviders.LOCALAI]: this.localAIProvider.bind(this),
|
[TTSProviders.LOCALAI]: this.localAIProvider.bind(this),
|
||||||
[TTSProviders.ELEVENLABS]: this.elevenLabsProvider.bind(this),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.sdkStrategies = {
|
this.sdkStrategies = {
|
||||||
|
|
@ -129,7 +128,9 @@ class TTSService {
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
Authorization: `Bearer ${extractEnvVariable(ttsSchema?.apiKey)}`,
|
Authorization: `${
|
||||||
|
ttsSchema.apiKey ? 'Bearer ' + extractEnvVariable(ttsSchema.apiKey) : undefined
|
||||||
|
}`,
|
||||||
};
|
};
|
||||||
|
|
||||||
return [url, data, headers];
|
return [url, data, headers];
|
||||||
|
|
@ -199,7 +200,7 @@ class TTSService {
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'xi-api-key': extractEnvVariable(ttsSchema?.apiKey),
|
'xi-api-key': ttsSchema.apiKey ? extractEnvVariable(ttsSchema.apiKey) : '',
|
||||||
Accept: 'audio/mpeg',
|
Accept: 'audio/mpeg',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -229,13 +230,11 @@ class TTSService {
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
'Content-Type': 'application/json',
|
'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];
|
return [url, data, headers];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -314,12 +313,12 @@ class TTSService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement a better way to determine if the SDK should be used
|
// TODO: Implement a better way to determine if the SDK should be used
|
||||||
shouldUseSDK(provider, sttSchema) {
|
shouldUseSDK(provider) {
|
||||||
if (provider == TTSProviders.DEEPGRAM) {
|
if (provider == TTSProviders.DEEPGRAM) {
|
||||||
return true;
|
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.
|
* @throws {Error} If the provider is invalid or the request fails.
|
||||||
*/
|
*/
|
||||||
async ttsRequest(provider, ttsSchema, { input, voice, stream = true }) {
|
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];
|
const strategy = useSDK ? this.sdkStrategies[provider] : this.apiStrategies[provider];
|
||||||
|
|
||||||
if (!strategy) {
|
if (!strategy) {
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ export default function HoverButtons({
|
||||||
messageId={message.messageId}
|
messageId={message.messageId}
|
||||||
content={message.content ?? message.text}
|
content={message.content ?? message.text}
|
||||||
isLast={isLast}
|
isLast={isLast}
|
||||||
className="hover-button rounded-md p-1 pl-0 text-gray-500 hover:bg-gray-100 hover:text-gray-500 dark:text-gray-400/70 dark:hover:bg-gray-700 dark:hover:text-gray-200 disabled:dark:hover:text-gray-400 md:group-hover:visible md:group-[.final-completion]:visible"
|
className="hover-button rounded-md p-1 hover:bg-gray-100 hover:text-gray-500 focus:opacity-100 dark:text-gray-400/70 dark:hover:bg-gray-700 dark:hover:text-gray-200 disabled:dark:hover:text-gray-400 md:group-hover:visible md:group-[.final-completion]:visible"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{isEditableEndpoint && (
|
{isEditableEndpoint && (
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
// client/src/components/Chat/Messages/MessageAudio.tsx
|
|
||||||
import { memo } from 'react';
|
import { memo } from 'react';
|
||||||
import { useRecoilValue } from 'recoil';
|
import { useRecoilValue } from 'recoil';
|
||||||
import type { TMessageAudio } from '~/common';
|
import type { TMessageAudio } from '~/common';
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
// client/src/hooks/Audio/useTTSBrowser.ts
|
|
||||||
import { useRef, useEffect, useState } from 'react';
|
import { useRef, useEffect, useState } from 'react';
|
||||||
import { useRecoilState, useRecoilValue } from 'recoil';
|
import { useRecoilState, useRecoilValue } from 'recoil';
|
||||||
import { parseTextParts } from 'librechat-data-provider';
|
import { parseTextParts } from 'librechat-data-provider';
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
// client/src/hooks/Audio/useTTSEdge.ts
|
|
||||||
import { useRef, useEffect, useState } from 'react';
|
import { useRef, useEffect, useState } from 'react';
|
||||||
import { useRecoilState, useRecoilValue } from 'recoil';
|
import { useRecoilState, useRecoilValue } from 'recoil';
|
||||||
import { parseTextParts } from 'librechat-data-provider';
|
import { parseTextParts } from 'librechat-data-provider';
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
// client/src/hooks/Audio/useTTSExternal.ts
|
|
||||||
import { useRef, useEffect, useState } from 'react';
|
import { useRef, useEffect, useState } from 'react';
|
||||||
import { useRecoilState, useRecoilValue } from 'recoil';
|
import { useRecoilState, useRecoilValue } from 'recoil';
|
||||||
import { parseTextParts } from 'librechat-data-provider';
|
import { parseTextParts } from 'librechat-data-provider';
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue