Skip to content

feat(chat): add multi-provider chat/LLM abstraction (#285) - #317

Merged
codeforstartups merged 3 commits into
codeforstartups:developmentfrom
Kaap10:feat/chat-model-abstraction
Oct 2, 2026
Merged

codeforstartups merged 3 commits into
codeforstartups:developmentfrom
Kaap10:feat/chat-model-abstraction

Conversation

@Kaap10

@Kaap10 Kaap10 commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

Description

Implements a unified multi-provider chat/LLM abstraction layer mirroring Dynavec's embedder architecture. This provides a single consistent interface to interact with multiple LLM backends (OpenAI, Anthropic, and AWS Bedrock) with full support for message formatting, function/tool calling, structured output schemas, and token streaming.

Related issue

Fixes #285

Changes

  • Core Chat Abstraction (src/dynavec/chat/base.py):
    • Defined standard data models: Message, Role, Tool, ToolCall, ChatResult, and ChatChunk.
    • Defined abstract base class ChatModel providing sync (invoke, stream) and async (ainvoke, astream) execution interfaces.
  • Provider Implementations:
    • src/dynavec/chat/openai.py: Added OpenAIChatModel with OpenAI function/tool calling and streaming delta support.
    • src/dynavec/chat/anthropic.py: Added AnthropicChatModel mapping conversation roles to Anthropic content blocks, handling system prompts, tool uses, and event streaming.
    • src/dynavec/chat/bedrock.py: Added BedrockChatModel powered by the unified AWS Bedrock Converse and ConverseStream APIs.
  • Module Exports (src/dynavec/chat/__init__.py):
    • Configured lazy module imports for provider classes to keep external SDK dependencies (openai, anthropic, boto3) optional.
  • Testing (tests/test_chat_models.py):
    • Added 6 comprehensive offline unit tests covering invoke, tool-calling, stream handling, async delegation, and missing dependency guards across all providers.

Testing

  • Tests pass locally
  • Ruff checks pass
  • Documentation updated, if applicable

Checklist

  • My changes are focused and relevant to this pull request.
  • I have added or updated tests where appropriate.
  • I have reviewed my changes for unrelated modifications.
  • I have updated documentation where necessary.

@Kaap10

Kaap10 commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator Author

Ready for review!

@codeforstartups

Copy link
Copy Markdown
Owner

Reviewed in depth — this is a strong foundation for the dynaflow model layer (closes #285). 🎯

Design — the ChatModel ABC cleanly mirrors our embedder abstraction: sync invoke/stream, async ainvoke/astream defaulting to asyncio.to_thread, and clean dataclasses (Message / Role / Tool / ToolCall / ChatResult / ChatChunk). Function/tool calling and structured output are modeled from the start.

Optional deps done right — provider SDKs (openai / anthropic / boto3) stay optional via lazy __getattr__ imports in chat/__init__.py; anthropic added as its own extra + to all/typecheck + mypy overrides.

Tests — 6 genuine offline tests with per-provider fakes, async delegation, exports, and missing-dependency guards. Verified locally (6 passed) and all 4 CI checks pass incl. strict mypy on 3.9/3.11/3.12.

Two non-blocking follow-ups for later (not needed to merge):

  1. The default astream buffers the full sync stream into a list before yielding, so the async fallback loses incremental streaming — providers can override for true async streaming (Anthropic/OpenAI both support it).
  2. Gemini/Vertex + Azure OpenAI remain to round out the provider matrix from Multi-provider chat/LLM abstraction (Bedrock, OpenAI, Anthropic, Gemini/Vertex, Azure OpenAI, local) #285.

Merging — excellent work @Kaap10!

@codeforstartups
codeforstartups merged commit fcb5a34 into codeforstartups:development Oct 2, 2026
4 checks passed
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.

Multi-provider chat/LLM abstraction (Bedrock, OpenAI, Anthropic, Gemini/Vertex, Azure OpenAI, local)

2 participants