+10









-LAN-
GitHub
twwu
crazywoola
jyong
Wu Tianwei
QuantumGhost
lyzno1
quicksand
Jyong
lyzno1
zxhlyh
Yongtao Huang
autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Joel
Copilot
nite-knite
Hanqing Zhao
gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Harry
85cda47c70
Signed-off-by: -LAN- <[email protected]> Co-authored-by: twwu <[email protected]> Co-authored-by: crazywoola <[email protected]> Co-authored-by: jyong <[email protected]> Co-authored-by: Wu Tianwei <[email protected]> Co-authored-by: QuantumGhost <[email protected]> Co-authored-by: lyzno1 <[email protected]> Co-authored-by: quicksand <[email protected]> Co-authored-by: Jyong <[email protected]> Co-authored-by: lyzno1 <[email protected]> Co-authored-by: zxhlyh <[email protected]> Co-authored-by: Yongtao Huang <[email protected]> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Joel <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: nite-knite <[email protected]> Co-authored-by: Hanqing Zhao <[email protected]> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Harry <[email protected]>
60 lines
2.1 KiB
Python
60 lines
2.1 KiB
Python
"""Provider ID entities for plugin system."""
|
|
|
|
import re
|
|
|
|
from werkzeug.exceptions import NotFound
|
|
|
|
|
|
class GenericProviderID:
|
|
organization: str
|
|
plugin_name: str
|
|
provider_name: str
|
|
is_hardcoded: bool
|
|
|
|
def to_string(self) -> str:
|
|
return str(self)
|
|
|
|
def __str__(self) -> str:
|
|
return f"{self.organization}/{self.plugin_name}/{self.provider_name}"
|
|
|
|
def __init__(self, value: str, is_hardcoded: bool = False) -> None:
|
|
if not value:
|
|
raise NotFound("plugin not found, please add plugin")
|
|
# check if the value is a valid plugin id with format: $organization/$plugin_name/$provider_name
|
|
if not re.match(r"^[a-z0-9_-]+\/[a-z0-9_-]+\/[a-z0-9_-]+$", value):
|
|
# check if matches [a-z0-9_-]+, if yes, append with langgenius/$value/$value
|
|
if re.match(r"^[a-z0-9_-]+$", value):
|
|
value = f"langgenius/{value}/{value}"
|
|
else:
|
|
raise ValueError(f"Invalid plugin id {value}")
|
|
|
|
self.organization, self.plugin_name, self.provider_name = value.split("/")
|
|
self.is_hardcoded = is_hardcoded
|
|
|
|
def is_langgenius(self) -> bool:
|
|
return self.organization == "langgenius"
|
|
|
|
@property
|
|
def plugin_id(self) -> str:
|
|
return f"{self.organization}/{self.plugin_name}"
|
|
|
|
|
|
class ModelProviderID(GenericProviderID):
|
|
def __init__(self, value: str, is_hardcoded: bool = False) -> None:
|
|
super().__init__(value, is_hardcoded)
|
|
if self.organization == "langgenius" and self.provider_name == "google":
|
|
self.plugin_name = "gemini"
|
|
|
|
|
|
class ToolProviderID(GenericProviderID):
|
|
def __init__(self, value: str, is_hardcoded: bool = False) -> None:
|
|
super().__init__(value, is_hardcoded)
|
|
if self.organization == "langgenius":
|
|
if self.provider_name in ["jina", "siliconflow", "stepfun", "gitee_ai"]:
|
|
self.plugin_name = f"{self.provider_name}_tool"
|
|
|
|
|
|
class DatasourceProviderID(GenericProviderID):
|
|
def __init__(self, value: str, is_hardcoded: bool = False) -> None:
|
|
super().__init__(value, is_hardcoded)
|