2727
2828@Gtk .Template (resource_path = '/com/jeffser/Alpaca/window.ui' )
2929class AlpacaWindow (Adw .ApplicationWindow ):
30+ config_dir = os .path .join (os .getenv ("XDG_CONFIG_HOME" ), "/" , os .path .expanduser ("~/.var/app/com.jeffser.Alpaca/config" ))
3031 __gtype_name__ = 'AlpacaWindow'
31-
3232 #Variables
3333 ollama_url = None
3434 local_models = []
@@ -106,7 +106,7 @@ def verify_connection(self):
106106 response = simple_get (self .ollama_url )
107107 if response ['status' ] == 'ok' :
108108 if "Ollama is running" in response ['text' ]:
109- with open ("server.conf" , "w+" ) as f : f .write (self .ollama_url )
109+ with open (os . path . join ( self . config_dir , "server.conf" ) , "w+" ) as f : f .write (self .ollama_url )
110110 self .message_entry .grab_focus_without_selecting ()
111111 self .update_list_local_models ()
112112 return True
@@ -320,14 +320,14 @@ def clear_conversation_dialog(self):
320320 )
321321
322322 def save_history (self ):
323- with open ("chats.json" , "w+" ) as f :
323+ with open (os . path . join ( self . config_dir , "chats.json" ) , "w+" ) as f :
324324 json .dump (self .chats , f , indent = 4 )
325325
326326 def load_history (self ):
327- if os .path .exists ("chats.json" ):
327+ if os .path .exists (os . path . join ( self . config_dir , "chats.json" ) ):
328328 self .clear_conversation ()
329329 try :
330- with open ("chats.json" , "r" ) as f :
330+ with open (os . path . join ( self . config_dir , "chats.json" ) , "r" ) as f :
331331 self .chats = json .load (f )
332332 except Exception as e :
333333 self .chats = {"chats" : {"0" : {"messages" : []}}}
@@ -350,8 +350,8 @@ def __init__(self, **kwargs):
350350 self .connection_url_entry .connect ("changed" , lambda entry : entry .set_css_classes ([]))
351351 self .connection_dialog .connect ("close-attempt" , lambda dialog : self .destroy ())
352352 self .load_history ()
353- if os .path .exists ("server.conf" ):
354- with open ("server.conf" , "r" ) as f :
353+ if os .path .exists (os . path . join ( self . config_dir , "server.conf" ) ):
354+ with open (os . path . join ( self . config_dir , "server.conf" ) , "r" ) as f :
355355 self .ollama_url = f .read ()
356356 if self .verify_connection () is False : self .show_connection_dialog ()
357357 else : self .connection_dialog .present (self )
0 commit comments