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

12345678910111213141516171819202122232425262728293031323334
  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.model_runtime.entities.model_entities import AIModelEntity
  7. from core.plugin.entities.plugin_daemon import PluginModelProviderEntity
  8. from core.tools.plugin_tool.provider import PluginToolProviderController
  9. """
  10. To avoid race-conditions caused by gunicorn thread recycling, using RecyclableContextVar to replace with
  11. """
  12. plugin_tool_providers: RecyclableContextVar[dict[str, "PluginToolProviderController"]] = RecyclableContextVar(
  13. ContextVar("plugin_tool_providers")
  14. )
  15. plugin_tool_providers_lock: RecyclableContextVar[Lock] = RecyclableContextVar(ContextVar("plugin_tool_providers_lock"))
  16. plugin_model_providers: RecyclableContextVar[list["PluginModelProviderEntity"] | None] = RecyclableContextVar(
  17. ContextVar("plugin_model_providers")
  18. )
  19. plugin_model_providers_lock: RecyclableContextVar[Lock] = RecyclableContextVar(
  20. ContextVar("plugin_model_providers_lock")
  21. )
  22. plugin_model_schema_lock: RecyclableContextVar[Lock] = RecyclableContextVar(ContextVar("plugin_model_schema_lock"))
  23. plugin_model_schemas: RecyclableContextVar[dict[str, "AIModelEntity"]] = RecyclableContextVar(
  24. ContextVar("plugin_model_schemas")
  25. )