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.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from contextvars import ContextVar
  2. from threading import Lock
  3. from typing import TYPE_CHECKING
  4. from contexts.wrapper import RecyclableContextVar
  5. if TYPE_CHECKING:
  6. from core.datasource.__base.datasource_provider import DatasourcePluginProviderController
  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. """
  11. To avoid race-conditions caused by gunicorn thread recycling, using RecyclableContextVar to replace with
  12. """
  13. plugin_tool_providers: RecyclableContextVar[dict[str, "PluginToolProviderController"]] = RecyclableContextVar(
  14. ContextVar("plugin_tool_providers")
  15. )
  16. plugin_tool_providers_lock: RecyclableContextVar[Lock] = RecyclableContextVar(ContextVar("plugin_tool_providers_lock"))
  17. plugin_model_providers: RecyclableContextVar[list["PluginModelProviderEntity"] | None] = RecyclableContextVar(
  18. ContextVar("plugin_model_providers")
  19. )
  20. plugin_model_providers_lock: RecyclableContextVar[Lock] = RecyclableContextVar(
  21. ContextVar("plugin_model_providers_lock")
  22. )
  23. plugin_model_schema_lock: RecyclableContextVar[Lock] = RecyclableContextVar(ContextVar("plugin_model_schema_lock"))
  24. plugin_model_schemas: RecyclableContextVar[dict[str, "AIModelEntity"]] = RecyclableContextVar(
  25. ContextVar("plugin_model_schemas")
  26. )
  27. datasource_plugin_providers: RecyclableContextVar[dict[str, "DatasourcePluginProviderController"]] = (
  28. RecyclableContextVar(ContextVar("datasource_plugin_providers"))
  29. )
  30. datasource_plugin_providers_lock: RecyclableContextVar[Lock] = RecyclableContextVar(
  31. ContextVar("datasource_plugin_providers_lock")
  32. )