pydantic-ai icon indicating copy to clipboard operation
pydantic-ai copied to clipboard

Fallback Model Support

Open sydney-runkle opened this issue 11 months ago • 4 comments

To mitigate issues with unpredictable LLM downtime: we'd like to add a new model that supports a list of models to use as fallbacks if the first doesn't work.

sydney-runkle avatar Dec 20 '24 15:12 sydney-runkle

I think the API can be as Simple as

model = FallbackModel('openai:gpt-4o', 'claude-3-5-haiku-latest', GeminiModel(...))
agent = Agent(model, ...)

E.g. the signature of FallbackModel is something like

class FallbackModel:
    def __init__(self, default_model: models.Model | models.KnownModelName, *fallback_models: models.Model | models.KnownModelName):
        ...

samuelcolvin avatar Jan 02 '25 17:01 samuelcolvin

Implemented a pydantic-ai FallbackModel some time ago here, in case there is interest: https://github.com/phil65/LLMling-models Cheers!

phil65 avatar Jan 03 '25 13:01 phil65

Another advantage of having a consistent way to detect 503 etc. responses, is we can use it to mark live tests as xfail when the underlying model fails.

samuelcolvin avatar Jan 07 '25 15:01 samuelcolvin

It´s actually quite funny what kind of things all can be done at model level. I now added a model to
to stream from another remote pydantic-ai model using FastAPI . 😄 (code might be sub-optimal though, just learning FastAPI a bit)

phil65 avatar Jan 07 '25 21:01 phil65

Will be starting work on this later today. PR to come soon 👍

sydney-runkle avatar Jan 08 '25 16:01 sydney-runkle

Implemented a pydantic-ai FallbackModel some time ago here, in case there is interest: https://github.com/phil65/LLMling-models Cheers!

Awesome, thanks so much @phil65!

sydney-runkle avatar Jan 08 '25 19:01 sydney-runkle