-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
feat: add LiteLLM support #549
Closed
Closed
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
781caed
feat: add --litellm
aleclarson 6804028
feat: default to litellm in certain cases
aleclarson 8e0ef61
fix: cache the litellm supported models data
aleclarson 3e28efe
fix: don‘t set --model default until later
aleclarson 399bc7e
fix: gemini 1.5 pro alias
aleclarson e83bf6e
fix: remove Model.create calls from aider/models/__init__.py
aleclarson edd88e6
fix: reuse litellm `model_cost` map and update its backup periodically
aleclarson fa4cbaf
chore: clean up
aleclarson 41ca019
fix: stop using pkg_resources
aleclarson 2484e6a
fix: set LiteLLM log level to ERROR
aleclarson ad53881
feat: support LITELLM_API_KEY, LITELLM_BASE_URL, etc
aleclarson aa8bca6
fix: check client typename instead of duck typing
aleclarson 164e4af
fix: import order issue
aleclarson 5613cc9
fix: stop using every LITELLM_ variable
aleclarson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import importlib.util | ||
import logging | ||
import tiktoken | ||
|
||
from .model import Model | ||
|
||
logging.basicConfig(level=logging.INFO, format="%(message)s") | ||
logger = logging.getLogger("aider-litellm") | ||
|
||
LITELLM_SPEC = importlib.util.find_spec("litellm") | ||
|
||
model_aliases = { | ||
# claude-3 | ||
"opus": "claude-3-opus-20240229", | ||
"sonnet": "claude-3-sonnet-20240229", | ||
"haiku": "claude-3-haiku-20240307", | ||
# gemini-1.5-pro | ||
"gemini": "gemini/gemini-1.5-pro-latest", | ||
# gpt-3.5 | ||
"gpt-3.5": "gpt-3.5-turbo-0613", | ||
"gpt-3.5-turbo": "gpt-3.5-turbo-0613", | ||
"gpt-3.5-turbo-16k": "gpt-3.5-turbo-16k-0613", | ||
# gpt-4 | ||
"gpt-4": "gpt-4-0613", | ||
"gpt-4-32k": "gpt-4-32k-0613", | ||
} | ||
|
||
models_info = None | ||
|
||
class LiteLLMModel(Model): | ||
def __init__(self, name): | ||
model_id = name | ||
if name in model_aliases: | ||
model_id = model_aliases[name] | ||
|
||
from litellm import model_cost | ||
|
||
model_data = model_cost.get(model_id) | ||
if not model_data: | ||
# For gemini 1.5 pro to work, LiteLLM appears to need the "-latest" | ||
# part included in the model name, but it's not included in the list | ||
# of supported models that way, so finesse it here | ||
if model_id == "gemini/gemini-1.5-pro-latest": | ||
model_data = model_cost.get("gemini/gemini-1.5-pro") | ||
if not model_data: | ||
raise ValueError(f"Unsupported model: {model_id}") | ||
else: | ||
raise ValueError(f"Unsupported model: {model_id}") | ||
|
||
self.tokenizer = tiktoken.get_encoding("cl100k_base") | ||
|
||
self.name = model_id | ||
self.max_context_tokens = model_data.get("max_input_tokens") | ||
self.prompt_price = model_data.get("input_cost_per_token") * 100 | ||
self.completion_price = model_data.get("output_cost_per_token") * 100 | ||
|
||
is_high_end = model_id.startswith("gpt-4") or model_id.startswith("claude-3-opus") | ||
|
||
self.edit_format = "udiff" if is_high_end else "whole" | ||
self.use_repo_map = is_high_end | ||
self.send_undo_reply = is_high_end | ||
|
||
# set the history token limit | ||
if self.max_context_tokens < 32 * 1024: | ||
self.max_chat_history_tokens = 1024 | ||
else: | ||
self.max_chat_history_tokens = 2 * 1024 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nkeilar please try setting
LITELLM_BASE_URL
environment variable and let me know if that works for you