-
Notifications
You must be signed in to change notification settings - Fork 22
Open
Description
Problem
~75 trivial parameter mapper wrapper classes are duplicated across providers. Each wrapper exists solely to set name = SomeParameter.SOMETHING on a base mapper class. For example, TemperatureMapper, MaxTokensMapper, OutputSchemaMapper, and ToolsMapper are defined identically in deepseek, moonshot, groq, huggingface (ChatCompletions) and openai, xai, openresponses (OpenResponses).
Proposed Solution
Define wrapper classes once per protocol, providers reference the shared list. Zero pattern changes.
Before — same file repeated N times per protocol:
# modalities/text/providers/deepseek/parameters.py (one of many copies)
class TemperatureMapper(_TemperatureMapper):
name = TextParameter.TEMPERATURE
class MaxTokensMapper(_MaxTokensMapper):
name = TextParameter.MAX_TOKENS
# ...
DEEPSEEK_PARAMETER_MAPPERS = [TemperatureMapper(), MaxTokensMapper(), ...]After — defined once, referenced everywhere:
# Shared canonical source (e.g. providers/chatcompletions/parameters.py)
class TemperatureMapper(_TemperatureMapper):
name = TextParameter.TEMPERATURE
# ...
CHATCOMPLETIONS_PARAMETER_MAPPERS = [TemperatureMapper(), MaxTokensMapper(), ...]# Trivial providers — just reference the shared list
DEEPSEEK_PARAMETER_MAPPERS = CHATCOMPLETIONS_PARAMETER_MAPPERS# Custom providers — filter + extend
GROQ_PARAMETER_MAPPERS = [
m for m in CHATCOMPLETIONS_PARAMETER_MAPPERS if m.name != TextParameter.TOOLS
] + [GroqToolsMapper()]Scope
| Modality | Providers affected | Est. LOC saved |
|---|---|---|
| Text (ChatCompletions) | deepseek, moonshot, groq, huggingface, mistral | ~200 |
| Text (OpenResponses) | openai, xai | ~100 |
| Audio | elevenlabs, openai, gradium | ~40 |
| Videos | byteplus, google, xai | ~50 |
| Images | openai, xai, byteplus, google | ~30 |
| Embeddings | ~5 |
Providers with custom logic (Anthropic, Cohere, Google text) keep their own files — only trivial wrappers are consolidated.
Validation
- Mappers are stateless — no instance state, no
__init__, noself.*writes - No
isinstanceor class identity checks on mappers anywhere in the codebase - Same mapper instances are safe to share across providers
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels