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
58ef52b4
Unverified
Commit
58ef52b4
authored
Jan 31, 2024
by
Yeuoly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: tool model authorization
parent
8672f98a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
4 deletions
+34
-4
model_tool_provider.py
api/core/tools/provider/model_tool_provider.py
+5
-1
header.tsx
web/app/components/tools/tool-list/header.tsx
+1
-1
index.tsx
web/app/components/tools/tool-list/index.tsx
+28
-2
No files found.
api/core/tools/provider/model_tool_provider.py
View file @
58ef52b4
...
...
@@ -15,6 +15,7 @@ from core.model_runtime.entities.model_entities import ModelType, ModelFeature
from
core.entities.model_entities
import
ModelStatus
from
core.provider_manager
import
ProviderManager
,
ProviderConfiguration
,
ProviderModelBundle
from
core.model_manager
import
ModelInstance
from
core.errors.error
import
ProviderTokenNotInitError
class
ModelToolProviderConfiguration
(
BaseModel
):
"""
...
...
@@ -142,7 +143,10 @@ class ModelToolProviderController(ToolProviderController):
model_type_instance
=
model_type_instance
)
model_instance
=
ModelInstance
(
provider_model_bundle
,
model
.
model
)
try
:
model_instance
=
ModelInstance
(
provider_model_bundle
,
model
.
model
)
except
ProviderTokenNotInitError
:
model_instance
=
None
tools
.
append
(
ModelTool
(
identity
=
ToolIdentity
(
...
...
web/app/components/tools/tool-list/header.tsx
View file @
58ef52b4
...
...
@@ -55,7 +55,7 @@ const Header: FC<Props> = ({
<
div
className=
{
cn
(
'cursor-pointer'
,
'ml-1 shrink-0 flex items-center h-8 border border-gray-200 rounded-lg px-3 space-x-2 shadow-xs'
)
}
onClick=
{
()
=>
{
if
(
collection
.
type
===
CollectionType
.
builtIn
)
if
(
collection
.
type
===
CollectionType
.
builtIn
||
collection
.
type
===
CollectionType
.
model
)
onShowAuth
()
}
}
>
...
...
web/app/components/tools/tool-list/index.tsx
View file @
58ef52b4
...
...
@@ -8,6 +8,7 @@ import type { Collection, CustomCollectionBackend, Tool } from '../types'
import
Loading
from
'../../base/loading'
import
{
ArrowNarrowRight
}
from
'../../base/icons/src/vender/line/arrows'
import
Toast
from
'../../base/toast'
import
{
ConfigurateMethodEnum
}
from
'../../header/account-setting/model-provider-page/declarations'
import
Header
from
'./header'
import
Item
from
'./item'
import
AppIcon
from
'@/app/components/base/app-icon'
...
...
@@ -16,6 +17,8 @@ import { fetchCustomCollection, removeBuiltInToolCredential, removeCustomCollect
import
EditCustomToolModal
from
'@/app/components/tools/edit-custom-collection-modal'
import
type
{
AgentTool
}
from
'@/types/app'
import
{
MAX_TOOLS_NUM
}
from
'@/config'
import
{
useModalContext
}
from
'@/context/modal-context'
import
{
useProviderContext
}
from
'@/context/provider-context'
type
Props
=
{
collection
:
Collection
|
null
...
...
@@ -45,7 +48,30 @@ const ToolList: FC<Props> = ({
const
isModel
=
collection
?.
type
===
CollectionType
.
model
const
needAuth
=
collection
?.
allow_delete
||
collection
?.
type
===
CollectionType
.
model
const
{
setShowModelModal
}
=
useModalContext
()
const
[
showSettingAuth
,
setShowSettingAuth
]
=
useState
(
false
)
const
{
modelProviders
:
providers
}
=
useProviderContext
()
const
showSettingAuthModal
=
()
=>
{
if
(
isModel
)
{
const
provider
=
providers
.
find
(
item
=>
item
.
provider
===
collection
?.
id
)
if
(
provider
)
{
setShowModelModal
({
payload
:
{
currentProvider
:
provider
,
currentConfigurateMethod
:
ConfigurateMethodEnum
.
predefinedModel
,
currentCustomConfigrationModelFixedFields
:
undefined
,
},
onSaveCallback
:
()
=>
{
onRefreshData
()
},
})
}
}
else
{
setShowSettingAuth
(
true
)
}
}
const
[
customCollection
,
setCustomCollection
]
=
useState
<
CustomCollectionBackend
|
null
>
(
null
)
useEffect
(()
=>
{
...
...
@@ -114,7 +140,7 @@ const ToolList: FC<Props> = ({
icon=
{
icon
}
collection=
{
collection
}
loc=
{
loc
}
onShowAuth=
{
()
=>
s
etShowSettingAuth
(
true
)
}
onShowAuth=
{
()
=>
s
howSettingAuthModal
(
)
}
onShowEditCustomCollection=
{
()
=>
setIsShowEditCustomCollectionModal
(
true
)
}
/>
<
div
className=
{
cn
(
isInToolsPage
?
'px-6 pt-4'
:
'px-4 pt-3'
)
}
>
...
...
@@ -127,7 +153,7 @@ const ToolList: FC<Props> = ({
<
div
>
·
</
div
>
<
div
className=
'flex items-center text-[#155EEF] cursor-pointer'
onClick=
{
()
=>
s
etShowSettingAuth
(
true
)
}
onClick=
{
()
=>
s
howSettingAuthModal
(
)
}
>
<
div
>
{
t
(
'tools.auth.setup'
)
}
</
div
>
<
ArrowNarrowRight
className=
'ml-0.5 w-3 h-3'
/>
...
...
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