Skip to content

Commit 4b07fe0

Browse files
committed
Have the default AI provider for text to text be Google
1 parent 26a88ba commit 4b07fe0

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/calibre/ai/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from qt.core import QComboBox, QDialog, QGroupBox, QHBoxLayout, QLabel, QStackedLayout, QVBoxLayout, QWidget
55

66
from calibre.ai import AICapabilities
7-
from calibre.ai.prefs import plugins_for_purpose, prefs
7+
from calibre.ai.prefs import plugin_for_purpose, plugins_for_purpose, prefs
88
from calibre.gui2 import Application, error_dialog
99

1010

@@ -31,7 +31,7 @@ def __init__(self, purpose: AICapabilities = AICapabilities.text_to_text, parent
3131
h.addWidget(la), h.addWidget(pcb), h.addStretch()
3232
v.addLayout(h)
3333
pcb.currentIndexChanged.connect(self.stack.setCurrentIndex)
34-
idx = pcb.findText(prefs()['purpose_map'].get(str(self.purpose), ''))
34+
idx = pcb.findText(getattr(plugin_for_purpose(self.purpose), 'name', ''))
3535
pcb.setCurrentIndex(max(0, idx))
3636
elif len(plugins) == 1:
3737
self.gb.setTitle(_('Configure AI provider: {}').format(plugins[0].name))

src/calibre/ai/prefs.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ def plugin_for_purpose(purpose: AICapabilities) -> AIProviderPlugin | None:
4747
if ans := compatible_plugins.get(q):
4848
return ans
4949
if compatible_plugins:
50+
from calibre.ai.google import GoogleAI
51+
# Prefer Google for text to text as it give us 1500 free web searches per day
52+
if purpose == AICapabilities.text_to_text:
53+
for name, p in compatible_plugins.items():
54+
if name == GoogleAI.name:
55+
return p
5056
return next(iter(compatible_plugins.values()))
5157
return None
5258

0 commit comments

Comments
 (0)