mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 08:44:59 +00:00
dynamically get pricing and context length for openrouter models
This commit is contained in:
parent
041f3a4a38
commit
a0d6efc13c
2 changed files with 11 additions and 2 deletions
|
@ -901,6 +901,5 @@ class Coder:
|
||||||
|
|
||||||
def check_model_availability(main_model):
|
def check_model_availability(main_model):
|
||||||
available_models = openai.Model.list()
|
available_models = openai.Model.list()
|
||||||
print(available_models)
|
|
||||||
model_ids = [model.id for model in available_models["data"]]
|
model_ids = [model.id for model in available_models["data"]]
|
||||||
return main_model.name in model_ids
|
return main_model.name in model_ids
|
||||||
|
|
|
@ -7,7 +7,17 @@ class OpenRouterModel(Model):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.edit_format = "diff"
|
self.edit_format = "diff"
|
||||||
self.use_repo_map = True
|
self.use_repo_map = True
|
||||||
self.max_context_tokens = 1024 * 8
|
|
||||||
|
|
||||||
# TODO: figure out proper encodings for non openai models
|
# TODO: figure out proper encodings for non openai models
|
||||||
self.tokenizer = tiktoken.get_encoding("cl100k_base")
|
self.tokenizer = tiktoken.get_encoding("cl100k_base")
|
||||||
|
|
||||||
|
available_models = openai.Model.list().data
|
||||||
|
found = next((details for details in available_models if details.get('id') == name), None)
|
||||||
|
|
||||||
|
if found:
|
||||||
|
self.max_context_tokens = int(found.context_length)
|
||||||
|
self.prompt_price = float(found.get('pricing').get('prompt')) * 1000
|
||||||
|
self.completion_price = float(found.get('pricing').get('completion')) * 1000
|
||||||
|
|
||||||
|
else:
|
||||||
|
raise ValueError('invalid openrouter model for {name}')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue