PluginAiOllama.py

changeset 16
cb6af351310b
parent 8
3118d16e526e
child 17
43b1396fe72f
equal deleted inserted replaced
15:c55270946c9a 16:cb6af351310b
7 Module implementing the ollama Interface plug-in. 7 Module implementing the ollama Interface plug-in.
8 """ 8 """
9 9
10 import os 10 import os
11 11
12 from PyQt6.QtCore import QObject, Qt, QTranslator, pyqtSignal 12 from PyQt6.QtCore import QCoreApplication, QObject, Qt, QTranslator, pyqtSignal
13 from PyQt6.QtGui import QKeySequence 13 from PyQt6.QtGui import QKeySequence
14 14
15 from eric7 import Globals, Preferences 15 from eric7 import Globals, Preferences
16 from eric7.EricGui import EricPixmapCache 16 from eric7.EricGui import EricPixmapCache
17 from eric7.EricGui.EricAction import EricAction 17 from eric7.EricGui.EricAction import EricAction
48 error = "" # noqa: U200 48 error = "" # noqa: U200
49 49
50 ollamaInterfacePluginObject = None 50 ollamaInterfacePluginObject = None
51 51
52 52
53 def pageCreationFunction(configDlg): 53 def createOllamaPage(_configDlg):
54 """ 54 """
55 Function to create the Translator configuration page. 55 Function to create the 'ollama' interface' configuration page.
56 56
57 @param configDlg reference to the configuration dialog 57 @param _configDlg reference to the configuration dialog
58 @type ConfigurationWidget 58 @type ConfigurationWidget
59 @return reference to the configuration page 59 @return reference to the configuration page
60 @rtype TranslatorPage 60 @rtype OllamaPage
61 """ 61 """
62 # TODO: not implemented yet 62 from OllamaInterface.ConfigurationPage.OllamaPage import OllamaPage
63 page = None # change this line to create the configuration page 63
64 global ollamaInterfacePluginObject
65
66 page = OllamaPage(ollamaInterfacePluginObject)
64 return page 67 return page
65 68
66 69
67 def getConfigData(): 70 def getConfigData():
68 """ 71 """
69 Function returning data as required by the configuration dialog. 72 Function returning data as required by the configuration dialog.
70 73
71 @return dictionary containing the relevant data 74 @return dictionary containing the relevant data
72 @rtype dict 75 @rtype dict
73 """ 76 """
74 # TODO: not implemented yet 77 usesDarkPalette = ericApp().usesDarkPalette()
78 iconSuffix = "dark" if usesDarkPalette else "light"
79
75 return { 80 return {
76 "<unique key>": [ 81 "ollamaPage": [
77 "<display string>", 82 QCoreApplication.translate(
78 "<pixmap filename>", 83 "PluginOllamaInterface", "ollama AI Interface"
79 pageCreationFunction, 84 ),
85 os.path.join("OllamaInterface", "icons", "ollama22-{0}".format(iconSuffix)),
86 createOllamaPage,
80 None, 87 None,
81 None, 88 None,
82 ], 89 ],
83 } 90 }
84 91
280 return Globals.toBool( 287 return Globals.toBool(
281 Preferences.Prefs.settings.value( 288 Preferences.Prefs.settings.value(
282 self.PreferencesKey + "/" + key, self.__defaults[key] 289 self.PreferencesKey + "/" + key, self.__defaults[key]
283 ) 290 )
284 ) 291 )
292 elif key in ("OllamaHost", "OllamaModelLibraryUrl"):
293 value = Preferences.Prefs.settings.value(
294 self.PreferencesKey + "/" + key, self.__defaults[key]
295 )
296 if not value:
297 # use default value if empty
298 value = self.__defaults[key]
299 return value
285 else: 300 else:
286 return Preferences.Prefs.settings.value( 301 return Preferences.Prefs.settings.value(
287 self.PreferencesKey + "/" + key, self.__defaults[key] 302 self.PreferencesKey + "/" + key, self.__defaults[key]
288 ) 303 )
289 304

eric ide

mercurial