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
c9368925
Unverified
Commit
c9368925
authored
Nov 21, 2023
by
takatost
Committed by
GitHub
Nov 21, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add `supported_model_types` field and filter in provider list (#1581)
parent
0d9ce1ba
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
78 additions
and
10 deletions
+78
-10
model_providers.py
api/controllers/console/workspace/model_providers.py
+5
-1
anthropic.json
api/core/model_providers/rules/anthropic.json
+3
-0
azure_openai.json
api/core/model_providers/rules/azure_openai.json
+4
-0
baichuan.json
api/core/model_providers/rules/baichuan.json
+3
-0
chatglm.json
api/core/model_providers/rules/chatglm.json
+4
-1
cohere.json
api/core/model_providers/rules/cohere.json
+4
-1
huggingface_hub.json
api/core/model_providers/rules/huggingface_hub.json
+5
-1
localai.json
api/core/model_providers/rules/localai.json
+5
-1
minimax.json
api/core/model_providers/rules/minimax.json
+4
-0
openai.json
api/core/model_providers/rules/openai.json
+6
-0
openllm.json
api/core/model_providers/rules/openllm.json
+5
-1
replicate.json
api/core/model_providers/rules/replicate.json
+5
-1
spark.json
api/core/model_providers/rules/spark.json
+3
-0
tongyi.json
api/core/model_providers/rules/tongyi.json
+3
-0
wenxin.json
api/core/model_providers/rules/wenxin.json
+3
-0
xinference.json
api/core/model_providers/rules/xinference.json
+5
-1
zhipuai.json
api/core/model_providers/rules/zhipuai.json
+4
-0
provider_service.py
api/services/provider_service.py
+7
-2
No files found.
api/controllers/console/workspace/model_providers.py
View file @
c9368925
...
@@ -21,8 +21,12 @@ class ModelProviderListApi(Resource):
...
@@ -21,8 +21,12 @@ class ModelProviderListApi(Resource):
def
get
(
self
):
def
get
(
self
):
tenant_id
=
current_user
.
current_tenant_id
tenant_id
=
current_user
.
current_tenant_id
parser
=
reqparse
.
RequestParser
()
parser
.
add_argument
(
'model_type'
,
type
=
str
,
required
=
False
,
nullable
=
True
,
location
=
'args'
)
args
=
parser
.
parse_args
()
provider_service
=
ProviderService
()
provider_service
=
ProviderService
()
provider_list
=
provider_service
.
get_provider_list
(
tenant_id
)
provider_list
=
provider_service
.
get_provider_list
(
tenant_id
=
tenant_id
,
model_type
=
args
.
get
(
'model_type'
)
)
return
provider_list
return
provider_list
...
...
api/core/model_providers/rules/anthropic.json
View file @
c9368925
...
@@ -12,6 +12,9 @@
...
@@ -12,6 +12,9 @@
"quota_limit"
:
0
"quota_limit"
:
0
},
},
"model_flexibility"
:
"fixed"
,
"model_flexibility"
:
"fixed"
,
"supported_model_types"
:
[
"text-generation"
],
"price_config"
:
{
"price_config"
:
{
"claude-instant-1"
:
{
"claude-instant-1"
:
{
"prompt"
:
"1.63"
,
"prompt"
:
"1.63"
,
...
...
api/core/model_providers/rules/azure_openai.json
View file @
c9368925
...
@@ -4,6 +4,10 @@
...
@@ -4,6 +4,10 @@
],
],
"system_config"
:
null
,
"system_config"
:
null
,
"model_flexibility"
:
"configurable"
,
"model_flexibility"
:
"configurable"
,
"supported_model_types"
:
[
"text-generation"
,
"embeddings"
],
"price_config"
:{
"price_config"
:{
"gpt-4"
:
{
"gpt-4"
:
{
"prompt"
:
"0.03"
,
"prompt"
:
"0.03"
,
...
...
api/core/model_providers/rules/baichuan.json
View file @
c9368925
...
@@ -4,6 +4,9 @@
...
@@ -4,6 +4,9 @@
],
],
"system_config"
:
null
,
"system_config"
:
null
,
"model_flexibility"
:
"fixed"
,
"model_flexibility"
:
"fixed"
,
"supported_model_types"
:
[
"text-generation"
],
"price_config"
:
{
"price_config"
:
{
"baichuan2-53b"
:
{
"baichuan2-53b"
:
{
"prompt"
:
"0.01"
,
"prompt"
:
"0.01"
,
...
...
api/core/model_providers/rules/chatglm.json
View file @
c9368925
...
@@ -3,5 +3,8 @@
...
@@ -3,5 +3,8 @@
"custom"
"custom"
],
],
"system_config"
:
null
,
"system_config"
:
null
,
"model_flexibility"
:
"fixed"
"model_flexibility"
:
"fixed"
,
"supported_model_types"
:
[
"text-generation"
]
}
}
\ No newline at end of file
api/core/model_providers/rules/cohere.json
View file @
c9368925
...
@@ -3,5 +3,8 @@
...
@@ -3,5 +3,8 @@
"custom"
"custom"
],
],
"system_config"
:
null
,
"system_config"
:
null
,
"model_flexibility"
:
"fixed"
"model_flexibility"
:
"fixed"
,
"supported_model_types"
:
[
"reranking"
]
}
}
\ No newline at end of file
api/core/model_providers/rules/huggingface_hub.json
View file @
c9368925
...
@@ -3,5 +3,9 @@
...
@@ -3,5 +3,9 @@
"custom"
"custom"
],
],
"system_config"
:
null
,
"system_config"
:
null
,
"model_flexibility"
:
"configurable"
"model_flexibility"
:
"configurable"
,
"supported_model_types"
:
[
"text-generation"
,
"embeddings"
]
}
}
\ No newline at end of file
api/core/model_providers/rules/localai.json
View file @
c9368925
...
@@ -3,5 +3,9 @@
...
@@ -3,5 +3,9 @@
"custom"
"custom"
],
],
"system_config"
:
null
,
"system_config"
:
null
,
"model_flexibility"
:
"configurable"
"model_flexibility"
:
"configurable"
,
"supported_model_types"
:
[
"text-generation"
,
"embeddings"
]
}
}
\ No newline at end of file
api/core/model_providers/rules/minimax.json
View file @
c9368925
...
@@ -10,6 +10,10 @@
...
@@ -10,6 +10,10 @@
"quota_unit"
:
"tokens"
"quota_unit"
:
"tokens"
},
},
"model_flexibility"
:
"fixed"
,
"model_flexibility"
:
"fixed"
,
"supported_model_types"
:
[
"text-generation"
,
"embeddings"
],
"price_config"
:
{
"price_config"
:
{
"abab5.5-chat"
:
{
"abab5.5-chat"
:
{
"prompt"
:
"0.015"
,
"prompt"
:
"0.015"
,
...
...
api/core/model_providers/rules/openai.json
View file @
c9368925
...
@@ -11,6 +11,12 @@
...
@@ -11,6 +11,12 @@
"quota_limit"
:
200
"quota_limit"
:
200
},
},
"model_flexibility"
:
"fixed"
,
"model_flexibility"
:
"fixed"
,
"supported_model_types"
:
[
"text-generation"
,
"embeddings"
,
"speech2text"
,
"moderation"
],
"price_config"
:
{
"price_config"
:
{
"gpt-4"
:
{
"gpt-4"
:
{
"prompt"
:
"0.03"
,
"prompt"
:
"0.03"
,
...
...
api/core/model_providers/rules/openllm.json
View file @
c9368925
...
@@ -3,5 +3,9 @@
...
@@ -3,5 +3,9 @@
"custom"
"custom"
],
],
"system_config"
:
null
,
"system_config"
:
null
,
"model_flexibility"
:
"configurable"
"model_flexibility"
:
"configurable"
,
"supported_model_types"
:
[
"text-generation"
,
"embeddings"
]
}
}
\ No newline at end of file
api/core/model_providers/rules/replicate.json
View file @
c9368925
...
@@ -3,5 +3,9 @@
...
@@ -3,5 +3,9 @@
"custom"
"custom"
],
],
"system_config"
:
null
,
"system_config"
:
null
,
"model_flexibility"
:
"configurable"
"model_flexibility"
:
"configurable"
,
"supported_model_types"
:
[
"text-generation"
,
"embeddings"
]
}
}
\ No newline at end of file
api/core/model_providers/rules/spark.json
View file @
c9368925
...
@@ -10,6 +10,9 @@
...
@@ -10,6 +10,9 @@
"quota_unit"
:
"tokens"
"quota_unit"
:
"tokens"
},
},
"model_flexibility"
:
"fixed"
,
"model_flexibility"
:
"fixed"
,
"supported_model_types"
:
[
"text-generation"
],
"price_config"
:
{
"price_config"
:
{
"spark"
:
{
"spark"
:
{
"prompt"
:
"0.18"
,
"prompt"
:
"0.18"
,
...
...
api/core/model_providers/rules/tongyi.json
View file @
c9368925
...
@@ -4,6 +4,9 @@
...
@@ -4,6 +4,9 @@
],
],
"system_config"
:
null
,
"system_config"
:
null
,
"model_flexibility"
:
"fixed"
,
"model_flexibility"
:
"fixed"
,
"supported_model_types"
:
[
"text-generation"
],
"price_config"
:
{
"price_config"
:
{
"qwen-turbo"
:
{
"qwen-turbo"
:
{
"prompt"
:
"0.012"
,
"prompt"
:
"0.012"
,
...
...
api/core/model_providers/rules/wenxin.json
View file @
c9368925
...
@@ -4,6 +4,9 @@
...
@@ -4,6 +4,9 @@
],
],
"system_config"
:
null
,
"system_config"
:
null
,
"model_flexibility"
:
"fixed"
,
"model_flexibility"
:
"fixed"
,
"supported_model_types"
:
[
"text-generation"
],
"price_config"
:
{
"price_config"
:
{
"ernie-bot-4"
:
{
"ernie-bot-4"
:
{
"prompt"
:
"0"
,
"prompt"
:
"0"
,
...
...
api/core/model_providers/rules/xinference.json
View file @
c9368925
...
@@ -3,5 +3,9 @@
...
@@ -3,5 +3,9 @@
"custom"
"custom"
],
],
"system_config"
:
null
,
"system_config"
:
null
,
"model_flexibility"
:
"configurable"
"model_flexibility"
:
"configurable"
,
"supported_model_types"
:
[
"text-generation"
,
"embeddings"
]
}
}
\ No newline at end of file
api/core/model_providers/rules/zhipuai.json
View file @
c9368925
...
@@ -10,6 +10,10 @@
...
@@ -10,6 +10,10 @@
"quota_unit"
:
"tokens"
"quota_unit"
:
"tokens"
},
},
"model_flexibility"
:
"fixed"
,
"model_flexibility"
:
"fixed"
,
"supported_model_types"
:
[
"text-generation"
,
"embeddings"
],
"price_config"
:
{
"price_config"
:
{
"chatglm_turbo"
:
{
"chatglm_turbo"
:
{
"prompt"
:
"0.005"
,
"prompt"
:
"0.005"
,
...
...
api/services/provider_service.py
View file @
c9368925
...
@@ -17,11 +17,12 @@ from models.provider import Provider, ProviderModel, TenantPreferredModelProvide
...
@@ -17,11 +17,12 @@ from models.provider import Provider, ProviderModel, TenantPreferredModelProvide
class
ProviderService
:
class
ProviderService
:
def
get_provider_list
(
self
,
tenant_id
:
str
)
:
def
get_provider_list
(
self
,
tenant_id
:
str
,
model_type
:
Optional
[
str
]
=
None
)
->
list
:
"""
"""
get provider list of tenant.
get provider list of tenant.
:param tenant_id:
:param tenant_id: workspace id
:param model_type: filter by model type
:return:
:return:
"""
"""
# get rules for all providers
# get rules for all providers
...
@@ -79,6 +80,9 @@ class ProviderService:
...
@@ -79,6 +80,9 @@ class ProviderService:
providers_list
=
{}
providers_list
=
{}
for
model_provider_name
,
model_provider_rule
in
model_provider_rules
.
items
():
for
model_provider_name
,
model_provider_rule
in
model_provider_rules
.
items
():
if
model_type
and
model_type
not
in
model_provider_rule
.
get
(
'supported_model_types'
,
[]):
continue
# get preferred provider type
# get preferred provider type
preferred_model_provider
=
provider_name_to_preferred_provider_type_dict
.
get
(
model_provider_name
)
preferred_model_provider
=
provider_name_to_preferred_provider_type_dict
.
get
(
model_provider_name
)
preferred_provider_type
=
ModelProviderFactory
.
get_preferred_type_by_preferred_model_provider
(
preferred_provider_type
=
ModelProviderFactory
.
get_preferred_type_by_preferred_model_provider
(
...
@@ -90,6 +94,7 @@ class ProviderService:
...
@@ -90,6 +94,7 @@ class ProviderService:
provider_config_dict
=
{
provider_config_dict
=
{
"preferred_provider_type"
:
preferred_provider_type
,
"preferred_provider_type"
:
preferred_provider_type
,
"model_flexibility"
:
model_provider_rule
[
'model_flexibility'
],
"model_flexibility"
:
model_provider_rule
[
'model_flexibility'
],
"supported_model_types"
:
model_provider_rule
.
get
(
"supported_model_types"
,
[]),
}
}
provider_parameter_dict
=
{}
provider_parameter_dict
=
{}
...
...
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