__init__.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. """Ollama Cloud provider profile.
  2. Top-level ``reasoning_effort`` on /v1/chat/completions accepts none|low|medium|
  3. high|max (``max`` is undocumented but real — ~2.5x more thinking tokens on
  4. DeepSeek V4); Hermes' ``xhigh`` maps to ``max``.
  5. """
  6. from typing import Any
  7. from agent.reasoning_effort import OLLAMA_CLOUD_EFFORTS, OLLAMA_CLOUD_OVERRIDES, clamp_effort
  8. from providers import register_provider
  9. from providers.base import ProviderProfile
  10. class OllamaCloudProfile(ProviderProfile):
  11. """Ollama Cloud — maps xhigh→max via top-level reasoning_effort."""
  12. def build_api_kwargs_extras(
  13. self, *, reasoning_config: dict | None = None, supports_reasoning: bool = False, **ctx: Any
  14. ) -> tuple[dict[str, Any], dict[str, Any]]:
  15. """Gated on ``supports_reasoning`` (resolved from the model's /api/show
  16. ``thinking`` capability) so non-thinking models get no meaningless field."""
  17. if not supports_reasoning or not reasoning_config or not isinstance(reasoning_config, dict):
  18. return {}, {}
  19. # Ollama Cloud defaults to thinking ON and ignores extra_body.thinking
  20. # (verified live); top-level reasoning_effort:"none" is the ONLY off switch.
  21. effort = (reasoning_config.get("effort") or "").strip().lower()
  22. if reasoning_config.get("enabled", True) is False or effort == "none":
  23. return {}, {"reasoning_effort": "none"}
  24. if not effort:
  25. return {}, {} # let the server default (thinking ON) apply
  26. # "minimal" 400s -> clamps to low; xhigh rounds up to max. Bespoke
  27. # levels outside the ladder are omitted rather than risking a 400.
  28. clamped = clamp_effort(effort, OLLAMA_CLOUD_EFFORTS, OLLAMA_CLOUD_OVERRIDES)
  29. return {}, {"reasoning_effort": clamped} if clamped in OLLAMA_CLOUD_EFFORTS else {}
  30. ollama_cloud = OllamaCloudProfile(
  31. name="ollama-cloud", aliases=("ollama_cloud",), default_aux_model="nemotron-3-nano:30b",
  32. env_vars=("OLLAMA_API_KEY",), base_url="https://ollama.com/v1",
  33. )
  34. register_provider(ollama_cloud)