update openrouter model to work with new openai client

This commit is contained in:
Joshua Vial 2023-12-11 20:50:02 +13:00
parent fe9423d7b8
commit b7d90197a9

View file

@ -21,13 +21,13 @@ class OpenRouterModel(Model):
if cached_model_details is None:
cached_model_details = client.models.list().data
found = next(
(details for details in cached_model_details if details.get("id") == name), None
(details for details in cached_model_details if details.id == name), None
)
if found:
self.max_context_tokens = int(found.get("context_length"))
self.prompt_price = round(float(found.get("pricing").get("prompt")) * 1000, 6)
self.completion_price = round(float(found.get("pricing").get("completion")) * 1000, 6)
self.max_context_tokens = int(found.context_length)
self.prompt_price = round(float(found.pricing.get("prompt")) * 1000, 6)
self.completion_price = round(float(found.pricing.get("completion")) * 1000, 6)
else:
raise ValueError(f"invalid openrouter model: {name}")