Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support litellm router features? #314

Open
benwhalley opened this issue Aug 20, 2024 · 3 comments
Open

Support litellm router features? #314

benwhalley opened this issue Aug 20, 2024 · 3 comments

Comments

@benwhalley
Copy link

litellm includes some nice features to rate limit calls, and switch between deployments based on https://docs.litellm.ai/docs/routing

I wonder if it would be possible to configure magentic to accept a router config?

e.g. on line 12 here, rather than just importing litellm and then using litellm.completion you could create a router instance based on a MAGENTIC_LITELLM_ROUTER config and below on line 61 or 94 use router.completion or router.acompletion rather than litellm.acompletion?

https://github.com/jackmpcollins/magentic/blob/5b4b1012e630bd01baa0ef8bf3caf86fb68ae993/src/magentic/chat_model/litellm_chat_model.py

My initial use case is just setting RPM limits, but I can see it would also be nice to be able to track token usage.

@jackmpcollins
Copy link
Owner

It's not currently possible but it could definitely be added. The code you link is old. The newer version would be even more simple to update.

response = discard_none_arguments(litellm.completion)(
model=self.model,

I think a good approach would be to add a router: litellm.Router | None = None parameter to LitellmChatModel.__init__. Then in (a)complete use router.completion instead of litellm.completion if router was provided (assuming they meet the same interface, which appears to be the case).

@benwhalley
Copy link
Author

would you be open to a pr if I have a go at this?

@jackmpcollins
Copy link
Owner

would you be open to a pr if I have a go at this?

@benwhalley Absolutely!

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

No branches or pull requests

2 participants