dynamically get pricing and context length for openrouter models

This commit is contained in:
JV 2023-08-15 04:04:02 +12:00 committed by Joshua Vial
parent 041f3a4a38
commit a0d6efc13c
2 changed files with 11 additions and 2 deletions

View file

@ -901,6 +901,5 @@ class Coder:
def check_model_availability(main_model):
available_models = openai.Model.list()
print(available_models)
model_ids = [model.id for model in available_models["data"]]
return main_model.name in model_ids

View file

@ -7,7 +7,17 @@ class OpenRouterModel(Model):
self.name = name
self.edit_format = "diff"
self.use_repo_map = True
self.max_context_tokens = 1024 * 8
# TODO: figure out proper encodings for non openai models
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}')