Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """Provider ID entities for plugin system."""
  2. import re
  3. from werkzeug.exceptions import NotFound
  4. class GenericProviderID:
  5. organization: str
  6. plugin_name: str
  7. provider_name: str
  8. is_hardcoded: bool
  9. def to_string(self) -> str:
  10. return str(self)
  11. def __str__(self) -> str:
  12. return f"{self.organization}/{self.plugin_name}/{self.provider_name}"
  13. def __init__(self, value: str, is_hardcoded: bool = False) -> None:
  14. if not value:
  15. raise NotFound("plugin not found, please add plugin")
  16. # check if the value is a valid plugin id with format: $organization/$plugin_name/$provider_name
  17. if not re.match(r"^[a-z0-9_-]+\/[a-z0-9_-]+\/[a-z0-9_-]+$", value):
  18. # check if matches [a-z0-9_-]+, if yes, append with langgenius/$value/$value
  19. if re.match(r"^[a-z0-9_-]+$", value):
  20. value = f"langgenius/{value}/{value}"
  21. else:
  22. raise ValueError(f"Invalid plugin id {value}")
  23. self.organization, self.plugin_name, self.provider_name = value.split("/")
  24. self.is_hardcoded = is_hardcoded
  25. def is_langgenius(self) -> bool:
  26. return self.organization == "langgenius"
  27. @property
  28. def plugin_id(self) -> str:
  29. return f"{self.organization}/{self.plugin_name}"
  30. class ModelProviderID(GenericProviderID):
  31. def __init__(self, value: str, is_hardcoded: bool = False) -> None:
  32. super().__init__(value, is_hardcoded)
  33. if self.organization == "langgenius" and self.provider_name == "google":
  34. self.plugin_name = "gemini"
  35. class ToolProviderID(GenericProviderID):
  36. def __init__(self, value: str, is_hardcoded: bool = False) -> None:
  37. super().__init__(value, is_hardcoded)
  38. if self.organization == "langgenius":
  39. if self.provider_name in ["jina", "siliconflow", "stepfun", "gitee_ai"]:
  40. self.plugin_name = f"{self.provider_name}_tool"
  41. class DatasourceProviderID(GenericProviderID):
  42. def __init__(self, value: str, is_hardcoded: bool = False) -> None:
  43. super().__init__(value, is_hardcoded)