Skip to content

Commit

Permalink
🐛 fix: fix tts in new provider model (#5569)
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx authored Jan 23, 2025
1 parent 8f7d907 commit 3fef83e
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/services/_header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
OPENAI_API_KEY_HEADER_KEY,
OPENAI_END_POINT,
} from '@/const/fetch';
import { isDeprecatedEdition } from '@/const/version';
import { aiProviderSelectors, useAiInfraStore } from '@/store/aiInfra';
import { useUserStore } from '@/store/user';
import { keyVaultsConfigSelectors } from '@/store/user/selectors';

Expand All @@ -14,14 +16,23 @@ import { keyVaultsConfigSelectors } from '@/store/user/selectors';
// eslint-disable-next-line no-undef
export const createHeaderWithOpenAI = (header?: HeadersInit): HeadersInit => {
const state = useUserStore.getState();
const openAIConfig = keyVaultsConfigSelectors.openAIConfig(state);

let keyVaults: Record<string, any> = {};

// TODO: remove this condition in V2.0
if (isDeprecatedEdition) {
keyVaults = keyVaultsConfigSelectors.getVaultByProvider('openai' as any)(
useUserStore.getState(),
);
} else {
keyVaults = aiProviderSelectors.providerKeyVaults('openai')(useAiInfraStore.getState()) || {};
}
// eslint-disable-next-line no-undef
return {
...header,
[LOBE_CHAT_ACCESS_CODE]: keyVaultsConfigSelectors.password(state),
[LOBE_USER_ID]: state.user?.id || '',
[OPENAI_API_KEY_HEADER_KEY]: openAIConfig.apiKey || '',
[OPENAI_END_POINT]: openAIConfig.baseURL || '',
[OPENAI_API_KEY_HEADER_KEY]: keyVaults.apiKey || '',
[OPENAI_END_POINT]: keyVaults.baseURL || '',
};
};

0 comments on commit 3fef83e

Please sign in to comment.