plugin_daemon.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. from datetime import datetime
  2. from enum import Enum
  3. from typing import Generic, Optional, TypeVar
  4. from pydantic import BaseModel, ConfigDict, Field
  5. from core.model_runtime.entities.model_entities import AIModelEntity
  6. from core.model_runtime.entities.provider_entities import ProviderEntity
  7. from core.tools.entities.tool_entities import ToolProviderEntityWithPlugin
  8. T = TypeVar("T", bound=(BaseModel | dict | list | bool))
  9. class PluginDaemonBasicResponse(BaseModel, Generic[T]):
  10. """
  11. Basic response from plugin daemon.
  12. """
  13. code: int
  14. message: str
  15. data: Optional[T]
  16. class InstallPluginMessage(BaseModel):
  17. """
  18. Message for installing a plugin.
  19. """
  20. class Event(Enum):
  21. Info = "info"
  22. Done = "done"
  23. Error = "error"
  24. event: Event
  25. data: str
  26. class PluginToolProviderEntity(BaseModel):
  27. provider: str
  28. plugin_unique_identifier: str
  29. plugin_id: str
  30. declaration: ToolProviderEntityWithPlugin
  31. class PluginBasicBooleanResponse(BaseModel):
  32. """
  33. Basic boolean response from plugin daemon.
  34. """
  35. result: bool
  36. class PluginModelSchemaEntity(BaseModel):
  37. model_schema: AIModelEntity = Field(description="The model schema.")
  38. # pydantic configs
  39. model_config = ConfigDict(protected_namespaces=())
  40. class PluginModelProviderEntity(BaseModel):
  41. id: str = Field(alias="ID", description="ID")
  42. created_at: datetime = Field(alias="CreatedAt", description="The created at time of the model provider.")
  43. updated_at: datetime = Field(alias="UpdatedAt", description="The updated at time of the model provider.")
  44. provider: str = Field(description="The provider of the model.")
  45. tenant_id: str = Field(description="The tenant ID.")
  46. plugin_unique_identifier: str = Field(description="The plugin unique identifier.")
  47. plugin_id: str = Field(description="The plugin ID.")
  48. declaration: ProviderEntity = Field(description="The declaration of the model provider.")
  49. class PluginNumTokensResponse(BaseModel):
  50. """
  51. Response for number of tokens.
  52. """
  53. num_tokens: int = Field(description="The number of tokens.")
  54. class PluginStringResultResponse(BaseModel):
  55. result: str = Field(description="The result of the string.")
  56. class PluginVoiceEntity(BaseModel):
  57. name: str = Field(description="The name of the voice.")
  58. value: str = Field(description="The value of the voice.")
  59. class PluginVoicesResponse(BaseModel):
  60. voices: list[PluginVoiceEntity] = Field(description="The result of the voices.")
  61. class PluginDaemonError(BaseModel):
  62. """
  63. Error from plugin daemon.
  64. """
  65. error_type: str
  66. message: str
  67. args: Optional[dict] = None
  68. class PluginDaemonInnerError(Exception):
  69. code: int
  70. message: str
  71. def __init__(self, code: int, message: str):
  72. self.code = code
  73. self.message = message