Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
e828217c
Commit
e828217c
authored
Jul 24, 2023
by
StyleZhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: disable speech-to-text when provider is not openai
parent
c33d7a14
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
13 deletions
+50
-13
layout.tsx
web/app/(commonLayout)/layout.tsx
+7
-4
index.tsx
web/app/components/app/configuration/config/index.tsx
+5
-7
index.tsx
web/app/components/app/configuration/debug/index.tsx
+3
-2
provider-context.tsx
web/context/provider-context.tsx
+35
-0
No files found.
web/app/(commonLayout)/layout.tsx
View file @
e828217c
...
...
@@ -6,6 +6,7 @@ import GA, { GaType } from '@/app/components/base/ga'
import
HeaderWrapper
from
'@/app/components/header/HeaderWrapper'
import
Header
from
'@/app/components/header'
import
{
EventEmitterContextProvider
}
from
'@/context/event-emitter'
import
{
ProviderContextProvider
}
from
'@/context/provider-context'
const
Layout
=
({
children
}:
{
children
:
ReactNode
})
=>
{
return
(
...
...
@@ -14,10 +15,12 @@ const Layout = ({ children }: { children: ReactNode }) => {
<
SwrInitor
>
<
AppContextProvider
>
<
EventEmitterContextProvider
>
<
ProviderContextProvider
>
<
HeaderWrapper
>
<
Header
/>
</
HeaderWrapper
>
{
children
}
</
ProviderContextProvider
>
</
EventEmitterContextProvider
>
</
AppContextProvider
>
</
SwrInitor
>
...
...
web/app/components/app/configuration/config/index.tsx
View file @
e828217c
...
...
@@ -4,7 +4,6 @@ import React from 'react'
import
{
useContext
}
from
'use-context-selector'
import
produce
from
'immer'
import
{
useBoolean
}
from
'ahooks'
import
useSWR
from
'swr'
import
DatasetConfig
from
'../dataset-config'
import
ChatGroup
from
'../features/chat-group'
import
ExperienceEnchanceGroup
from
'../features/experience-enchance-group'
...
...
@@ -20,7 +19,7 @@ import ConfigPrompt from '@/app/components/app/configuration/config-prompt'
import
ConfigVar
from
'@/app/components/app/configuration/config-var'
import
type
{
PromptVariable
}
from
'@/models/debug'
import
{
AppType
}
from
'@/types/app'
import
{
fetchTenantInfo
}
from
'@/service/common
'
import
{
useProviderContext
}
from
'@/context/provider-context
'
const
Config
:
FC
=
()
=>
{
const
{
...
...
@@ -39,8 +38,7 @@ const Config: FC = () => {
setSpeechToTextConfig
,
}
=
useContext
(
ConfigContext
)
const
isChatApp
=
mode
===
AppType
.
chat
const
{
data
:
userInfo
}
=
useSWR
({
url
:
'/info'
},
fetchTenantInfo
)
const
openaiProvider
=
userInfo
?.
providers
?.
find
(({
token_is_set
,
is_valid
,
provider_name
})
=>
token_is_set
&&
is_valid
&&
provider_name
===
'openai'
)
const
{
currentProvider
}
=
useProviderContext
()
const
promptTemplate
=
modelConfig
.
configs
.
prompt_template
const
promptVariables
=
modelConfig
.
configs
.
prompt_variables
...
...
@@ -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
[
showAutomatic
,
{
setTrue
:
showAutomaticTrue
,
setFalse
:
showAutomaticFalse
}]
=
useBoolean
(
false
)
...
...
@@ -122,7 +120,7 @@ const Config: FC = () => {
isChatApp=
{
isChatApp
}
config=
{
featureConfig
}
onChange=
{
handleFeatureChange
}
showSpeechToTextItem=
{
!!
openaiProvider
}
showSpeechToTextItem=
{
currentProvider
?.
provider_name
===
'openai'
}
/>
)
}
{
showAutomatic
&&
(
...
...
@@ -162,7 +160,7 @@ const Config: FC = () => {
}
}
isShowSuggestedQuestionsAfterAnswer=
{
featureConfig
.
suggestedQuestionsAfterAnswer
}
isShowSpeechText=
{
featureConfig
.
speechToText
}
isShowSpeechText=
{
featureConfig
.
speechToText
&&
currentProvider
?.
provider_name
===
'openai'
}
/>
)
}
...
...
web/app/components/app/configuration/debug/index.tsx
View file @
e828217c
...
...
@@ -22,6 +22,7 @@ import type { ModelConfig as BackendModelConfig } from '@/types/app'
import
{
promptVariablesToUserInputsForm
}
from
'@/utils/model-config'
import
TextGeneration
from
'@/app/components/app/text-generate/item'
import
{
IS_CE_EDITION
}
from
'@/config'
import
{
useProviderContext
}
from
'@/context/provider-context'
type
IDebug
=
{
hasSetAPIKEY
:
boolean
...
...
@@ -51,7 +52,7 @@ const Debug: FC<IDebug> = ({
modelConfig
,
completionParams
,
}
=
useContext
(
ConfigContext
)
const
{
currentProvider
}
=
useProviderContext
()
const
[
chatList
,
setChatList
,
getChatList
]
=
useGetState
<
IChatItem
[]
>
([])
const
chatListDomRef
=
useRef
<
HTMLDivElement
>
(
null
)
useEffect
(()
=>
{
...
...
@@ -389,7 +390,7 @@ const Debug: FC<IDebug> = ({
}
}
isShowSuggestion=
{
doShowSuggestion
}
suggestionList=
{
suggestQuestions
}
isShowSpeechToText=
{
speechToTextConfig
.
enabled
}
isShowSpeechToText=
{
speechToTextConfig
.
enabled
&&
currentProvider
?.
provider_name
===
'openai'
}
/>
</
div
>
</
div
>
...
...
web/context/provider-context.tsx
0 → 100644
View file @
e828217c
'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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment