You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

__init__.py 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from contextvars import ContextVar
  2. from threading import Lock
  3. from typing import TYPE_CHECKING
  4. from contexts.wrapper import RecyclableContextVar
  5. from core.datasource.__base.datasource_provider import DatasourcePluginProviderController
  6. if TYPE_CHECKING:
  7. from core.model_runtime.entities.model_entities import AIModelEntity
  8. from core.plugin.entities.plugin_daemon import PluginModelProviderEntity
  9. from core.tools.plugin_tool.provider import PluginToolProviderController
  10. from core.workflow.entities.variable_pool import VariablePool
  11. tenant_id: ContextVar[str] = ContextVar("tenant_id")
  12. workflow_variable_pool: ContextVar["VariablePool"] = ContextVar("workflow_variable_pool")
  13. """
  14. To avoid race-conditions caused by gunicorn thread recycling, using RecyclableContextVar to replace with
  15. """
  16. plugin_tool_providers: RecyclableContextVar[dict[str, "PluginToolProviderController"]] = RecyclableContextVar(
  17. ContextVar("plugin_tool_providers")
  18. )
  19. plugin_tool_providers_lock: RecyclableContextVar[Lock] = RecyclableContextVar(ContextVar("plugin_tool_providers_lock"))
  20. plugin_model_providers: RecyclableContextVar[list["PluginModelProviderEntity"] | None] = RecyclableContextVar(
  21. ContextVar("plugin_model_providers")
  22. )
  23. plugin_model_providers_lock: RecyclableContextVar[Lock] = RecyclableContextVar(
  24. ContextVar("plugin_model_providers_lock")
  25. )
  26. plugin_model_schema_lock: RecyclableContextVar[Lock] = RecyclableContextVar(ContextVar("plugin_model_schema_lock"))
  27. plugin_model_schemas: RecyclableContextVar[dict[str, "AIModelEntity"]] = RecyclableContextVar(
  28. ContextVar("plugin_model_schemas")
  29. )
  30. datasource_plugin_providers: RecyclableContextVar[dict[str, "DatasourcePluginProviderController"]] = RecyclableContextVar(
  31. ContextVar("datasource_plugin_providers")
  32. )
  33. datasource_plugin_providers_lock: RecyclableContextVar[Lock] = RecyclableContextVar(
  34. ContextVar("datasource_plugin_providers_lock")
  35. )