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
e7284142
Commit
e7284142
authored
Jul 07, 2023
by
StyleZhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
5a299625
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
11 deletions
+37
-11
app_model_config_service.py
api/services/app_model_config_service.py
+6
-0
audio_service.py
api/services/audio_service.py
+11
-2
index.tsx
...app/configuration/config/feature/choose-feature/index.tsx
+14
-8
index.tsx
web/app/components/app/configuration/config/index.tsx
+6
-1
No files found.
api/services/app_model_config_service.py
View file @
e7284142
...
...
@@ -4,6 +4,7 @@ import uuid
from
core.constant
import
llm_constant
from
models.account
import
Account
from
services.dataset_service
import
DatasetService
from
core.llm.llm_builder
import
LLMBuilder
class
AppModelConfigService
:
...
...
@@ -123,6 +124,11 @@ class AppModelConfigService:
if
not
isinstance
(
config
[
"speech_to_text"
][
"enabled"
],
bool
):
raise
ValueError
(
"enabled in speech_to_text must be of boolean type"
)
provider_name
=
LLMBuilder
.
get_default_provider
(
account
.
current_tenant_id
)
if
config
[
"speech_to_text"
][
"enabled"
]
and
provider_name
!=
'openai'
:
raise
ValueError
(
"provider not support speech to text"
)
# more_like_this
if
'more_like_this'
not
in
config
or
not
config
[
"more_like_this"
]:
...
...
api/services/audio_service.py
View file @
e7284142
...
...
@@ -4,6 +4,7 @@ from werkzeug.datastructures import FileStorage
from
core.llm.llm_builder
import
LLMBuilder
from
core.llm.provider.llm_provider_service
import
LLMProviderService
from
services.errors.audio
import
NoAudioUploadedError
,
AudioTooLargeError
,
UnsupportedAudioTypeError
from
openai.error
import
InvalidRequestError
FILE_SIZE_LIMIT
=
1
*
1024
*
1024
ALLOWED_EXTENSIONS
=
[
'mp3'
,
'mp4'
,
'mpeg'
,
'mpga'
,
'm4a'
,
'wav'
,
'webm'
]
...
...
@@ -32,7 +33,8 @@ class AudioService:
buffer
=
io
.
BytesIO
(
file_content
)
buffer
.
name
=
'temp.wav'
transcript
=
openai
.
Audio
.
transcribe
(
try
:
transcript
=
openai
.
Audio
.
transcribe
(
model
=
'whisper-1'
,
file
=
buffer
,
api_key
=
credentials
.
get
(
'openai_api_key'
),
...
...
@@ -42,4 +44,11 @@ class AudioService:
params
=
params
)
return
transcript
\ No newline at end of file
return
transcript
except
InvalidRequestError
as
e
:
return
{
'message'
:
str
(
e
)},
400
\ No newline at end of file
web/app/components/app/configuration/config/feature/choose-feature/index.tsx
View file @
e7284142
...
...
@@ -21,6 +21,7 @@ export type IChooseFeatureProps = {
config
:
IConfig
isChatApp
:
boolean
onChange
:
(
key
:
string
,
value
:
boolean
)
=>
void
showSpeechToTextItem
?:
boolean
}
const
OpeningStatementIcon
=
(
...
...
@@ -35,6 +36,7 @@ const ChooseFeature: FC<IChooseFeatureProps> = ({
isChatApp
,
config
,
onChange
,
showSpeechToTextItem
,
})
=>
{
const
{
t
}
=
useTranslation
()
...
...
@@ -71,14 +73,18 @@ const ChooseFeature: FC<IChooseFeatureProps> = ({
value=
{
config
.
suggestedQuestionsAfterAnswer
}
onChange=
{
value
=>
onChange
(
'suggestedQuestionsAfterAnswer'
,
value
)
}
/>
<
FeatureItem
icon=
{
<
Microphone01
className=
'w-4 h-4 text-[#7839EE]'
/>
}
previewImgClassName=
'speechToTextPreview'
title=
{
t
(
'appDebug.feature.speechToText.title'
)
}
description=
{
t
(
'appDebug.feature.speechToText.description'
)
}
value=
{
config
.
speechToText
}
onChange=
{
value
=>
onChange
(
'speechToText'
,
value
)
}
/>
{
showSpeechToTextItem
&&
(
<
FeatureItem
icon=
{
<
Microphone01
className=
'w-4 h-4 text-[#7839EE]'
/>
}
previewImgClassName=
'speechToTextPreview'
title=
{
t
(
'appDebug.feature.speechToText.title'
)
}
description=
{
t
(
'appDebug.feature.speechToText.description'
)
}
value=
{
config
.
speechToText
}
onChange=
{
value
=>
onChange
(
'speechToText'
,
value
)
}
/>
)
}
</>
</
FeatureGroup
>
)
}
...
...
web/app/components/app/configuration/config/index.tsx
View file @
e7284142
...
...
@@ -4,6 +4,7 @@ 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'
...
...
@@ -19,6 +20,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'
const
Config
:
FC
=
()
=>
{
const
{
...
...
@@ -37,6 +39,8 @@ const Config: FC = () => {
setSpeechToTextConfig
,
}
=
useContext
(
ConfigContext
)
const
isChatApp
=
mode
===
AppType
.
chat
const
{
data
:
userInfo
}
=
useSWR
({
url
:
'/info'
},
fetchTenantInfo
)
const
targetProvider
=
userInfo
?.
providers
?.
find
(({
token_is_set
,
is_valid
})
=>
token_is_set
&&
is_valid
)
const
promptTemplate
=
modelConfig
.
configs
.
prompt_template
const
promptVariables
=
modelConfig
.
configs
.
prompt_variables
...
...
@@ -88,7 +92,7 @@ const Config: FC = () => {
},
})
const
hasChatConfig
=
isChatApp
&&
(
featureConfig
.
openingStatement
||
featureConfig
.
suggestedQuestionsAfterAnswer
||
featureConfig
.
speechToText
)
const
hasChatConfig
=
isChatApp
&&
(
featureConfig
.
openingStatement
||
featureConfig
.
suggestedQuestionsAfterAnswer
||
(
featureConfig
.
speechToText
&&
targetProvider
?.
provider_name
===
'openai'
)
)
const
hasToolbox
=
false
const
[
showAutomatic
,
{
setTrue
:
showAutomaticTrue
,
setFalse
:
showAutomaticFalse
}]
=
useBoolean
(
false
)
...
...
@@ -118,6 +122,7 @@ const Config: FC = () => {
isChatApp=
{
isChatApp
}
config=
{
featureConfig
}
onChange=
{
handleFeatureChange
}
showSpeechToTextItem=
{
targetProvider
?.
provider_name
===
'openai'
}
/>
)
}
{
showAutomatic
&&
(
...
...
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