Unverified Commit 6fb03384 authored by Yeuoly's avatar Yeuoly

feat: add model provider alias

parent 5fde711b
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 图像理解
......@@ -4,6 +4,7 @@
- webscraper
- wolframalpha
- model_provider.openai
- model_provider.google
- chart
- time
- yahoo
......
from abc import abstractmethod
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, \
ToolParamter, ToolProviderCredentials, ToolDescription, ToolProviderIdentity
......@@ -13,6 +15,25 @@ from core.model_runtime.entities.model_entities import ModelType, ModelFeature
from core.entities.model_entities import ModelStatus
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):
configuration: ProviderConfiguration = None
is_active: bool = False
......@@ -43,14 +64,21 @@ class ModelToolProviderController(ToolProviderController):
is_active = False
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(
is_active=is_active,
identity=ToolProviderIdentity(
author='Dify',
name=configuration.provider.provider,
description=I18nObject(
zh_Hans=f'{configuration.provider.label.zh_Hans}多模态模型工具',
en_US=f'{configuration.provider.label.en_US} multimodal model tool'
zh_Hans=f'{configuration.provider.label.zh_Hans} 模型能力提供商',
en_US=f'{configuration.provider.label.en_US} model capability provider'
),
label=I18nObject(
zh_Hans=configuration.provider.label.zh_Hans,
......@@ -91,8 +119,20 @@ class ModelToolProviderController(ToolProviderController):
return tools
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():
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(
identity=ToolIdentity(
author='Dify',
......
......@@ -73,8 +73,8 @@ const Tools: FC<Props> = ({
let typeFilteredList: Collection[] = []
if (collectionType === CollectionType.all)
typeFilteredList = collectionList
else
typeFilteredList = collectionList.filter(item => item.type === collectionType)
else if (collectionType === CollectionType.builtIn)
typeFilteredList = collectionList.filter(item => item.type === CollectionType.builtIn || item.type === CollectionType.model)
if (query)
return typeFilteredList.filter(item => item.name.includes(query))
......
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