OllamaInterface/OllamaClient.py

changeset 7
eb1dec15b2f0
parent 5
6e8af43d537d
child 8
3118d16e526e
diff -r d8064fb63eac -r eb1dec15b2f0 OllamaInterface/OllamaClient.py
--- a/OllamaInterface/OllamaClient.py	Wed Aug 07 18:19:25 2024 +0200
+++ b/OllamaInterface/OllamaClient.py	Thu Aug 08 18:33:49 2024 +0200
@@ -95,12 +95,23 @@
         self.__heartbeatTimer.timeout.connect(self.__periodicHeartbeat)
 
         self.__state = OllamaClientState.Waiting
+        self.__localServer = False
 
         self.__serverResponding = False  # start with a faulty state
 
         self.__plugin.preferencesChanged.connect(self.__setHeartbeatTimer)
         self.__setHeartbeatTimer()
 
+    def setMode(self, local):
+        """
+        Public method to set the client mode to local.
+
+        @param local flag indicating to connect to a locally started ollama server
+        @type bool
+        """
+        self.__localServer = local
+        self.__serverResponding = False
+
     def chat(self, model, messages, streaming=True):
         """
         Public method to request a chat completion from the 'ollama' server.
@@ -353,8 +364,16 @@
         ollamaUrl = QUrl(
             "{0}://{1}:{2}/api/{3}".format(
                 self.__plugin.getPreferences("OllamaScheme"),
-                self.__plugin.getPreferences("OllamaHost"),
-                self.__plugin.getPreferences("OllamaPort"),
+                (
+                    "127.0.0.1"
+                    if self.__localServer
+                    else self.__plugin.getPreferences("OllamaHost")
+                ),
+                (
+                    self.__plugin.getPreferences("OllamaLocalPort")
+                    if self.__localServer
+                    else self.__plugin.getPreferences("OllamaPort")
+                ),
                 endpoint,
             )
         )

eric ide

mercurial