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
ab6a01b4
Commit
ab6a01b4
authored
Feb 18, 2024
by
Joel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: handle llm model type
parent
dce01cf0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
15 deletions
+45
-15
field.tsx
web/app/components/workflow/nodes/_base/components/field.tsx
+2
-2
mock.ts
web/app/components/workflow/nodes/llm/mock.ts
+1
-1
panel.tsx
web/app/components/workflow/nodes/llm/panel.tsx
+22
-5
use-input.ts
web/app/components/workflow/nodes/llm/use-input.ts
+20
-7
No files found.
web/app/components/workflow/nodes/_base/components/field.tsx
View file @
ab6a01b4
...
...
@@ -7,7 +7,7 @@ import TooltipPlus from '@/app/components/base/tooltip-plus'
type
Props
=
{
title
:
string
tooltip
?:
string
children
:
JSX
.
Element
|
string
children
?:
JSX
.
Element
|
string
|
null
operations
?:
JSX
.
Element
inline
?:
boolean
}
...
...
@@ -33,7 +33,7 @@ const Filed: FC<Props> = ({
</
div
>
{
operations
&&
<
div
>
{
operations
}
</
div
>
}
</
div
>
<
div
>
{
children
}
</
div
>
{
children
&&
<
div
className=
{
cn
(
!
inline
&&
'mt-1'
)
}
>
{
children
}
</
div
>
}
</
div
>
)
}
...
...
web/app/components/workflow/nodes/llm/mock.ts
View file @
ab6a01b4
...
...
@@ -9,7 +9,7 @@ export const mockLLMNodeData: LLMNodeData = {
model
:
{
provider
:
'openai'
,
name
:
'gpt-4'
,
mode
:
'c
ompletion
'
,
mode
:
'c
hat
'
,
completion_params
:
{
temperature
:
0.7
,
},
...
...
web/app/components/workflow/nodes/llm/panel.tsx
View file @
ab6a01b4
...
...
@@ -7,15 +7,21 @@ import Field from '@/app/components/workflow/nodes/_base/components/field'
import
AddButton
from
'@/app/components/base/button/add-button'
import
Split
from
'@/app/components/workflow/nodes/_base/components/split'
import
ModelSelector
from
'@/app/components/header/account-setting/model-provider-page/model-selector'
import
{
useTextGenerationCurrentProviderAndModelAndModelList
}
from
'@/app/components/header/account-setting/model-provider-page/hooks
'
import
Switch
from
'@/app/components/base/switch
'
const
i18nPrefix
=
'workflow.nodes.llm'
const
Panel
:
FC
=
()
=>
{
const
{
t
}
=
useTranslation
()
const
{
inputs
,
handleModelChanged
}
=
useInput
(
mockLLMNodeData
)
const
{
textGenerationModelList
,
}
=
useTextGenerationCurrentProviderAndModelAndModelList
()
inputs
,
handleModelChanged
,
toggleContextEnabled
,
}
=
useInput
(
mockLLMNodeData
)
const
modelMode
=
inputs
.
model
.
mode
const
isChatMode
=
modelMode
===
'chat'
const
handleAddVariable
=
()
=>
{
console
.
log
(
'add variable'
)
}
...
...
@@ -49,11 +55,22 @@ const Panel: FC = () => {
<
Field
title=
{
t
(
`${i18nPrefix}.context`
)
}
operations=
{
<
Switch
defaultValue=
{
inputs
.
context
.
enabled
}
onChange=
{
toggleContextEnabled
}
size=
'md'
/>
}
>
Context
{
inputs
.
context
.
enabled
?
(
<
div
>
Context
</
div
>
)
:
null
}
</
Field
>
<
Field
title=
{
t
(
`${i18nPrefix}.
contex
t`
)
}
title=
{
t
(
`${i18nPrefix}.
promp
t`
)
}
>
Prompt
</
Field
>
...
...
web/app/components/workflow/nodes/llm/use-input.ts
View file @
ab6a01b4
import
{
useCallback
,
useState
}
from
'react'
import
produce
from
'immer'
import
type
{
LLMNodeData
}
from
'../../types'
import
{
useTextGenerationCurrentProviderAndModelAndModelList
}
from
'@/app/components/header/account-setting/model-provider-page/hooks'
const
useInput
=
(
initInputs
:
LLMNodeData
)
=>
{
const
{
textGenerationModelList
,
}
=
useTextGenerationCurrentProviderAndModelAndModelList
()
const
[
inputs
,
setInputs
]
=
useState
<
LLMNodeData
>
(
initInputs
)
const
handleModelChanged
=
useCallback
((
model
:
{
provider
:
string
;
model
:
string
})
=>
{
const
targetProvider
=
textGenerationModelList
.
find
(
modelItem
=>
modelItem
.
provider
===
model
.
provider
)
const
targetModelItem
=
targetProvider
?.
models
.
find
(
modelItem
=>
modelItem
.
model
===
model
.
model
)
const
newInputs
=
produce
(
inputs
,
(
draft
)
=>
{
draft
.
model
.
provider
=
model
.
provider
draft
.
model
.
name
=
model
.
model
draft
.
model
.
mode
=
targetModelItem
?.
model_properties
.
mode
as
string
})
setInputs
(
newInputs
)
},
[
inputs
.
model
])
},
[
inputs
.
model
,
textGenerationModelList
])
const
toggleContextEnabled
=
useCallback
(()
=>
{
const
newInputs
=
produce
(
inputs
,
(
draft
)
=>
{
draft
.
context
.
enabled
=
!
draft
.
context
.
enabled
})
setInputs
(
newInputs
)
},
[
inputs
.
context
.
enabled
])
return
{
textGenerationModelList
,
inputs
,
setInputs
:
(
key
:
string
,
payload
:
any
)
=>
{
setInputs
({
...
inputs
,
[
key
]:
payload
,
}
as
LLMNodeData
)
},
handleModelChanged
,
toggleContextEnabled
,
}
}
...
...
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