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
6fb03384
Unverified
Commit
6fb03384
authored
Jan 26, 2024
by
Yeuoly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add model provider alias
parent
5fde711b
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
74 additions
and
5 deletions
+74
-5
_model_providers.yaml
api/core/tools/provider/_model_providers.yaml
+28
-0
_position.yaml
api/core/tools/provider/_position.yaml
+1
-0
model_tool_provider.py
api/core/tools/provider/model_tool_provider.py
+43
-3
index.tsx
web/app/components/tools/index.tsx
+2
-2
No files found.
api/core/tools/provider/_model_providers.yaml
0 → 100644
View file @
6fb03384
providers
:
-
provider
:
google
alias
:
en_US
:
GeminiVision
zh_Hans
:
Gemini 图像理解
models
:
-
name
:
gemini-pro-vision
alias
:
en_US
:
Gemini Pro Vision
zh_Hans
:
Gemini Pro 图像理解
-
provider
:
zhipuai
alias
:
en_US
:
ZhipuaiModel
zh_Hans
:
智谱AI模型能力
models
:
-
name
:
glm-4v
alias
:
en_US
:
GLM-4V
zh_Hans
:
GLM-4V 图像理解
-
provider
:
openai
alias
:
en_US
:
OpenAIModel
zh_Hans
:
OpenAI模型能力
models
:
-
name
:
gpt-4-vision-preview
alias
:
en_US
:
GPT-4 Vision Preview
zh_Hans
:
GPT-4 图像理解
api/core/tools/provider/_position.yaml
View file @
6fb03384
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
-
webscraper
-
webscraper
-
wolframalpha
-
wolframalpha
-
model_provider.openai
-
model_provider.openai
-
model_provider.google
-
chart
-
chart
-
time
-
time
-
yahoo
-
yahoo
...
...
api/core/tools/provider/model_tool_provider.py
View file @
6fb03384
from
abc
import
abstractmethod
from
typing
import
List
,
Dict
,
Any
from
typing
import
List
,
Dict
,
Any
from
pydantic
import
BaseModel
from
os
import
path
from
yaml
import
load
,
FullLoader
from
core.tools.entities.tool_entities
import
ToolProviderType
,
\
from
core.tools.entities.tool_entities
import
ToolProviderType
,
\
ToolParamter
,
ToolProviderCredentials
,
ToolDescription
,
ToolProviderIdentity
ToolParamter
,
ToolProviderCredentials
,
ToolDescription
,
ToolProviderIdentity
...
@@ -13,6 +15,25 @@ from core.model_runtime.entities.model_entities import ModelType, ModelFeature
...
@@ -13,6 +15,25 @@ from core.model_runtime.entities.model_entities import ModelType, ModelFeature
from
core.entities.model_entities
import
ModelStatus
from
core.entities.model_entities
import
ModelStatus
from
core.provider_manager
import
ProviderManager
,
ProviderConfiguration
from
core.provider_manager
import
ProviderManager
,
ProviderConfiguration
class
ModelToolProviderConifguration
(
BaseModel
):
"""
the configuration of the model tool provider
"""
class
Provider
(
BaseModel
):
class
Model
(
BaseModel
):
name
:
str
alias
:
I18nObject
=
None
provider
:
str
alias
:
I18nObject
=
None
models
:
List
[
Model
]
=
None
providers
:
List
[
Provider
]
=
None
_model_tool_provider_config
:
ModelToolProviderConifguration
=
None
with
open
(
path
.
join
(
path
.
dirname
(
__file__
),
'_model_providers.yaml'
),
'r'
)
as
f
:
_model_tool_provider_config
=
ModelToolProviderConifguration
(
**
load
(
f
,
Loader
=
FullLoader
))
class
ModelToolProviderController
(
ToolProviderController
):
class
ModelToolProviderController
(
ToolProviderController
):
configuration
:
ProviderConfiguration
=
None
configuration
:
ProviderConfiguration
=
None
is_active
:
bool
=
False
is_active
:
bool
=
False
...
@@ -43,14 +64,21 @@ class ModelToolProviderController(ToolProviderController):
...
@@ -43,14 +64,21 @@ class ModelToolProviderController(ToolProviderController):
is_active
=
False
is_active
=
False
break
break
# override the configuration
for
provider
in
_model_tool_provider_config
.
providers
:
if
provider
.
provider
==
configuration
.
provider
.
provider
:
configuration
.
provider
.
label
.
en_US
=
provider
.
alias
.
en_US
configuration
.
provider
.
label
.
zh_Hans
=
provider
.
alias
.
zh_Hans
break
return
ModelToolProviderController
(
return
ModelToolProviderController
(
is_active
=
is_active
,
is_active
=
is_active
,
identity
=
ToolProviderIdentity
(
identity
=
ToolProviderIdentity
(
author
=
'Dify'
,
author
=
'Dify'
,
name
=
configuration
.
provider
.
provider
,
name
=
configuration
.
provider
.
provider
,
description
=
I18nObject
(
description
=
I18nObject
(
zh_Hans
=
f
'{configuration.provider.label.zh_Hans}
多模态模型工具
'
,
zh_Hans
=
f
'{configuration.provider.label.zh_Hans}
模型能力提供商
'
,
en_US
=
f
'{configuration.provider.label.en_US} m
ultimodal model tool
'
en_US
=
f
'{configuration.provider.label.en_US} m
odel capability provider
'
),
),
label
=
I18nObject
(
label
=
I18nObject
(
zh_Hans
=
configuration
.
provider
.
label
.
zh_Hans
,
zh_Hans
=
configuration
.
provider
.
label
.
zh_Hans
,
...
@@ -91,8 +119,20 @@ class ModelToolProviderController(ToolProviderController):
...
@@ -91,8 +119,20 @@ class ModelToolProviderController(ToolProviderController):
return
tools
return
tools
configuration
=
self
.
configuration
configuration
=
self
.
configuration
provider_configuration
=
next
(
filter
(
lambda
x
:
x
.
provider
==
self
.
configuration
.
provider
.
provider
,
_model_tool_provider_config
.
providers
),
None
)
for
model
in
configuration
.
get_provider_models
():
for
model
in
configuration
.
get_provider_models
():
if
model
.
model_type
==
ModelType
.
LLM
and
ModelFeature
.
VISION
in
(
model
.
features
or
[]):
if
model
.
model_type
==
ModelType
.
LLM
and
ModelFeature
.
VISION
in
(
model
.
features
or
[]):
# override the configuration
if
provider_configuration
is
not
None
:
for
model_config
in
provider_configuration
.
models
or
[]:
if
model_config
.
name
==
model
.
model
:
model
.
label
.
en_US
=
model_config
.
alias
.
en_US
model
.
label
.
zh_Hans
=
model_config
.
alias
.
zh_Hans
break
tools
.
append
(
ModelTool
(
tools
.
append
(
ModelTool
(
identity
=
ToolIdentity
(
identity
=
ToolIdentity
(
author
=
'Dify'
,
author
=
'Dify'
,
...
...
web/app/components/tools/index.tsx
View file @
6fb03384
...
@@ -73,8 +73,8 @@ const Tools: FC<Props> = ({
...
@@ -73,8 +73,8 @@ const Tools: FC<Props> = ({
let
typeFilteredList
:
Collection
[]
=
[]
let
typeFilteredList
:
Collection
[]
=
[]
if
(
collectionType
===
CollectionType
.
all
)
if
(
collectionType
===
CollectionType
.
all
)
typeFilteredList
=
collectionList
typeFilteredList
=
collectionList
else
else
if
(
collectionType
===
CollectionType
.
builtIn
)
typeFilteredList
=
collectionList
.
filter
(
item
=>
item
.
type
===
collectionType
)
typeFilteredList
=
collectionList
.
filter
(
item
=>
item
.
type
===
CollectionType
.
builtIn
||
item
.
type
===
CollectionType
.
model
)
if
(
query
)
if
(
query
)
return
typeFilteredList
.
filter
(
item
=>
item
.
name
.
includes
(
query
))
return
typeFilteredList
.
filter
(
item
=>
item
.
name
.
includes
(
query
))
...
...
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