Skip to content

Refactor/adapters#12

Merged
Verdenroz merged 23 commits intomasterfrom
refactor/adapters
Feb 18, 2026
Merged

Refactor/adapters#12
Verdenroz merged 23 commits intomasterfrom
refactor/adapters

Conversation

@Verdenroz
Copy link
Copy Markdown
Owner

This branch replaces the old SDK-per-provider architecture with a unified HTTP layer backed by stateless adapters, removes ~9k lines of duplicated provider code, adds structured output, completes the provider matrix (OpenRouter), hardens the test suite, and polishes the public API surface.


Architecture Change

Before

  • Each provider had its own client class in src/chimeric/providers/<name>/client.py, each importing that provider's SDK (openai, anthropic, google-generativeai, etc.)
  • ~7 provider SDK dependencies; install extras per-provider
  • base.py (1585 lines) held a monolithic base class shared by all providers

After

  • No SDK dependencies — single httpx transport for all providers
  • src/chimeric/http.py — one HttpClient with sync + async paths, tool-execution loop, SSE parsing
  • src/chimeric/adapters/ — 4 stateless pure-function adapters (openai, anthropic, google, cohere)
  • src/chimeric/config.py — immutable ProviderConfig dataclass + PROVIDER_REGISTRY (8 providers)
  • OpenAI adapter is reused by: groq, cerebras, grok, openrouter (different base_url only)
  • Plain pip install chimeric — no per-provider extras

What Changed

Core (src/chimeric/)

File Change
base.py Deleted (1585 lines)
providers/*/client.py Deleted (7 provider clients, ~6500 lines total)
config.py NewProviderConfig dataclass + PROVIDER_REGISTRY
http.py New — unified sync/async HTTP client, tool loop, SSE
adapters/openai.py New — request/response adapter for OpenAI wire format
adapters/anthropic.py New — Anthropic messages API adapter
adapters/google.py New — Gemini REST adapter (query-param auth, model-in-path URLs)
adapters/cohere.py New — Cohere /chat NDJSON-SSE adapter
schema.py New — structured output schema builder (per-provider JSON schema shaping)
chimeric.py Rewritten facade; routing, tool management, response_model support
__init__.py Trimmed public API — removed internal types (ToolManager, ToolCallChunk, ToolExecutionResult, ToolParameters)

New public API additions (chimeric.py)

  • base_url / api_key constructor params — registers a custom OpenAI-compatible endpoint (e.g. local llama.cpp / llama-swap / Ollama) as a "custom" provider with automatic model routing
  • response_model — pass a Pydantic model class to generate() / agenerate() for structured JSON output; the parsed instance is available on response.parsed

Tests

Suite Count Coverage
Unit 257 84.6%
Integration VCR-cassette based, all providers reverified

New test files

File What it covers
tests/unit/test_config.py PROVIDER_REGISTRY structure and immutability
tests/unit/test_http.py HttpClient URL/header building, error mapping
tests/unit/test_schema.py Structured output schema builders per provider
tests/unit/adapters/test_openai.py OpenAI adapter request/response/streaming
tests/unit/adapters/test_anthropic.py Anthropic adapter
tests/unit/adapters/test_google.py Google adapter
tests/unit/adapters/test_cohere.py Cohere adapter
tests/unit/test_doc_examples.py 48 tests — every public code block in docs verified against live API shapes
tests/integration/test_provider_openrouter.py OpenRouter end-to-end (new provider)
tests/integration/test_structured_outputs.py Structured output across all providers

Removed test files

Old SDK-based unit tests (tests/unit/providers/test_*.py, tests/unit/test_base.py) deleted alongside the code they tested.


Documentation

File Change
docs/index.md 8 providers (was 7); removed provider extras install; removed native=True
docs/usage/getting-started.md Removed native=True / stop_reason; fixed streaming field names
docs/usage/configuration.md Accurate to new API
docs/usage/local-ai.md New — custom base_url usage, llama-swap / Ollama / LM Studio
docs/usage/streaming.md Removed stale "native streaming" bullet
docs/usage/responses.md usage nullable guard added
docs/usage/tools.md Removed non-existent get_capabilities() reference
mkdocs.yml "Local AI" added to nav

Breaking Changes

What Detail
native=True parameter Removed — provider-specific extras are in response.metadata
Provider install extras Removed — pip install chimeric installs all providers
ToolManager top-level export Moved to chimeric.tools.ToolManager
ToolCallChunk, ToolExecutionResult, ToolParameters No longer in chimeric.* — import from chimeric.types if needed

- Deleted client classes from the providers module.
- Removed related imports and references in the __init__.py file.
- Updated types.py to streamline core data models and removed unused classes.
- Simplified utility functions in utils.py, focusing on message normalization and response creation.
@Verdenroz Verdenroz merged commit 6596e42 into master Feb 18, 2026
14 checks passed
@Verdenroz Verdenroz mentioned this pull request Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant