From 316287f24939d45167ed7af9025e49e374c8725e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 1 Sep 2025 10:56:09 +0530 Subject: [PATCH] Finish description of model widget --- src/calibre/ai/open_router/backend.py | 3 ++- src/calibre/ai/open_router/config.py | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/calibre/ai/open_router/backend.py b/src/calibre/ai/open_router/backend.py index a81b990827..71640a824f 100644 --- a/src/calibre/ai/open_router/backend.py +++ b/src/calibre/ai/open_router/backend.py @@ -105,6 +105,7 @@ class Pricing(NamedTuple): class Model(NamedTuple): name: str id: str + slug: str created: int description: str context_length: int @@ -126,7 +127,7 @@ class Model(NamedTuple): return Model( name=x['name'], id=x['id'], created=datetime.datetime.fromtimestamp(x['created'], datetime.timezone.utc), - description=x['description'], context_length=x['context_length'], + description=x['description'], context_length=x['context_length'], slug=x['canonical_slug'], parameters=tuple(x['supported_parameters']), pricing=Pricing.from_dict(x['pricing']), is_moderated=x['top_provider']['is_moderated'], tokenizer=arch['tokenizer'], capabilities=capabilities, diff --git a/src/calibre/ai/open_router/config.py b/src/calibre/ai/open_router/config.py index eee458dd75..e674e08252 100644 --- a/src/calibre/ai/open_router/config.py +++ b/src/calibre/ai/open_router/config.py @@ -13,6 +13,7 @@ from qt.core import ( QLabel, QLineEdit, QListView, + QLocale, QModelIndex, QPushButton, QSize, @@ -32,6 +33,7 @@ from calibre.customize.ui import available_ai_provider_plugins from calibre.ebooks.txt.processor import create_markdown_object from calibre.gui2 import Application, error_dialog, safe_open_url from calibre.gui2.widgets2 import Dialog +from calibre.utils.date import qt_from_dt from calibre.utils.icu import primary_sort_key pref = partial(pref_for_provider, OpenRouterAI.name) @@ -137,7 +139,6 @@ class ModelDetails(QTextBrowser): self.anchorClicked.connect(self.open_link) def show_model_details(self, m: 'AIModel'): - # we use output token price since there are typically more output than input tokens if m.pricing.is_free: price = f"{_('Free')}" else: @@ -149,11 +150,17 @@ class ModelDetails(QTextBrowser): if m.pricing.image: price += f'$ {m.pricing.image * 1e3:.2g}/K {_("input images")} ' md = create_markdown_object(extensions=()) + created = qt_from_dt(m.created).date() html = f'''

{_('Description')}

{md.convert(m.description)}

{_('Price')}

{price}

+

{_('Details')}

+

{_('Created:')} {QLocale.system().toString(created, QLocale.FormatType.ShortFormat)}
+ {_('Context length:')} {QLocale.system().toString(m.context_length)}
+ {_('See the model on')} OpenRouter.ai +

''' self.setText(html)