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
3e380c08
Unverified
Commit
3e380c08
authored
Jun 06, 2023
by
Joel
Committed by
GitHub
Jun 06, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: reset some config not work: like var required status, dataset, feature status (#305)
parent
53db5bab
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
147 additions
and
121 deletions
+147
-121
index.tsx
web/app/components/app/configuration/config/index.tsx
+5
-5
index.tsx
web/app/components/app/configuration/debug/index.tsx
+2
-2
index.tsx
web/app/components/app/configuration/index.tsx
+59
-42
index.tsx
web/app/components/base/switch/index.tsx
+9
-5
index.tsx
web/app/components/share/text-generation/index.tsx
+3
-3
debug-configuration.ts
web/context/debug-configuration.ts
+6
-6
debug.ts
web/models/debug.ts
+63
-58
No files found.
web/app/components/app/configuration/config/index.tsx
View file @
3e380c08
...
@@ -29,8 +29,8 @@ const Config: FC = () => {
...
@@ -29,8 +29,8 @@ const Config: FC = () => {
setModelConfig
,
setModelConfig
,
setPrevPromptConfig
,
setPrevPromptConfig
,
setFormattingChanged
,
setFormattingChanged
,
moreLikeThisCon
if
g
,
moreLikeThisCon
fi
g
,
setMoreLikeThisCon
if
g
,
setMoreLikeThisCon
fi
g
,
suggestedQuestionsAfterAnswerConfig
,
suggestedQuestionsAfterAnswerConfig
,
setSuggestedQuestionsAfterAnswerConfig
,
setSuggestedQuestionsAfterAnswerConfig
,
}
=
useContext
(
ConfigContext
)
}
=
useContext
(
ConfigContext
)
...
@@ -66,9 +66,9 @@ const Config: FC = () => {
...
@@ -66,9 +66,9 @@ const Config: FC = () => {
const
{
featureConfig
,
handleFeatureChange
}
=
useFeature
({
const
{
featureConfig
,
handleFeatureChange
}
=
useFeature
({
introduction
,
introduction
,
setIntroduction
,
setIntroduction
,
moreLikeThis
:
moreLikeThisCon
if
g
.
enabled
,
moreLikeThis
:
moreLikeThisCon
fi
g
.
enabled
,
setMoreLikeThis
:
(
value
)
=>
{
setMoreLikeThis
:
(
value
)
=>
{
setMoreLikeThisCon
ifg
(
produce
(
moreLikeThisConif
g
,
(
draft
)
=>
{
setMoreLikeThisCon
fig
(
produce
(
moreLikeThisConfi
g
,
(
draft
)
=>
{
draft
.
enabled
=
value
draft
.
enabled
=
value
}))
}))
},
},
...
@@ -154,7 +154,7 @@ const Config: FC = () => {
...
@@ -154,7 +154,7 @@ const Config: FC = () => {
}
}
{
/* TextnGeneration config */
}
{
/* TextnGeneration config */
}
{
moreLikeThisCon
if
g
.
enabled
&&
(
{
moreLikeThisCon
fi
g
.
enabled
&&
(
<
ExperienceEnchanceGroup
/>
<
ExperienceEnchanceGroup
/>
)
}
)
}
...
...
web/app/components/app/configuration/debug/index.tsx
View file @
3e380c08
...
@@ -38,7 +38,7 @@ const Debug: FC<IDebug> = ({
...
@@ -38,7 +38,7 @@ const Debug: FC<IDebug> = ({
mode
,
mode
,
introduction
,
introduction
,
suggestedQuestionsAfterAnswerConfig
,
suggestedQuestionsAfterAnswerConfig
,
moreLikeThisCon
if
g
,
moreLikeThisCon
fi
g
,
inputs
,
inputs
,
// setInputs,
// setInputs,
formattingChanged
,
formattingChanged
,
...
@@ -304,7 +304,7 @@ const Debug: FC<IDebug> = ({
...
@@ -304,7 +304,7 @@ const Debug: FC<IDebug> = ({
user_input_form
:
promptVariablesToUserInputsForm
(
modelConfig
.
configs
.
prompt_variables
),
user_input_form
:
promptVariablesToUserInputsForm
(
modelConfig
.
configs
.
prompt_variables
),
opening_statement
:
introduction
,
opening_statement
:
introduction
,
suggested_questions_after_answer
:
suggestedQuestionsAfterAnswerConfig
,
suggested_questions_after_answer
:
suggestedQuestionsAfterAnswerConfig
,
more_like_this
:
moreLikeThisCon
if
g
,
more_like_this
:
moreLikeThisCon
fi
g
,
agent_mode
:
{
agent_mode
:
{
enabled
:
true
,
enabled
:
true
,
tools
:
[...
postDatasets
],
tools
:
[...
postDatasets
],
...
...
web/app/components/app/configuration/index.tsx
View file @
3e380c08
...
@@ -5,7 +5,10 @@ import { useTranslation } from 'react-i18next'
...
@@ -5,7 +5,10 @@ import { useTranslation } from 'react-i18next'
import
{
useContext
}
from
'use-context-selector'
import
{
useContext
}
from
'use-context-selector'
import
{
usePathname
}
from
'next/navigation'
import
{
usePathname
}
from
'next/navigation'
import
produce
from
'immer'
import
produce
from
'immer'
import
type
{
CompletionParams
,
Inputs
,
ModelConfig
,
PromptConfig
,
PromptVariable
,
MoreLikeThisConfig
}
from
'@/models/debug'
import
{
useBoolean
}
from
'ahooks'
import
Button
from
'../../base/button'
import
Loading
from
'../../base/loading'
import
type
{
CompletionParams
,
Inputs
,
ModelConfig
,
MoreLikeThisConfig
,
PromptConfig
,
PromptVariable
}
from
'@/models/debug'
import
type
{
DataSet
}
from
'@/models/datasets'
import
type
{
DataSet
}
from
'@/models/datasets'
import
type
{
ModelConfig
as
BackendModelConfig
}
from
'@/types/app'
import
type
{
ModelConfig
as
BackendModelConfig
}
from
'@/types/app'
import
ConfigContext
from
'@/context/debug-configuration'
import
ConfigContext
from
'@/context/debug-configuration'
...
@@ -17,12 +20,9 @@ import type { AppDetailResponse } from '@/models/app'
...
@@ -17,12 +20,9 @@ import type { AppDetailResponse } from '@/models/app'
import
{
ToastContext
}
from
'@/app/components/base/toast'
import
{
ToastContext
}
from
'@/app/components/base/toast'
import
{
fetchTenantInfo
}
from
'@/service/common'
import
{
fetchTenantInfo
}
from
'@/service/common'
import
{
fetchAppDetail
,
updateAppModelConfig
}
from
'@/service/apps'
import
{
fetchAppDetail
,
updateAppModelConfig
}
from
'@/service/apps'
import
{
userInputsFormToPromptVariables
,
promptVariablesToUserInputsForm
}
from
'@/utils/model-config'
import
{
promptVariablesToUserInputsForm
,
userInputsFormToPromptVariables
}
from
'@/utils/model-config'
import
{
fetchDatasets
}
from
'@/service/datasets'
import
{
fetchDatasets
}
from
'@/service/datasets'
import
AccountSetting
from
'@/app/components/header/account-setting'
import
AccountSetting
from
'@/app/components/header/account-setting'
import
{
useBoolean
}
from
'ahooks'
import
Button
from
'../../base/button'
import
Loading
from
'../../base/loading'
const
Configuration
:
FC
=
()
=>
{
const
Configuration
:
FC
=
()
=>
{
const
{
t
}
=
useTranslation
()
const
{
t
}
=
useTranslation
()
...
@@ -35,8 +35,8 @@ const Configuration: FC = () => {
...
@@ -35,8 +35,8 @@ const Configuration: FC = () => {
const
matched
=
pathname
.
match
(
/
\/
app
\/([^/]
+
)
/
)
const
matched
=
pathname
.
match
(
/
\/
app
\/([^/]
+
)
/
)
const
appId
=
(
matched
?.
length
&&
matched
[
1
])
?
matched
[
1
]
:
''
const
appId
=
(
matched
?.
length
&&
matched
[
1
])
?
matched
[
1
]
:
''
const
[
mode
,
setMode
]
=
useState
(
''
)
const
[
mode
,
setMode
]
=
useState
(
''
)
const
[
pu
sblisedConfig
,
setPusblis
edConfig
]
=
useState
<
{
const
[
pu
blishedConfig
,
setPublish
edConfig
]
=
useState
<
{
modelConfig
:
ModelConfig
,
modelConfig
:
ModelConfig
completionParams
:
CompletionParams
completionParams
:
CompletionParams
}
|
null
>
(
null
)
}
|
null
>
(
null
)
...
@@ -47,7 +47,7 @@ const Configuration: FC = () => {
...
@@ -47,7 +47,7 @@ const Configuration: FC = () => {
prompt_template
:
''
,
prompt_template
:
''
,
prompt_variables
:
[],
prompt_variables
:
[],
})
})
const
[
moreLikeThisCon
ifg
,
setMoreLikeThisConif
g
]
=
useState
<
MoreLikeThisConfig
>
({
const
[
moreLikeThisCon
fig
,
setMoreLikeThisConfi
g
]
=
useState
<
MoreLikeThisConfig
>
({
enabled
:
false
,
enabled
:
false
,
})
})
const
[
suggestedQuestionsAfterAnswerConfig
,
setSuggestedQuestionsAfterAnswerConfig
]
=
useState
<
MoreLikeThisConfig
>
({
const
[
suggestedQuestionsAfterAnswerConfig
,
setSuggestedQuestionsAfterAnswerConfig
]
=
useState
<
MoreLikeThisConfig
>
({
...
@@ -70,6 +70,10 @@ const Configuration: FC = () => {
...
@@ -70,6 +70,10 @@ const Configuration: FC = () => {
prompt_template
:
''
,
prompt_template
:
''
,
prompt_variables
:
[]
as
PromptVariable
[],
prompt_variables
:
[]
as
PromptVariable
[],
},
},
opening_statement
:
''
,
more_like_this
:
null
,
suggested_questions_after_answer
:
null
,
dataSets
:
[],
})
})
const
setModelConfig
=
(
newModelConfig
:
ModelConfig
)
=>
{
const
setModelConfig
=
(
newModelConfig
:
ModelConfig
)
=>
{
...
@@ -77,19 +81,29 @@ const Configuration: FC = () => {
...
@@ -77,19 +81,29 @@ const Configuration: FC = () => {
}
}
const
setModelId
=
(
modelId
:
string
)
=>
{
const
setModelId
=
(
modelId
:
string
)
=>
{
const
newModelConfig
=
produce
(
modelConfig
,
(
draft
)
=>
{
const
newModelConfig
=
produce
(
modelConfig
,
(
draft
:
any
)
=>
{
draft
.
model_id
=
modelId
draft
.
model_id
=
modelId
})
})
setModelConfig
(
newModelConfig
)
setModelConfig
(
newModelConfig
)
}
}
const
syncToPublishedConfig
=
(
_pusblisedConfig
:
any
)
=>
{
setModelConfig
(
_pusblisedConfig
.
modelConfig
)
setCompletionParams
(
_pusblisedConfig
.
completionParams
)
}
const
[
dataSets
,
setDataSets
]
=
useState
<
DataSet
[]
>
([])
const
[
dataSets
,
setDataSets
]
=
useState
<
DataSet
[]
>
([])
const
syncToPublishedConfig
=
(
_publishedConfig
:
any
)
=>
{
const
modelConfig
=
_publishedConfig
.
modelConfig
setModelConfig
(
_publishedConfig
.
modelConfig
)
setCompletionParams
(
_publishedConfig
.
completionParams
)
setDataSets
(
modelConfig
.
dataSets
||
[])
// feature
setIntroduction
(
modelConfig
.
opening_statement
)
setMoreLikeThisConfig
(
modelConfig
.
more_like_this
||
{
enabled
:
false
,
})
setSuggestedQuestionsAfterAnswerConfig
(
modelConfig
.
suggested_questions_after_answer
||
{
enabled
:
false
,
})
}
const
[
hasSetCustomAPIKEY
,
setHasSetCustomerAPIKEY
]
=
useState
(
true
)
const
[
hasSetCustomAPIKEY
,
setHasSetCustomerAPIKEY
]
=
useState
(
true
)
const
[
isTrailFinished
,
setIsTrailFinished
]
=
useState
(
false
)
const
[
isTrailFinished
,
setIsTrailFinished
]
=
useState
(
false
)
const
hasSetAPIKEY
=
hasSetCustomAPIKEY
||
!
isTrailFinished
const
hasSetAPIKEY
=
hasSetCustomAPIKEY
||
!
isTrailFinished
...
@@ -116,35 +130,40 @@ const Configuration: FC = () => {
...
@@ -116,35 +130,40 @@ const Configuration: FC = () => {
const
model
=
res
.
model_config
.
model
const
model
=
res
.
model_config
.
model
let
datasets
:
any
=
null
let
datasets
:
any
=
null
if
(
modelConfig
.
agent_mode
?.
enabled
)
{
if
(
modelConfig
.
agent_mode
?.
enabled
)
datasets
=
modelConfig
.
agent_mode
?.
tools
.
filter
(({
dataset
}:
any
)
=>
dataset
?.
enabled
)
datasets
=
modelConfig
.
agent_mode
?.
tools
.
filter
(({
dataset
}:
any
)
=>
dataset
?.
enabled
)
}
if
(
dataSets
&&
datasets
?.
length
&&
datasets
?.
length
>
0
)
{
if
(
dataSets
&&
datasets
?.
length
&&
datasets
?.
length
>
0
)
{
const
{
data
:
dataSetsWithDetail
}
=
await
fetchDatasets
({
url
:
'/datasets'
,
params
:
{
page
:
1
,
ids
:
datasets
.
map
(({
dataset
}:
any
)
=>
dataset
.
id
)
}
})
const
{
data
:
dataSetsWithDetail
}
=
await
fetchDatasets
({
url
:
'/datasets'
,
params
:
{
page
:
1
,
ids
:
datasets
.
map
(({
dataset
}:
any
)
=>
dataset
.
id
)
}
})
datasets
=
dataSetsWithDetail
datasets
=
dataSetsWithDetail
setDataSets
(
datasets
)
setDataSets
(
datasets
)
}
}
setIntroduction
(
modelConfig
.
opening_statement
)
if
(
modelConfig
.
more_like_this
)
setMoreLikeThisConfig
(
modelConfig
.
more_like_this
)
if
(
modelConfig
.
suggested_questions_after_answer
)
setSuggestedQuestionsAfterAnswerConfig
(
modelConfig
.
suggested_questions_after_answer
)
const
config
=
{
const
config
=
{
modelConfig
:
{
modelConfig
:
{
provider
:
model
.
provider
,
provider
:
model
.
provider
,
model_id
:
model
.
name
,
model_id
:
model
.
name
,
configs
:
{
configs
:
{
prompt_template
:
modelConfig
.
pre_prompt
,
prompt_template
:
modelConfig
.
pre_prompt
,
prompt_variables
:
userInputsFormToPromptVariables
(
modelConfig
.
user_input_form
)
prompt_variables
:
userInputsFormToPromptVariables
(
modelConfig
.
user_input_form
)
,
},
},
opening_statement
:
modelConfig
.
opening_statement
,
more_like_this
:
modelConfig
.
more_like_this
,
suggested_questions_after_answer
:
modelConfig
.
suggested_questions_after_answer
,
dataSets
:
datasets
||
[],
},
},
completionParams
:
model
.
completion_params
,
completionParams
:
model
.
completion_params
,
}
}
syncToPublishedConfig
(
config
)
syncToPublishedConfig
(
config
)
setPusblisedConfig
(
config
)
setPublishedConfig
(
config
)
setIntroduction
(
modelConfig
.
opening_statement
)
if
(
modelConfig
.
more_like_this
)
{
setMoreLikeThisConifg
(
modelConfig
.
more_like_this
)
}
if
(
modelConfig
.
suggested_questions_after_answer
)
{
setSuggestedQuestionsAfterAnswerConfig
(
modelConfig
.
suggested_questions_after_answer
)
}
setHasFetchedDetail
(
true
)
setHasFetchedDetail
(
true
)
})
})
},
[
appId
])
},
[
appId
])
...
@@ -154,18 +173,11 @@ const Configuration: FC = () => {
...
@@ -154,18 +173,11 @@ const Configuration: FC = () => {
const
promptTemplate
=
modelConfig
.
configs
.
prompt_template
const
promptTemplate
=
modelConfig
.
configs
.
prompt_template
const
promptVariables
=
modelConfig
.
configs
.
prompt_variables
const
promptVariables
=
modelConfig
.
configs
.
prompt_variables
// not save empty key adn name
// const missingNameItem = promptVariables.find(item => item.name.trim() === '')
// if (missingNameItem) {
// notify({ type: 'error', message: t('appDebug.errorMessage.nameOfKeyRequired', { key: missingNameItem.key }) })
// return
// }
const
postDatasets
=
dataSets
.
map
(({
id
})
=>
({
const
postDatasets
=
dataSets
.
map
(({
id
})
=>
({
dataset
:
{
dataset
:
{
enabled
:
true
,
enabled
:
true
,
id
,
id
,
}
}
,
}))
}))
// new model config data struct
// new model config data struct
...
@@ -173,11 +185,11 @@ const Configuration: FC = () => {
...
@@ -173,11 +185,11 @@ const Configuration: FC = () => {
pre_prompt
:
promptTemplate
,
pre_prompt
:
promptTemplate
,
user_input_form
:
promptVariablesToUserInputsForm
(
promptVariables
),
user_input_form
:
promptVariablesToUserInputsForm
(
promptVariables
),
opening_statement
:
introduction
||
''
,
opening_statement
:
introduction
||
''
,
more_like_this
:
moreLikeThisCon
if
g
,
more_like_this
:
moreLikeThisCon
fi
g
,
suggested_questions_after_answer
:
suggestedQuestionsAfterAnswerConfig
,
suggested_questions_after_answer
:
suggestedQuestionsAfterAnswerConfig
,
agent_mode
:
{
agent_mode
:
{
enabled
:
true
,
enabled
:
true
,
tools
:
[...
postDatasets
]
tools
:
[...
postDatasets
]
,
},
},
model
:
{
model
:
{
provider
:
modelConfig
.
provider
,
provider
:
modelConfig
.
provider
,
...
@@ -187,8 +199,14 @@ const Configuration: FC = () => {
...
@@ -187,8 +199,14 @@ const Configuration: FC = () => {
}
}
await
updateAppModelConfig
({
url
:
`/apps/
${
appId
}
/model-config`
,
body
:
data
})
await
updateAppModelConfig
({
url
:
`/apps/
${
appId
}
/model-config`
,
body
:
data
})
setPusblisedConfig
({
const
newModelConfig
=
produce
(
modelConfig
,
(
draft
:
any
)
=>
{
modelConfig
,
draft
.
opening_statement
=
introduction
draft
.
more_like_this
=
moreLikeThisConfig
draft
.
suggested_questions_after_answer
=
suggestedQuestionsAfterAnswerConfig
draft
.
dataSets
=
dataSets
})
setPublishedConfig
({
modelConfig
:
newModelConfig
,
completionParams
,
completionParams
,
})
})
notify
({
type
:
'success'
,
message
:
t
(
'common.api.success'
),
duration
:
3000
})
notify
({
type
:
'success'
,
message
:
t
(
'common.api.success'
),
duration
:
3000
})
...
@@ -196,8 +214,7 @@ const Configuration: FC = () => {
...
@@ -196,8 +214,7 @@ const Configuration: FC = () => {
const
[
showConfirm
,
setShowConfirm
]
=
useState
(
false
)
const
[
showConfirm
,
setShowConfirm
]
=
useState
(
false
)
const
resetAppConfig
=
()
=>
{
const
resetAppConfig
=
()
=>
{
// debugger
syncToPublishedConfig
(
publishedConfig
)
syncToPublishedConfig
(
pusblisedConfig
)
setShowConfirm
(
false
)
setShowConfirm
(
false
)
}
}
...
@@ -224,8 +241,8 @@ const Configuration: FC = () => {
...
@@ -224,8 +241,8 @@ const Configuration: FC = () => {
setControlClearChatMessage
,
setControlClearChatMessage
,
prevPromptConfig
,
prevPromptConfig
,
setPrevPromptConfig
,
setPrevPromptConfig
,
moreLikeThisCon
if
g
,
moreLikeThisCon
fi
g
,
setMoreLikeThisCon
if
g
,
setMoreLikeThisCon
fi
g
,
suggestedQuestionsAfterAnswerConfig
,
suggestedQuestionsAfterAnswerConfig
,
setSuggestedQuestionsAfterAnswerConfig
,
setSuggestedQuestionsAfterAnswerConfig
,
formattingChanged
,
formattingChanged
,
...
@@ -239,7 +256,7 @@ const Configuration: FC = () => {
...
@@ -239,7 +256,7 @@ const Configuration: FC = () => {
modelConfig
,
modelConfig
,
setModelConfig
,
setModelConfig
,
dataSets
,
dataSets
,
setDataSets
setDataSets
,
}
}
}
}
>
>
<>
<>
...
...
web/app/components/base/switch/index.tsx
View file @
3e380c08
'use client'
'use client'
import
React
,
{
useState
}
from
'react'
import
React
,
{
use
Effect
,
use
State
}
from
'react'
import
classNames
from
'classnames'
import
classNames
from
'classnames'
import
{
Switch
as
OriginalSwitch
}
from
'@headlessui/react'
import
{
Switch
as
OriginalSwitch
}
from
'@headlessui/react'
...
@@ -12,25 +12,29 @@ type SwitchProps = {
...
@@ -12,25 +12,29 @@ type SwitchProps = {
const
Switch
=
({
onChange
,
size
=
'lg'
,
defaultValue
=
false
,
disabled
=
false
}:
SwitchProps
)
=>
{
const
Switch
=
({
onChange
,
size
=
'lg'
,
defaultValue
=
false
,
disabled
=
false
}:
SwitchProps
)
=>
{
const
[
enabled
,
setEnabled
]
=
useState
(
defaultValue
)
const
[
enabled
,
setEnabled
]
=
useState
(
defaultValue
)
useEffect
(()
=>
{
setEnabled
(
defaultValue
)
},
[
defaultValue
])
const
wrapStyle
=
{
const
wrapStyle
=
{
lg
:
'h-6 w-11'
,
lg
:
'h-6 w-11'
,
md
:
'h-4 w-7'
md
:
'h-4 w-7'
,
}
}
const
circleStyle
=
{
const
circleStyle
=
{
lg
:
'h-5 w-5'
,
lg
:
'h-5 w-5'
,
md
:
'h-3 w-3'
md
:
'h-3 w-3'
,
}
}
const
translateLeft
=
{
const
translateLeft
=
{
lg
:
'translate-x-5'
,
lg
:
'translate-x-5'
,
md
:
'translate-x-3'
md
:
'translate-x-3'
,
}
}
return
(
return
(
<
OriginalSwitch
<
OriginalSwitch
checked=
{
enabled
}
checked=
{
enabled
}
onChange=
{
(
checked
:
boolean
)
=>
{
onChange=
{
(
checked
:
boolean
)
=>
{
if
(
disabled
)
return
;
if
(
disabled
)
return
setEnabled
(
checked
)
setEnabled
(
checked
)
onChange
(
checked
)
onChange
(
checked
)
}
}
}
}
...
...
web/app/components/share/text-generation/index.tsx
View file @
3e380c08
...
@@ -47,7 +47,7 @@ const TextGeneration: FC<IMainProps> = ({
...
@@ -47,7 +47,7 @@ const TextGeneration: FC<IMainProps> = ({
const
[
appId
,
setAppId
]
=
useState
<
string
>
(
''
)
const
[
appId
,
setAppId
]
=
useState
<
string
>
(
''
)
const
[
siteInfo
,
setSiteInfo
]
=
useState
<
SiteInfo
|
null
>
(
null
)
const
[
siteInfo
,
setSiteInfo
]
=
useState
<
SiteInfo
|
null
>
(
null
)
const
[
promptConfig
,
setPromptConfig
]
=
useState
<
PromptConfig
|
null
>
(
null
)
const
[
promptConfig
,
setPromptConfig
]
=
useState
<
PromptConfig
|
null
>
(
null
)
const
[
moreLikeThisCon
ifg
,
setMoreLikeThisConif
g
]
=
useState
<
MoreLikeThisConfig
|
null
>
(
null
)
const
[
moreLikeThisCon
fig
,
setMoreLikeThisConfi
g
]
=
useState
<
MoreLikeThisConfig
|
null
>
(
null
)
const
[
isResponsing
,
{
setTrue
:
setResponsingTrue
,
setFalse
:
setResponsingFalse
}]
=
useBoolean
(
false
)
const
[
isResponsing
,
{
setTrue
:
setResponsingTrue
,
setFalse
:
setResponsingFalse
}]
=
useBoolean
(
false
)
const
[
query
,
setQuery
]
=
useState
(
''
)
const
[
query
,
setQuery
]
=
useState
(
''
)
const
[
completionRes
,
setCompletionRes
]
=
useState
(
''
)
const
[
completionRes
,
setCompletionRes
]
=
useState
(
''
)
...
@@ -193,7 +193,7 @@ const TextGeneration: FC<IMainProps> = ({
...
@@ -193,7 +193,7 @@ const TextGeneration: FC<IMainProps> = ({
prompt_template
:
''
,
// placeholder for feture
prompt_template
:
''
,
// placeholder for feture
prompt_variables
,
prompt_variables
,
}
as
PromptConfig
)
}
as
PromptConfig
)
setMoreLikeThisCon
if
g
(
more_like_this
)
setMoreLikeThisCon
fi
g
(
more_like_this
)
})()
})()
},
[])
},
[])
...
@@ -251,7 +251,7 @@ const TextGeneration: FC<IMainProps> = ({
...
@@ -251,7 +251,7 @@ const TextGeneration: FC<IMainProps> = ({
content=
{
completionRes
}
content=
{
completionRes
}
messageId=
{
messageId
}
messageId=
{
messageId
}
isInWebApp
isInWebApp
moreLikeThis=
{
moreLikeThisCon
if
g
?.
enabled
}
moreLikeThis=
{
moreLikeThisCon
fi
g
?.
enabled
}
onFeedback=
{
handleFeedback
}
onFeedback=
{
handleFeedback
}
feedback=
{
feedback
}
feedback=
{
feedback
}
onSave=
{
handleSaveMessage
}
onSave=
{
handleSaveMessage
}
...
...
web/context/debug-configuration.ts
View file @
3e380c08
import
{
createContext
}
from
'use-context-selector'
import
{
createContext
}
from
'use-context-selector'
import
type
{
CompletionParams
,
Inputs
,
ModelConfig
,
PromptConfig
,
MoreLikeThis
Config
,
SuggestedQuestionsAfterAnswerConfig
}
from
'@/models/debug'
import
type
{
CompletionParams
,
Inputs
,
ModelConfig
,
MoreLikeThisConfig
,
Prompt
Config
,
SuggestedQuestionsAfterAnswerConfig
}
from
'@/models/debug'
import
type
{
DataSet
}
from
'@/models/datasets'
import
type
{
DataSet
}
from
'@/models/datasets'
type
IDebugConfiguration
=
{
type
IDebugConfiguration
=
{
...
@@ -15,9 +15,9 @@ type IDebugConfiguration = {
...
@@ -15,9 +15,9 @@ type IDebugConfiguration = {
setControlClearChatMessage
:
(
controlClearChatMessage
:
number
)
=>
void
setControlClearChatMessage
:
(
controlClearChatMessage
:
number
)
=>
void
prevPromptConfig
:
PromptConfig
prevPromptConfig
:
PromptConfig
setPrevPromptConfig
:
(
prevPromptConfig
:
PromptConfig
)
=>
void
setPrevPromptConfig
:
(
prevPromptConfig
:
PromptConfig
)
=>
void
moreLikeThisCon
ifg
:
MoreLikeThisConfig
,
moreLikeThisCon
fig
:
MoreLikeThisConfig
setMoreLikeThisCon
if
g
:
(
moreLikeThisConfig
:
MoreLikeThisConfig
)
=>
void
setMoreLikeThisCon
fi
g
:
(
moreLikeThisConfig
:
MoreLikeThisConfig
)
=>
void
suggestedQuestionsAfterAnswerConfig
:
SuggestedQuestionsAfterAnswerConfig
,
suggestedQuestionsAfterAnswerConfig
:
SuggestedQuestionsAfterAnswerConfig
setSuggestedQuestionsAfterAnswerConfig
:
(
suggestedQuestionsAfterAnswerConfig
:
SuggestedQuestionsAfterAnswerConfig
)
=>
void
setSuggestedQuestionsAfterAnswerConfig
:
(
suggestedQuestionsAfterAnswerConfig
:
SuggestedQuestionsAfterAnswerConfig
)
=>
void
formattingChanged
:
boolean
formattingChanged
:
boolean
setFormattingChanged
:
(
formattingChanged
:
boolean
)
=>
void
setFormattingChanged
:
(
formattingChanged
:
boolean
)
=>
void
...
@@ -51,10 +51,10 @@ const DebugConfigurationContext = createContext<IDebugConfiguration>({
...
@@ -51,10 +51,10 @@ const DebugConfigurationContext = createContext<IDebugConfiguration>({
prompt_variables
:
[],
prompt_variables
:
[],
},
},
setPrevPromptConfig
:
()
=>
{
},
setPrevPromptConfig
:
()
=>
{
},
moreLikeThisCon
if
g
:
{
moreLikeThisCon
fi
g
:
{
enabled
:
false
,
enabled
:
false
,
},
},
setMoreLikeThisCon
if
g
:
()
=>
{
},
setMoreLikeThisCon
fi
g
:
()
=>
{
},
suggestedQuestionsAfterAnswerConfig
:
{
suggestedQuestionsAfterAnswerConfig
:
{
enabled
:
false
,
enabled
:
false
,
},
},
...
...
web/models/debug.ts
View file @
3e380c08
export
type
Inputs
=
Record
<
string
,
string
|
number
|
object
>
export
type
Inputs
=
Record
<
string
,
string
|
number
|
object
>
export
type
PromptVariable
=
{
export
type
PromptVariable
=
{
key
:
string
,
key
:
string
name
:
string
,
name
:
string
type
:
string
,
// "string" | "number" | "select",
type
:
string
// "string" | "number" | "select",
default
?:
string
|
number
,
default
?:
string
|
number
required
:
boolean
,
required
:
boolean
options
?:
string
[]
options
?:
string
[]
max_length
?:
number
max_length
?:
number
}
}
export
type
CompletionParams
=
{
export
type
CompletionParams
=
{
max_tokens
:
number
,
max_tokens
:
number
temperature
:
number
,
temperature
:
number
top_p
:
number
,
top_p
:
number
presence_penalty
:
number
,
presence_penalty
:
number
frequency_penalty
:
number
,
frequency_penalty
:
number
}
}
export
type
ModelId
=
"gpt-3.5-turbo"
|
"text-davinci-003"
export
type
ModelId
=
'gpt-3.5-turbo'
|
'text-davinci-003'
export
type
PromptConfig
=
{
export
type
PromptConfig
=
{
prompt_template
:
string
,
prompt_template
:
string
prompt_variables
:
PromptVariable
[]
,
prompt_variables
:
PromptVariable
[]
}
}
export
type
MoreLikeThisConfig
=
{
export
type
MoreLikeThisConfig
=
{
...
@@ -33,83 +33,88 @@ export type SuggestedQuestionsAfterAnswerConfig = MoreLikeThisConfig
...
@@ -33,83 +33,88 @@ export type SuggestedQuestionsAfterAnswerConfig = MoreLikeThisConfig
// frontend use. Not the same as backend
// frontend use. Not the same as backend
export
type
ModelConfig
=
{
export
type
ModelConfig
=
{
provider
:
string
,
// LLM Provider: for example "OPENAI"
provider
:
string
// LLM Provider: for example "OPENAI"
model_id
:
string
,
model_id
:
string
configs
:
PromptConfig
configs
:
PromptConfig
opening_statement
:
string
|
null
more_like_this
:
{
enabled
:
boolean
}
|
null
suggested_questions_after_answer
:
{
enabled
:
boolean
}
|
null
dataSets
:
any
[]
}
}
export
type
DebugRequestBody
=
{
export
type
DebugRequestBody
=
{
inputs
:
Inputs
,
inputs
:
Inputs
query
:
string
,
query
:
string
completion_params
:
CompletionParams
,
completion_params
:
CompletionParams
model_config
:
ModelConfig
model_config
:
ModelConfig
}
}
export
type
DebugResponse
=
{
export
type
DebugResponse
=
{
id
:
string
,
id
:
string
answer
:
string
,
answer
:
string
created_at
:
string
,
created_at
:
string
}
}
export
type
DebugResponseStream
=
{
export
type
DebugResponseStream
=
{
id
:
string
,
id
:
string
data
:
string
,
data
:
string
created_at
:
string
,
created_at
:
string
}
}
export
type
FeedBackRequestBody
=
{
export
type
FeedBackRequestBody
=
{
message_id
:
string
,
message_id
:
string
rating
:
'like'
|
'dislike'
,
rating
:
'like'
|
'dislike'
content
?:
string
,
content
?:
string
from_source
:
'api'
|
'log'
from_source
:
'api'
|
'log'
}
}
export
type
FeedBackResponse
=
{
export
type
FeedBackResponse
=
{
message_id
:
string
,
message_id
:
string
rating
:
'like'
|
'dislike'
rating
:
'like'
|
'dislike'
}
}
// Log session list
// Log session list
export
type
LogSessionListQuery
=
{
export
type
LogSessionListQuery
=
{
keyword
?:
string
,
keyword
?:
string
start
?:
string
,
// format datetime(YYYY-mm-dd HH:ii)
start
?:
string
// format datetime(YYYY-mm-dd HH:ii)
end
?:
string
,
// format datetime(YYYY-mm-dd HH:ii)
end
?:
string
// format datetime(YYYY-mm-dd HH:ii)
page
:
number
,
page
:
number
limit
:
number
,
// default 20. 1-100
limit
:
number
// default 20. 1-100
}
}
export
type
LogSessionListResponse
=
{
export
type
LogSessionListResponse
=
{
data
:
{
data
:
{
id
:
string
,
id
:
string
conversation_id
:
string
,
conversation_id
:
string
query
:
string
,
// user's query question
query
:
string
// user's query question
message
:
string
,
// prompt send to LLM
message
:
string
// prompt send to LLM
answer
:
string
,
answer
:
string
creat_at
:
string
,
creat_at
:
string
}[]
,
}[]
total
:
number
,
total
:
number
page
:
number
,
page
:
number
}
}
// log session detail and debug
// log session detail and debug
export
type
LogSessionDetailResponse
=
{
export
type
LogSessionDetailResponse
=
{
id
:
string
,
id
:
string
cnversation_id
:
string
,
cnversation_id
:
string
model_provider
:
string
,
model_provider
:
string
query
:
string
,
query
:
string
inputs
:
Record
<
string
,
string
|
number
|
object
>
[]
,
inputs
:
Record
<
string
,
string
|
number
|
object
>
[]
message
:
string
,
message
:
string
message_tokens
:
number
,
// number of tokens in message
message_tokens
:
number
// number of tokens in message
answer
:
string
,
answer
:
string
answer_tokens
:
number
,
// number of tokens in answer
answer_tokens
:
number
// number of tokens in answer
provider_response_latency
:
number
,
// used time in ms
provider_response_latency
:
number
// used time in ms
from_source
:
'api'
|
'log'
,
from_source
:
'api'
|
'log'
}
}
export
type
SavedMessage
=
{
export
type
SavedMessage
=
{
id
:
string
,
id
:
string
answer
:
string
answer
:
string
}
}
\ No newline at end of file
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