Skip to content

Commit

Permalink
Fixed model tweaks loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffser committed May 30, 2024
1 parent a13ffd2 commit c994307
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 99 deletions.
25 changes: 0 additions & 25 deletions com.jeffser.Alpaca.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,31 +71,6 @@
}
]
},
{
"name": "ollama",
"buildsystem": "simple",
"build-commands": [
"install -Dm0755 ollama* ${FLATPAK_DEST}/bin/ollama"
],
"sources": [
{
"type": "file",
"url": "https://github.com/ollama/ollama/releases/download/v0.1.38/ollama-linux-amd64",
"sha256": "c3360812503a9756a507ebb9d78667e2b21800a760b45046bc48a8f3b81972f4",
"only-arches": [
"x86_64"
]
},
{
"type": "file",
"url": "https://github.com/ollama/ollama/releases/download/v0.1.38/ollama-linux-arm64",
"sha256": "f2d091afe665b2d5ba8b68e2473d36cdfaf80c61c7d2844a0a8f533c4e62f547",
"only-arches": [
"aarch64"
]
}
]
},
{
"name" : "alpaca",
"builddir" : true,
Expand Down
148 changes: 77 additions & 71 deletions src/alpaca_search_provider.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,83 +8,89 @@ DBUS_OBJECT_PATH = "/com/jeffser/Alpaca/SearchProvider"
DBUS_INTERFACE = "org.gnome.Shell.SearchProvider2"

class SearchProvider:
def __init__(self):
print("ALPACA __init__")
self.connection = Gio.bus_get_sync(Gio.BusType.SESSION, None)
self.connection.register_object(DBUS_OBJECT_PATH, self.get_interface_info(), None, self.handle_method_call, None)
def __init__(self):
print("ALPACA __init__")
self.connection = Gio.bus_get_sync(Gio.BusType.SESSION, None)
self.connection.register_object(DBUS_OBJECT_PATH, self.get_interface_info(), None, self.handle_method_call, None)

def get_interface_info(self):
print("ALPACA get_interface_info")
xml = """
<node>
<interface name='org.gnome.Shell.SearchProvider2'>
<method name='GetInitialResultSet'>
<arg type='as' name='terms' direction='in'/>
<arg type='as' name='results' direction='out'/>
</method>
<method name='GetSubsearchResultSet'>
<arg type='as' name='previous_results' direction='in'/>
<arg type='as' name='terms' direction='in'/>
<arg type='as' name='results' direction='out'/>
</method>
<method name='GetResultMetas'>
<arg type='as' name='identifiers' direction='in'/>
<arg type='a{sv}' name='metas' direction='out'/>
</method>
<method name='ActivateResult'>
<arg type='s' name='identifier' direction='in'/>
<arg type='as' name='terms' direction='in'/>
<arg type='i' name='timestamp' direction='in'/>
</method>
</interface>
</node>
"""
return Gio.DBusNodeInfo.new_for_xml(xml).interfaces[0]
def get_interface_info(self):
print("ALPACA get_interface_info")
xml = """
<node>
<interface name='org.gnome.Shell.SearchProvider2'>
<method name='GetInitialResultSet'>
<arg type='as' name='terms' direction='in'/>
<arg type='as' name='results' direction='out'/>
</method>
<method name='GetSubsearchResultSet'>
<arg type='as' name='previous_results' direction='in'/>
<arg type='as' name='terms' direction='in'/>
<arg type='as' name='results' direction='out'/>
</method>
<method name='GetResultMetas'>
<arg type='as' name='identifiers' direction='in'/>
<arg type='a{sv}' name='metas' direction='out'/>
</method>
<method name='ActivateResult'>
<arg type='s' name='identifier' direction='in'/>
<arg type='as' name='terms' direction='in'/>
<arg type='i' name='timestamp' direction='in'/>
</method>
</interface>
</node>
"""
return Gio.DBusNodeInfo.new_for_xml(xml).interfaces[0]

def handle_method_call(self, connection, sender, object_path, interface_name, method_name, parameters, invocation):
print("ALPACA handle_method_call")
if method_name == "GetInitialResultSet":
self.handle_get_initial_result_set(invocation, parameters)
elif method_name == "GetSubsearchResultSet":
self.handle_get_subsearch_result_set(invocation, parameters)
elif method_name == "GetResultMetas":
self.handle_get_result_metas(invocation, parameters)
elif method_name == "ActivateResult":
self.handle_activate_result(invocation, parameters)
def handle_method_call(self, connection, sender, object_path, interface_name, method_name, parameters, invocation):
print(f"ALPACA handle_method_call: {method_name}")
if method_name == "GetInitialResultSet":
self.handle_get_initial_result_set(invocation, parameters)
elif method_name == "GetSubsearchResultSet":
self.handle_get_subsearch_result_set(invocation, parameters)
elif method_name == "GetResultMetas":
self.handle_get_result_metas(invocation, parameters)
elif method_name == "ActivateResult":
self.handle_activate_result(invocation, parameters)

def handle_get_initial_result_set(self, invocation, parameters):
print("ALPACA handle_get_initial_result_set")
terms = parameters.unpack()[0]
print(f"Initial search terms: {terms}")
results = ["result1", "result2"]
invocation.return_value(GLib.Variant("(as)", [results]))
def handle_get_initial_result_set(self, invocation, parameters):
print("ALPACA handle_get_initial_result_set")
terms = parameters.unpack()[0]
print(f"Initial search terms: {terms}")
results = []
if "Alpaca" in terms:
results.append("placeholder_result")
print(f"Returning results: {results}")
invocation.return_value(GLib.Variant("(as)", [results]))

def handle_get_subsearch_result_set(self, invocation, parameters):
print("ALPACA handle_get_subsearch_result_set")
previous_results, terms = parameters.unpack()
print(f"Subsearch terms: {terms}, previous results: {previous_results}")
results = ["result3", "result4"]
invocation.return_value(GLib.Variant("(as)", [results]))
def handle_get_subsearch_result_set(self, invocation, parameters):
print("ALPACA handle_get_subsearch_result_set")
previous_results, terms = parameters.unpack()
print(f"Subsearch terms: {terms}, previous results: {previous_results}")
results = []
if "Alpaca" in terms:
results.append("sub_placeholder_result")
print(f"Returning subsearch results: {results}")
invocation.return_value(GLib.Variant("(as)", [results]))

def handle_get_result_metas(self, invocation, parameters):
print("ALPACA handle_get_result_metas")
identifiers = parameters.unpack()[0] #LINE 66
print(f"Result metas for identifiers: {identifiers}")
metas = []
for identifier in identifiers:
meta = {"name": GLib.Variant("s", identifier)}
metas.append(GLib.Variant("a{sv}", meta))
invocation.return_value(GLib.Variant("(a{sv})", [metas]))
def handle_get_result_metas(self, invocation, parameters):
print("ALPACA handle_get_result_metas")
identifiers = parameters.unpack()[0]
print(f"Result metas for identifiers: {identifiers}")
metas = []
for identifier in identifiers:
meta = {"name": GLib.Variant("s", "Placeholder result for " + identifier)}
metas.append(GLib.Variant("a{sv}", meta))
print(f"Returning metas: {metas}")
invocation.return_value(GLib.Variant("(a{sv})", [metas]))


def handle_activate_result(self, invocation, parameters):
print("ALPACA handle_activate_result")
identifier, terms, timestamp = parameters.unpack()
print(f"Activated result: {identifier}, terms: {terms}, timestamp: {timestamp}")
invocation.return_value(None)
def handle_activate_result(self, invocation, parameters):
print("ALPACA handle_activate_result")
identifier, terms, timestamp = parameters.unpack()
print(f"Activated result: {identifier}, terms: {terms}, timestamp: {timestamp}")
invocation.return_value(None)

if __name__ == "__main__":
provider = SearchProvider()
loop = GLib.MainLoop()
loop.run()
provider = SearchProvider()
loop = GLib.MainLoop()
loop.run()

6 changes: 3 additions & 3 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,9 +920,9 @@ def __init__(self, **kwargs):
self.run_on_background = data['run_on_background']
#Model Tweaks
if "model_tweaks" in data: self.model_tweaks = data['model_tweaks']
self.temperature_spin.set_value(self.model_tweaks['model_tweaks']['temperature'])
self.seed_spin.set_value(self.model_tweaks['model_tweaks']['seed'])
self.keep_alive_spin.set_value(self.model_tweaks['model_tweaks']['keep_alive'])
self.temperature_spin.set_value(self.model_tweaks['temperature'])
self.seed_spin.set_value(self.model_tweaks['seed'])
self.keep_alive_spin.set_value(self.model_tweaks['keep_alive'])

self.background_switch.set_active(self.run_on_background)
self.set_hide_on_close(self.run_on_background)
Expand Down

0 comments on commit c994307

Please sign in to comment.