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
b70dabed
Commit
b70dabed
authored
Jul 06, 2023
by
StyleZhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix count
parent
c4a90e8e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
14 deletions
+20
-14
completion.py
api/controllers/console/explore/completion.py
+0
-1
completion.py
api/controllers/web/completion.py
+1
-0
index.tsx
web/app/components/base/voice-input/index.tsx
+19
-13
No files found.
api/controllers/console/explore/completion.py
View file @
b70dabed
...
...
@@ -19,7 +19,6 @@ from core.llm.error import LLMBadRequestError, LLMAPIUnavailableError, LLMAuthor
LLMRateLimitError
,
ProviderTokenNotInitError
,
QuotaExceededError
,
ModelCurrentlyNotSupportError
from
libs.helper
import
uuid_value
from
services.completion_service
import
CompletionService
from
services.completion_service
import
CompletionService
# define completion api for user
...
...
api/controllers/web/completion.py
View file @
b70dabed
...
...
@@ -19,6 +19,7 @@ from core.llm.error import LLMBadRequestError, LLMAPIUnavailableError, LLMAuthor
from
libs.helper
import
uuid_value
from
services.completion_service
import
CompletionService
# define completion api for user
class
CompletionApi
(
WebApiResource
):
...
...
web/app/components/base/voice-input/index.tsx
View file @
b70dabed
...
...
@@ -2,6 +2,7 @@ import { useCallback, useEffect, useRef, useState } from 'react'
import
{
useTranslation
}
from
'react-i18next'
import
cn
from
'classnames'
import
Recorder
from
'js-audio-recorder'
import
{
useRafInterval
}
from
'ahooks'
import
s
from
'./index.module.css'
import
{
StopCircle
}
from
'@/app/components/base/icons/src/vender/solid/mediaAndDevices'
import
{
Loading02
,
XClose
}
from
'@/app/components/base/icons/src/vender/line/general'
...
...
@@ -23,10 +24,13 @@ const VoiceInput = ({
const
canvasRef
=
useRef
<
HTMLCanvasElement
|
null
>
(
null
)
const
ctxRef
=
useRef
<
CanvasRenderingContext2D
|
null
>
(
null
)
const
drawRecordId
=
useRef
<
number
|
null
>
(
null
)
const
[
duration
,
setDuration
]
=
useState
(
'00:00'
)
const
[
originDuration
,
setOriginDuration
]
=
useState
(
0
)
const
[
startRecord
,
setStartRecord
]
=
useState
(
false
)
const
[
startConvert
,
setStartConvert
]
=
useState
(
false
)
const
clearInterval
=
useRafInterval
(()
=>
{
setOriginDuration
(
originDuration
+
1
)
},
1000
)
const
drawRecord
=
useCallback
(()
=>
{
drawRecordId
.
current
=
requestAnimationFrame
(
drawRecord
)
const
canvas
=
canvasRef
.
current
!
...
...
@@ -58,6 +62,7 @@ const VoiceInput = ({
ctx
.
closePath
()
},
[])
const
handleStopRecorder
=
useCallback
(
async
()
=>
{
clearInterval
()
setStartRecord
(
false
)
setStartConvert
(
true
)
recorder
.
current
.
stop
()
...
...
@@ -85,15 +90,6 @@ const VoiceInput = ({
setStartRecord
(
true
)
setStartConvert
(
false
)
recorder
.
current
.
start
()
recorder
.
current
.
onprogress
=
(
params
)
=>
{
const
originDuration
=
params
.
duration
setOriginDuration
(
originDuration
)
if
(
originDuration
>=
120
)
handleStopRecorder
()
const
minutes
=
parseInt
(
`
${
parseInt
(
`
${
originDuration
}
`
)
/
60
}
`
)
const
seconds
=
parseInt
(
`
${
originDuration
}
`
)
%
60
setDuration
(
`0
${
minutes
.
toFixed
(
0
)}
:
${
seconds
>=
10
?
seconds
:
`0
${
seconds
}
`
}
`
)
}
if
(
canvasRef
.
current
&&
ctxRef
.
current
)
drawRecord
()
}
...
...
@@ -117,11 +113,21 @@ const VoiceInput = ({
}
}
}
if
(
originDuration
>=
120
&&
startRecord
)
handleStopRecorder
()
useEffect
(()
=>
{
initCanvas
()
handleStartRecord
()
initCanvas
();
(
Recorder
as
any
).
getPermission
().
then
(()
=>
{
handleStartRecord
()
},
()
=>
{
handleStopRecorder
()
})
},
[])
const
minutes
=
parseInt
(
`
${
parseInt
(
`
${
originDuration
}
`
)
/
60
}
`
)
const
seconds
=
parseInt
(
`
${
originDuration
}
`
)
%
60
return
(
<
div
className=
{
cn
(
s
.
wrapper
,
'absolute inset-0 rounded-xl'
)
}
>
<
div
className=
'absolute inset-[1.5px] flex items-center pl-[14.5px] pr-[6.5px] py-[14px] bg-primary-25 rounded-[10.5px] overflow-hidden'
>
...
...
@@ -165,7 +171,7 @@ const VoiceInput = ({
</
div
>
)
}
<
div
className=
{
`w-[45px] pl-1 text-xs font-medium ${originDuration > 110 ? 'text-[#F04438]' : 'text-gray-700'}`
}
>
{
duration
}
</
div
>
<
div
className=
{
`w-[45px] pl-1 text-xs font-medium ${originDuration > 110 ? 'text-[#F04438]' : 'text-gray-700'}`
}
>
{
`0${minutes.toFixed(0)}:${seconds >= 10 ? seconds : `
0
$
{
seconds
}
`}`
}
</
div
>
</
div
>
</
div
>
)
...
...
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