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
80504660
Unverified
Commit
80504660
authored
Jan 26, 2024
by
Yeuoly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: frontend support add model tool
parent
61fec52f
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
94 additions
and
16 deletions
+94
-16
tool_providers.py
api/controllers/console/workspace/tool_providers.py
+20
-0
model_tool_provider.py
api/core/tools/provider/model_tool_provider.py
+2
-2
tool_manager.py
api/core/tools/tool_manager.py
+20
-1
tools_manage_service.py
api/services/tools_manage_service.py
+24
-0
index.tsx
...ents/app/configuration/config/agent/agent-tools/index.tsx
+1
-1
index.tsx
web/app/components/tools/index.tsx
+7
-3
header.tsx
web/app/components/tools/tool-list/header.tsx
+6
-3
index.tsx
web/app/components/tools/tool-list/index.tsx
+5
-3
index.tsx
web/app/components/tools/tool-nav-list/index.tsx
+3
-3
types.ts
web/app/components/tools/types.ts
+1
-0
tools.ts
web/service/tools.ts
+5
-0
No files found.
api/controllers/console/workspace/tool_providers.py
View file @
80504660
...
...
@@ -89,6 +89,25 @@ class ToolModelProviderIconApi(Resource):
def
get
(
self
,
provider
):
icon_bytes
,
minetype
=
ToolManageService
.
get_model_tool_provider_icon
(
provider
)
return
send_file
(
io
.
BytesIO
(
icon_bytes
),
mimetype
=
minetype
)
class
ToolModelProviderListToolsApi
(
Resource
):
@
setup_required
@
login_required
@
account_initialization_required
def
get
(
self
):
user_id
=
current_user
.
id
tenant_id
=
current_user
.
current_tenant_id
parser
=
reqparse
.
RequestParser
()
parser
.
add_argument
(
'provider'
,
type
=
str
,
required
=
True
,
nullable
=
False
,
location
=
'args'
)
args
=
parser
.
parse_args
()
return
ToolManageService
.
list_model_tool_provider_tools
(
user_id
,
tenant_id
,
args
[
'provider'
],
)
class
ToolApiProviderAddApi
(
Resource
):
@
setup_required
...
...
@@ -289,6 +308,7 @@ api.add_resource(ToolBuiltinProviderUpdateApi, '/workspaces/current/tool-provide
api
.
add_resource
(
ToolBuiltinProviderCredentialsSchemaApi
,
'/workspaces/current/tool-provider/builtin/<provider>/credentials_schema'
)
api
.
add_resource
(
ToolBuiltinProviderIconApi
,
'/workspaces/current/tool-provider/builtin/<provider>/icon'
)
api
.
add_resource
(
ToolModelProviderIconApi
,
'/workspaces/current/tool-provider/model/<provider>/icon'
)
api
.
add_resource
(
ToolModelProviderListToolsApi
,
'/workspaces/current/tool-provider/model/tools'
)
api
.
add_resource
(
ToolApiProviderAddApi
,
'/workspaces/current/tool-provider/api/add'
)
api
.
add_resource
(
ToolApiProviderGetRemoteSchemaApi
,
'/workspaces/current/tool-provider/api/remote'
)
api
.
add_resource
(
ToolApiProviderListToolsApi
,
'/workspaces/current/tool-provider/api/tools'
)
...
...
api/core/tools/provider/model_tool_provider.py
View file @
80504660
...
...
@@ -129,13 +129,13 @@ class ModelToolProviderController(ToolProviderController):
"""
return
{}
def
get_tools
(
self
,
user_id
:
str
,
t
ane
nt_id
:
str
)
->
List
[
ModelTool
]:
def
get_tools
(
self
,
user_id
:
str
,
t
ena
nt_id
:
str
)
->
List
[
ModelTool
]:
"""
returns a list of tools that the provider can provide
:return: list of tools
"""
return
self
.
_get_model_tools
(
tenant_id
=
t
ane
nt_id
)
return
self
.
_get_model_tools
(
tenant_id
=
t
ena
nt_id
)
def
get_tool
(
self
,
tool_name
:
str
)
->
ModelTool
:
"""
...
...
api/core/tools/tool_manager.py
View file @
80504660
...
...
@@ -292,6 +292,24 @@ class ToolManager:
return
model_providers
@
staticmethod
def
get_model_provider
(
tenant_id
:
str
,
provider_name
:
str
)
->
ModelToolProviderController
:
"""
get the model provider
:param provider_name: the name of the provider
:return: the provider
"""
# get configurations
provider_manager
=
ProviderManager
()
configurations
=
provider_manager
.
get_configurations
(
tenant_id
)
configuration
=
configurations
.
get
(
provider_name
)
if
configuration
is
None
:
raise
ToolProviderNotFoundError
(
f
'model provider {provider_name} not found'
)
return
ModelToolProviderController
.
from_db
(
configuration
)
@
staticmethod
def
get_tool_label
(
tool_name
:
str
)
->
Union
[
I18nObject
,
None
]:
"""
...
...
@@ -512,4 +530,5 @@ class ToolManager:
'description'
:
provider
.
description
,
'credentials'
:
masked_credentials
,
'privacy_policy'
:
provider
.
privacy_policy
}))
\ No newline at end of file
}))
\ No newline at end of file
api/services/tools_manage_service.py
View file @
80504660
...
...
@@ -309,6 +309,30 @@ class ToolManageService:
)
for
tool_bundle
in
provider
.
tools
])
)
@
staticmethod
def
list_model_tool_provider_tools
(
user_id
:
str
,
tenant_id
:
str
,
provider
:
str
):
"""
list model tool provider tools
"""
provider_controller
=
ToolManager
.
get_model_provider
(
tenant_id
=
tenant_id
,
provider_name
=
provider
)
tools
=
provider_controller
.
get_tools
(
user_id
=
user_id
,
tenant_id
=
tenant_id
)
result
=
[
UserTool
(
author
=
tool
.
identity
.
author
,
name
=
tool
.
identity
.
name
,
label
=
tool
.
identity
.
label
,
description
=
tool
.
description
.
human
,
parameters
=
tool
.
parameters
or
[]
)
for
tool
in
tools
]
return
json
.
loads
(
serialize_base_model_array
(
result
)
)
@
staticmethod
def
update_builtin_tool_provider
(
...
...
web/app/components/app/configuration/config/agent/agent-tools/index.tsx
View file @
80504660
...
...
@@ -32,7 +32,7 @@ const AgentTools: FC = () => {
const
[
selectedProviderId
,
setSelectedProviderId
]
=
useState
<
string
|
undefined
>
(
undefined
)
const
[
isShowSettingTool
,
setIsShowSettingTool
]
=
useState
(
false
)
const
tools
=
(
modelConfig
?.
agentConfig
?.
tools
as
AgentTool
[]
||
[]).
map
((
item
)
=>
{
const
collection
=
collectionList
.
find
(
collection
=>
collection
.
id
===
item
.
provider_id
)
const
collection
=
collectionList
.
find
(
collection
=>
collection
.
id
===
item
.
provider_id
&&
collection
.
type
===
item
.
provider_type
)
const
icon
=
collection
?.
icon
return
{
...
item
,
...
...
web/app/components/tools/index.tsx
View file @
80504660
...
...
@@ -16,7 +16,7 @@ import EditCustomToolModal from './edit-custom-collection-modal'
import
NoCustomTool
from
'./info/no-custom-tool'
import
NoSearchRes
from
'./info/no-search-res'
import
TabSlider
from
'@/app/components/base/tab-slider'
import
{
createCustomCollection
,
fetchCollectionList
as
doFetchCollectionList
,
fetchBuiltInToolList
,
fetchCustomToolList
}
from
'@/service/tools'
import
{
createCustomCollection
,
fetchCollectionList
as
doFetchCollectionList
,
fetchBuiltInToolList
,
fetchCustomToolList
,
fetchModelToolList
}
from
'@/service/tools'
import
type
{
AgentTool
}
from
'@/types/app'
type
Props
=
{
...
...
@@ -105,10 +105,14 @@ const Tools: FC<Props> = ({
const
list
=
await
fetchBuiltInToolList
(
currCollection
.
name
)
as
Tool
[]
setCurrentTools
(
list
)
}
else
{
else
if
(
currCollection
.
type
===
CollectionType
.
custom
)
{
const
list
=
await
fetchCustomToolList
(
currCollection
.
name
)
as
Tool
[]
setCurrentTools
(
list
)
}
else
if
(
currCollection
.
type
===
CollectionType
.
model
)
{
const
list
=
await
fetchModelToolList
(
currCollection
.
name
)
as
Tool
[]
setCurrentTools
(
list
)
}
}
catch
(
e
)
{
}
setIsDetailLoading
(
false
)
...
...
@@ -180,7 +184,7 @@ const Tools: FC<Props> = ({
(
showCollectionList
.
length
>
0
||
!
query
)
?
<
ToolNavList
className=
'mt-2 grow height-0 overflow-y-auto'
current
Name=
{
currCollection
?.
name
||
''
}
current
Index=
{
currCollectionIndex
||
0
}
list=
{
showCollectionList
}
onChosen=
{
setCurrCollectionIndex
}
/>
...
...
web/app/components/tools/tool-list/header.tsx
View file @
80504660
...
...
@@ -30,7 +30,7 @@ const Header: FC<Props> = ({
const
{
t
}
=
useTranslation
()
const
isInToolsPage
=
loc
===
LOC
.
tools
const
isInDebugPage
=
!
isInToolsPage
const
needAuth
=
collection
?.
allow_delete
const
needAuth
=
collection
?.
allow_delete
||
collection
?.
type
===
CollectionType
.
model
// const isBuiltIn = collection.type === CollectionType.builtIn
const
isAuthed
=
collection
.
is_team_authorization
...
...
@@ -51,10 +51,13 @@ const Header: FC<Props> = ({
)
}
</
div
>
</
div
>
{
collection
.
type
===
CollectionType
.
builtIn
&&
needAuth
&&
(
{
(
collection
.
type
===
CollectionType
.
builtIn
||
collection
.
type
===
CollectionType
.
model
)
&&
needAuth
&&
(
<
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=
{
()
=>
onShowAuth
()
}
onClick=
{
()
=>
{
if
(
collection
.
type
===
CollectionType
.
builtIn
)
onShowAuth
()
}
}
>
<
div
className=
{
cn
(
isAuthed
?
'border-[#12B76A] bg-[#32D583]'
:
'border-gray-400 bg-gray-300'
,
'rounded h-2 w-2 border'
)
}
></
div
>
<
div
className=
'leading-5 text-sm font-medium text-gray-700'
>
{
t
(
`tools.auth.${isAuthed ? 'authorized' : 'unauthorized'}`
)
}
</
div
>
...
...
web/app/components/tools/tool-list/index.tsx
View file @
80504660
...
...
@@ -42,7 +42,8 @@ const ToolList: FC<Props> = ({
const
{
t
}
=
useTranslation
()
const
isInToolsPage
=
loc
===
LOC
.
tools
const
isBuiltIn
=
collection
?.
type
===
CollectionType
.
builtIn
const
needAuth
=
collection
?.
allow_delete
const
isModel
=
collection
?.
type
===
CollectionType
.
model
const
needAuth
=
collection
?.
allow_delete
||
collection
?.
type
===
CollectionType
.
model
const
[
showSettingAuth
,
setShowSettingAuth
]
=
useState
(
false
)
...
...
@@ -52,6 +53,7 @@ const ToolList: FC<Props> = ({
return
(
async
()
=>
{
if
(
collection
.
type
===
CollectionType
.
custom
)
{
console
.
log
(
collection
)
const
res
=
await
fetchCustomCollection
(
collection
.
name
)
as
any
setCustomCollection
({
...
res
,
...
...
@@ -120,7 +122,7 @@ const ToolList: FC<Props> = ({
<
div
className=
''
>
{
t
(
'tools.includeToolNum'
,
{
num
:
list
.
length
,
})
}
</
div
>
{
needAuth
&&
isBuiltIn
&&
!
collection
.
is_team_authorization
&&
(
{
needAuth
&&
(
isBuiltIn
||
isModel
)
&&
!
collection
.
is_team_authorization
&&
(
<>
<
div
>
·
</
div
>
<
div
...
...
@@ -145,7 +147,7 @@ const ToolList: FC<Props> = ({
collection=
{
collection
}
isInToolsPage=
{
isInToolsPage
}
isToolNumMax=
{
(
addedTools
?.
length
||
0
)
>=
MAX_TOOLS_NUM
}
added=
{
!!
addedTools
?.
find
(
v
=>
v
.
provider_id
===
collection
.
id
&&
v
.
tool_name
===
item
.
name
)
}
added=
{
!!
addedTools
?.
find
(
v
=>
v
.
provider_id
===
collection
.
id
&&
v
.
provider_type
===
collection
.
type
&&
v
.
tool_name
===
item
.
name
)
}
onAdd=
{
!
isInToolsPage
?
tool
=>
onAddTool
?.(
collection
as
Collection
,
tool
)
:
undefined
}
/>
))
}
...
...
web/app/components/tools/tool-nav-list/index.tsx
View file @
80504660
...
...
@@ -6,21 +6,21 @@ import Item from './item'
import
type
{
Collection
}
from
'@/app/components/tools/types'
type
Props
=
{
className
?:
string
current
Name
:
string
current
Index
:
number
list
:
Collection
[]
onChosen
:
(
index
:
number
)
=>
void
}
const
ToolNavList
:
FC
<
Props
>
=
({
className
,
current
Name
,
current
Index
,
list
,
onChosen
,
})
=>
{
return
(
<
div
className=
{
cn
(
className
)
}
>
{
list
.
map
((
item
,
index
)
=>
(
<
Item
isCurrent=
{
i
tem
.
name
===
currentName
}
key=
{
item
.
name
}
payload=
{
item
}
onClick=
{
()
=>
onChosen
(
index
)
}
></
Item
>
<
Item
isCurrent=
{
i
ndex
===
currentIndex
}
key=
{
item
.
name
}
payload=
{
item
}
onClick=
{
()
=>
onChosen
(
index
)
}
></
Item
>
))
}
</
div
>
)
...
...
web/app/components/tools/types.ts
View file @
80504660
...
...
@@ -19,6 +19,7 @@ export enum CollectionType {
all
=
'all'
,
builtIn
=
'builtin'
,
custom
=
'api'
,
model
=
'model'
,
}
export
type
Emoji
=
{
...
...
web/service/tools.ts
View file @
80504660
...
...
@@ -12,6 +12,11 @@ export const fetchBuiltInToolList = (collectionName: string) => {
export
const
fetchCustomToolList
=
(
collectionName
:
string
)
=>
{
return
get
(
`/workspaces/current/tool-provider/api/tools?provider=
${
collectionName
}
`
)
}
export
const
fetchModelToolList
=
(
collectionName
:
string
)
=>
{
return
get
(
`/workspaces/current/tool-provider/model/tools?provider=
${
collectionName
}
`
)
}
export
const
fetchBuiltInToolCredentialSchema
=
(
collectionName
:
string
)
=>
{
return
get
(
`/workspaces/current/tool-provider/builtin/
${
collectionName
}
/credentials_schema`
)
}
...
...
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