Commit e828217c authored by StyleZhang's avatar StyleZhang

fix: disable speech-to-text when provider is not openai

parent c33d7a14
...@@ -6,6 +6,7 @@ import GA, { GaType } from '@/app/components/base/ga' ...@@ -6,6 +6,7 @@ import GA, { GaType } from '@/app/components/base/ga'
import HeaderWrapper from '@/app/components/header/HeaderWrapper' import HeaderWrapper from '@/app/components/header/HeaderWrapper'
import Header from '@/app/components/header' import Header from '@/app/components/header'
import { EventEmitterContextProvider } from '@/context/event-emitter' import { EventEmitterContextProvider } from '@/context/event-emitter'
import { ProviderContextProvider } from '@/context/provider-context'
const Layout = ({ children }: { children: ReactNode }) => { const Layout = ({ children }: { children: ReactNode }) => {
return ( return (
...@@ -14,10 +15,12 @@ const Layout = ({ children }: { children: ReactNode }) => { ...@@ -14,10 +15,12 @@ const Layout = ({ children }: { children: ReactNode }) => {
<SwrInitor> <SwrInitor>
<AppContextProvider> <AppContextProvider>
<EventEmitterContextProvider> <EventEmitterContextProvider>
<HeaderWrapper> <ProviderContextProvider>
<Header /> <HeaderWrapper>
</HeaderWrapper> <Header />
{children} </HeaderWrapper>
{children}
</ProviderContextProvider>
</EventEmitterContextProvider> </EventEmitterContextProvider>
</AppContextProvider> </AppContextProvider>
</SwrInitor> </SwrInitor>
......
...@@ -4,7 +4,6 @@ import React from 'react' ...@@ -4,7 +4,6 @@ import React from 'react'
import { useContext } from 'use-context-selector' import { useContext } from 'use-context-selector'
import produce from 'immer' import produce from 'immer'
import { useBoolean } from 'ahooks' import { useBoolean } from 'ahooks'
import useSWR from 'swr'
import DatasetConfig from '../dataset-config' import DatasetConfig from '../dataset-config'
import ChatGroup from '../features/chat-group' import ChatGroup from '../features/chat-group'
import ExperienceEnchanceGroup from '../features/experience-enchance-group' import ExperienceEnchanceGroup from '../features/experience-enchance-group'
...@@ -20,7 +19,7 @@ import ConfigPrompt from '@/app/components/app/configuration/config-prompt' ...@@ -20,7 +19,7 @@ import ConfigPrompt from '@/app/components/app/configuration/config-prompt'
import ConfigVar from '@/app/components/app/configuration/config-var' import ConfigVar from '@/app/components/app/configuration/config-var'
import type { PromptVariable } from '@/models/debug' import type { PromptVariable } from '@/models/debug'
import { AppType } from '@/types/app' import { AppType } from '@/types/app'
import { fetchTenantInfo } from '@/service/common' import { useProviderContext } from '@/context/provider-context'
const Config: FC = () => { const Config: FC = () => {
const { const {
...@@ -39,8 +38,7 @@ const Config: FC = () => { ...@@ -39,8 +38,7 @@ const Config: FC = () => {
setSpeechToTextConfig, setSpeechToTextConfig,
} = useContext(ConfigContext) } = useContext(ConfigContext)
const isChatApp = mode === AppType.chat const isChatApp = mode === AppType.chat
const { data: userInfo } = useSWR({ url: '/info' }, fetchTenantInfo) const { currentProvider } = useProviderContext()
const openaiProvider = userInfo?.providers?.find(({ token_is_set, is_valid, provider_name }) => token_is_set && is_valid && provider_name === 'openai')
const promptTemplate = modelConfig.configs.prompt_template const promptTemplate = modelConfig.configs.prompt_template
const promptVariables = modelConfig.configs.prompt_variables const promptVariables = modelConfig.configs.prompt_variables
...@@ -92,7 +90,7 @@ const Config: FC = () => { ...@@ -92,7 +90,7 @@ const Config: FC = () => {
}, },
}) })
const hasChatConfig = isChatApp && (featureConfig.openingStatement || featureConfig.suggestedQuestionsAfterAnswer || (featureConfig.speechToText && openaiProvider)) const hasChatConfig = isChatApp && (featureConfig.openingStatement || featureConfig.suggestedQuestionsAfterAnswer || (featureConfig.speechToText && currentProvider?.provider_name === 'openai'))
const hasToolbox = false const hasToolbox = false
const [showAutomatic, { setTrue: showAutomaticTrue, setFalse: showAutomaticFalse }] = useBoolean(false) const [showAutomatic, { setTrue: showAutomaticTrue, setFalse: showAutomaticFalse }] = useBoolean(false)
...@@ -122,7 +120,7 @@ const Config: FC = () => { ...@@ -122,7 +120,7 @@ const Config: FC = () => {
isChatApp={isChatApp} isChatApp={isChatApp}
config={featureConfig} config={featureConfig}
onChange={handleFeatureChange} onChange={handleFeatureChange}
showSpeechToTextItem={!!openaiProvider} showSpeechToTextItem={currentProvider?.provider_name === 'openai'}
/> />
)} )}
{showAutomatic && ( {showAutomatic && (
...@@ -162,7 +160,7 @@ const Config: FC = () => { ...@@ -162,7 +160,7 @@ const Config: FC = () => {
} }
} }
isShowSuggestedQuestionsAfterAnswer={featureConfig.suggestedQuestionsAfterAnswer} isShowSuggestedQuestionsAfterAnswer={featureConfig.suggestedQuestionsAfterAnswer}
isShowSpeechText={featureConfig.speechToText} isShowSpeechText={featureConfig.speechToText && currentProvider?.provider_name === 'openai'}
/> />
) )
} }
......
...@@ -22,6 +22,7 @@ import type { ModelConfig as BackendModelConfig } from '@/types/app' ...@@ -22,6 +22,7 @@ import type { ModelConfig as BackendModelConfig } from '@/types/app'
import { promptVariablesToUserInputsForm } from '@/utils/model-config' import { promptVariablesToUserInputsForm } from '@/utils/model-config'
import TextGeneration from '@/app/components/app/text-generate/item' import TextGeneration from '@/app/components/app/text-generate/item'
import { IS_CE_EDITION } from '@/config' import { IS_CE_EDITION } from '@/config'
import { useProviderContext } from '@/context/provider-context'
type IDebug = { type IDebug = {
hasSetAPIKEY: boolean hasSetAPIKEY: boolean
...@@ -51,7 +52,7 @@ const Debug: FC<IDebug> = ({ ...@@ -51,7 +52,7 @@ const Debug: FC<IDebug> = ({
modelConfig, modelConfig,
completionParams, completionParams,
} = useContext(ConfigContext) } = useContext(ConfigContext)
const { currentProvider } = useProviderContext()
const [chatList, setChatList, getChatList] = useGetState<IChatItem[]>([]) const [chatList, setChatList, getChatList] = useGetState<IChatItem[]>([])
const chatListDomRef = useRef<HTMLDivElement>(null) const chatListDomRef = useRef<HTMLDivElement>(null)
useEffect(() => { useEffect(() => {
...@@ -389,7 +390,7 @@ const Debug: FC<IDebug> = ({ ...@@ -389,7 +390,7 @@ const Debug: FC<IDebug> = ({
}} }}
isShowSuggestion={doShowSuggestion} isShowSuggestion={doShowSuggestion}
suggestionList={suggestQuestions} suggestionList={suggestQuestions}
isShowSpeechToText={speechToTextConfig.enabled} isShowSpeechToText={speechToTextConfig.enabled && currentProvider?.provider_name === 'openai'}
/> />
</div> </div>
</div> </div>
......
'use client'
import { createContext, useContext } from 'use-context-selector'
import useSWR from 'swr'
import { fetchTenantInfo } from '@/service/common'
const ProviderContext = createContext<{ currentProvider: {
provider: string
provider_name: string
token_is_set: boolean
is_valid: boolean
token_is_valid: boolean
} | null | undefined }>({
currentProvider: null,
})
export const useProviderContext = () => useContext(ProviderContext)
type ProviderContextProviderProps = {
children: React.ReactNode
}
export const ProviderContextProvider = ({
children,
}: ProviderContextProviderProps) => {
const { data: userInfo } = useSWR({ url: '/info' }, fetchTenantInfo)
const currentProvider = userInfo?.providers?.find(({ token_is_set, is_valid }) => token_is_set && is_valid)
return (
<ProviderContext.Provider value={{ currentProvider }}>
{children}
</ProviderContext.Provider>
)
}
export default ProviderContext
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment