mirror of
https://github.com/Alishahryar1/free-claude-code.git
synced 2026-07-03 14:05:26 +02:00
fa01c2a3a6
## Summary - move provider transport families under `providers/transports/` - split OpenAI-chat transport into thin transport, stream runner, tool-call assembly, and recovery modules - split native Anthropic transport into thin transport, stream runner, recovery, and HTTP helper modules - update concrete provider imports, architecture docs, transport import contracts, version, and lockfile ## Verification - `uv run pytest tests/providers/test_streaming_errors.py tests/providers/test_openai_compat_5xx_retry.py tests/providers/test_anthropic_messages.py tests/providers/test_anthropic_messages_429_retry.py tests/providers/test_provider_transport_logging.py tests/providers/test_gemini.py tests/providers/test_nvidia_nim_request.py tests/providers/test_subagent_interception.py tests/contracts/test_import_boundaries.py` - `uv run ruff format` - `./scripts/ci.ps1`
50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
"""Google AI Studio Gemini provider (OpenAI-compatible chat completions)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from copy import deepcopy
|
|
from typing import Any
|
|
|
|
from providers.base import ProviderConfig
|
|
from providers.defaults import GEMINI_DEFAULT_BASE
|
|
from providers.transports.openai_chat import OpenAIChatTransport
|
|
|
|
from .request import build_request_body
|
|
|
|
_MAX_TOOL_CALL_EXTRA_CONTENT_CACHE = 4096
|
|
|
|
|
|
class GeminiProvider(OpenAIChatTransport):
|
|
"""Gemini API using ``https://generativelanguage.googleapis.com/v1beta/openai/``."""
|
|
|
|
def __init__(self, config: ProviderConfig):
|
|
super().__init__(
|
|
config,
|
|
provider_name="GEMINI",
|
|
base_url=config.base_url or GEMINI_DEFAULT_BASE,
|
|
api_key=config.api_key,
|
|
)
|
|
self._tool_call_extra_content_by_id: dict[str, dict[str, Any]] = {}
|
|
|
|
def _record_tool_call_extra_content(
|
|
self, tool_call_id: str, extra_content: dict[str, Any]
|
|
) -> None:
|
|
if (
|
|
tool_call_id not in self._tool_call_extra_content_by_id
|
|
and len(self._tool_call_extra_content_by_id)
|
|
>= _MAX_TOOL_CALL_EXTRA_CONTENT_CACHE
|
|
):
|
|
self._tool_call_extra_content_by_id.pop(
|
|
next(iter(self._tool_call_extra_content_by_id))
|
|
)
|
|
self._tool_call_extra_content_by_id[tool_call_id] = deepcopy(extra_content)
|
|
|
|
def _build_request_body(
|
|
self, request: Any, thinking_enabled: bool | None = None
|
|
) -> dict:
|
|
return build_request_body(
|
|
request,
|
|
thinking_enabled=self._is_thinking_enabled(request, thinking_enabled),
|
|
tool_call_extra_content_by_id=self._tool_call_extra_content_by_id,
|
|
)
|