Make backends extensible without editing core stdlib internals

Aperta
#1,467 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

Start by reading mellea/stdlib/session.py and mellea/stdlib/start_backend.py, then trace backend_name_to_class and _resolve_model_id_str. Decide how registration, typing, and model defaults should work; done means an external backend can be added without changing the core unions, built-in overloads remain precise, and the docs explain authoring and use.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area/backends help wanted needs-design p2

Problem

Adding a backend today requires editing core stdlib internals in several places at once:

  • the Literal[...] backend-name unions on start_session (mellea/stdlib/session.py) and start_backend (mellea/stdlib/start_backend.py)
  • the if/elif dispatch in backend_name_to_class
  • the backend→model-attr map in _resolve_model_id_str
  • a block of @overloads per backend in start_backend

That means every new provider (e.g. #1426) is a change to core union types and dispatch, and the ongoing maintenance (e.g. provider model catalogs drifting over time) falls on core maintainers. It doesn't scale, and it sets the bar too high for what is often just a provider-convenience wrapper.

Goal

A registration mechanism so a backend can be added from outside stdlib without editing the core union types or dispatch.

Scope / open questions

  • Registration API: how are backend names/aliases registered? A registry dict, a decorator, or Python entry points via pyproject.toml. Entry points would let providers ship backends in separate packages.
  • Typing: start_backend currently relies on Literal + @overload for precise return types. Decide the typing contract for dynamically-registered backends (likely a generic fallback overload, with precise overloads kept only for built-ins).
  • Model-id resolution: _resolve_model_id_str hardcodes a backend→attr map. A registered backend needs to declare its own model-attr / default-model behavior.
  • Docs: a short "writing a backend" guide, plus a note in the core docs on how to use said backends.

Acceptance

  • A new provider backend can be added with no edits to session.py / start_backend.py core unions.
  • Built-in backends keep their precise typed overloads.
  • Docs cover both authoring and using a contributed backend.
Lingua principale
Python
Stelle
1.8k
Fork
161
Merge medio
4g 3h
PR unite (30g)
45

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di generative-computing/mellea

Tutte le issue di generative-computing/mellea

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.