Unverified Commit c9368925 authored by takatost's avatar takatost Committed by GitHub

feat: add `supported_model_types` field and filter in provider list (#1581)

parent 0d9ce1ba
...@@ -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
......
...@@ -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",
......
...@@ -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",
......
...@@ -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",
......
...@@ -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
...@@ -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
...@@ -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
...@@ -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
...@@ -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",
......
...@@ -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",
......
...@@ -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
...@@ -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
...@@ -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",
......
...@@ -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",
......
...@@ -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",
......
...@@ -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
...@@ -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",
......
...@@ -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 = {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment