Skip to content

Commit

Permalink
Merge pull request #24 from FrancescoCaracciolo/nyarch-sync-0.4.5
Browse files Browse the repository at this point in the history
Nyarch sync 0.4.5
  • Loading branch information
FrancescoCaracciolo authored Nov 16, 2024
2 parents 4ed8ffd + f9cf175 commit d7219ed
Show file tree
Hide file tree
Showing 12 changed files with 299 additions and 127 deletions.
6 changes: 6 additions & 0 deletions data/icons/info-outline-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions data/icons/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ symbolic_dir = join_paths(get_option('datadir'), 'icons/hicolor/symbolic/apps')
install_data (
'internet-symbolic.svg',
'attach-symbolic.svg',
'info-outline-symbolic.svg',
install_dir: symbolic_dir
)
install_data (
Expand Down
10 changes: 10 additions & 0 deletions data/moe.nyarchlinux.assistant.appdata.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@
<url type="bugtracker">https://github.com/qwersyk/nyarchassistant/issues</url>
<content_rating type="oars-1.0" />
<releases>
<release version="0.4.1" date="2024-11-16">
<description>
<p>Updated the g4f library with versioning, added user guides, improved extension browsing, and enhanced model handling.</p>
</description>
</release>
<release version="0.4.0" date="2024-11-02">
<description>
<p>Bug fixes and new features have been implemented. We've modified the extension architecture, added new models, and introduced vision support, along with more capabilities.</p>
</description>
</release>
<release version="0.3.1" date="2024-09-28">
<description>
<p>Bug fixes</p>
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
project('nyarchassistant',
version: '0.4.4',
version: '0.4.5',
meson_version: '>= 0.62.0',
default_options: [ 'warning_level=2', 'werror=false', ],
)
Expand Down
16 changes: 9 additions & 7 deletions modules/python3-pygame.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
"name": "python3-pygame",
"buildsystem": "simple",
"build-commands": [
"pip3 install --verbose --prefix=${FLATPAK_DEST} pygame"
"pip3 install --verbose --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"pygame\" --no-build-isolation"
],
"build-options": {
"build-args": [
"--share=network"
]
}
}
"sources": [
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/49/cc/08bba60f00541f62aaa252ce0cfbd60aebd04616c0b9574f755b583e45ae/pygame-2.6.1.tar.gz",
"sha256": "56fb02ead529cee00d415c3e007f75e0780c655909aaa8e8bf616ee09c9feb1f"
}
]
}
3 changes: 1 addition & 2 deletions modules/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
requests
pillow
g4f==0.3.3.4
requests-toolbelt
g4f
curl_cffi
gpt4all
g4f
gtts
expandvars
pyaudio
Expand Down
39 changes: 23 additions & 16 deletions src/extension.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import subprocess
from threading import Thread
import gi, os

from .extra import get_spawn_command

from .constants import AVAILABLE_LLMS, AVAILABLE_PROMPTS, AVAILABLE_STT, AVAILABLE_TTS, PROMPTS
from .settings import Settings
from .extensions import ExtensionLoader
Expand Down Expand Up @@ -75,7 +78,13 @@ def update(self):
row.add_suffix(invisible_icon)

settings.add_flatpak_waning_button(extension, row)
self.extensiongroup.add(row)
self.extensiongroup.add(row)
download_button = Gtk.Button(label=_("User guide to Extensions"), margin_top=10)
download_button.connect("clicked", lambda x : subprocess.Popen(get_spawn_command() + ["xdg-open", "https://github.com/qwersyk/Newelle/wiki/User-guide-to-Extensions"]))
self.main.append(download_button)
download_button = Gtk.Button(label=_("Download new Extensions"), margin_top=10)
download_button.connect("clicked", lambda x : subprocess.Popen(get_spawn_command() + ["xdg-open", "https://github.com/topics/newelle-extension"]))
self.main.append(download_button)
folder_button = Gtk.Button(label=_("Choose an extension"), css_classes=["suggested-action"], margin_top=10)
folder_button.connect("clicked", self.on_folder_button_clicked)
self.main.append(folder_button)
Expand All @@ -93,18 +102,17 @@ def delete_extension(self,widget):
self.update()

def on_folder_button_clicked(self, widget):
dialog = Gtk.FileChooserNative(transient_for=self.app.win, title=_("Add extension"), modal=True, action=Gtk.FileChooserAction.OPEN)
dialog.connect("response", self.process_folder)
dialog.show()

def process_folder(self, dialog, response):
if response != Gtk.ResponseType.ACCEPT:
dialog.destroy()
return False
filter = Gtk.FileFilter(name="Newelle Extensions", patterns=["*.py"])
dialog = Gtk.FileDialog(title="Import extension", modal=True, default_filter=filter)
dialog.open(self, None, self.process_folder)

file=dialog.get_file()
if file == None:
return True
def process_folder(self, dialog, result):
try:
file=dialog.open_finish(result)
except Exception as _:
return
if file is None:
return
file_path = file.get_path()
self.extensionloader.add_extension(file_path)
self.extensionloader.load_extensions()
Expand All @@ -118,12 +126,11 @@ def process_folder(self, dialog, response):
break

if os.path.basename(file_path) in self.extensionloader.filemap.values():
self.notification_block.add_toast(Adw.Toast(title=(_("Extension added. New extensions will run"))))
self.notification_block.add_toast(Adw.Toast(title="Extension added. New extensions will run"))
self.extensionloader.load_extensions()
self.update()
else:
self.notification_block.add_toast(Adw.Toast(title=_("This is not an extension or it is not correct")))
self.notification_block.add_toast(Adw.Toast(title="This is not an extension or it is not correct"))

dialog.destroy()
return False
return

17 changes: 14 additions & 3 deletions src/extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def get_spawn_command() -> list:
return ["flatpak-spawn", "--host"]
else:
return []

def get_image_base64(image_str: str):
"""
Get image string as base64 string, starting with data:/image/jpeg;base64,
Expand Down Expand Up @@ -192,6 +193,9 @@ def convert_history_openai(history: list, prompts: list, vision_support : bool =
})
return result

def open_website(website):
subprocess.Popen(get_spawn_command() + ["xdg-open", website])

def encode_image_base64(image_path):
with open(image_path, "rb") as image_file:
encoded_string = base64.b64encode(image_file.read()).decode("utf-8")
Expand Down Expand Up @@ -293,8 +297,8 @@ def find_module(full_module_name):
def install_module(module, path):
if find_module("pip") is None:
print("Downloading pip...")
subprocess.check_output(["bash", "-c", "wget https://bootstrap.pypa.io/get-pip.py && python get-pip.py"])
r = subprocess.run([sys.executable, "-m", "pip", "install", "--target", path, module], capture_output=False)
subprocess.check_output(["bash", "-c", "cd " + os.path.dirname(path) + " && wget https://bootstrap.pypa.io/get-pip.py && python get-pip.py"])
r = subprocess.run([sys.executable, "-m", "pip", "install","--target", path, "--upgrade", module], capture_output=False)
return r

def is_flatpak() -> bool:
Expand Down Expand Up @@ -322,7 +326,14 @@ def can_escape_sandbox() -> bool:
except subprocess.CalledProcessError as _:
return False
return True

def get_streaming_extra_setting():
return {
"key": "streaming",
"title": _("Message Streaming"),
"description": _("Gradually stream message output"),
"type": "toggle",
"default": True
}
def override_prompts(override_setting, PROMPTS):
prompt_list = {}
for prompt in PROMPTS:
Expand Down
16 changes: 14 additions & 2 deletions src/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Handler():
"""Handler for a module"""
key = ""
schema_key = ""

on_extra_settings_update = None
def __init__(self, settings, path):
self.settings = settings
self.path = path
Expand All @@ -24,6 +24,10 @@ def get_extra_settings(self) -> list:
- description: description for the setting
- default: default value for the setting
- type: What type of row to create, possible rows:
- button: runs a function when the button is pressed
- label: label of the button
- icon: icon of the button, if label is not provided
- callback: the function to run on press, first argument is the button
- entry: input text
- toggle: bool
- combo: for multiple choice
Expand Down Expand Up @@ -61,7 +65,7 @@ def get_setting(self, key: str, search_default: bool = True) -> Any:
"""Get a setting from the given key
Args:
key (str): key of the setting
search_default (bool, optional): if the default value should be searched. Defaults to True.
search_default (bool, optional): if the default value should be searched. Defaults to True.
Returns:
object: value of the setting
Expand Down Expand Up @@ -102,4 +106,12 @@ def get_default_setting(self, key) -> object:
return s["default"]
return None

def set_extra_settings_update(self, callback):
self.on_extra_settings_update = callback

def settings_update(self):
if self.on_extra_settings_update is not None:
try:
self.on_extra_settings_update("")
except Exception as e:
print(e)
Loading

0 comments on commit d7219ed

Please sign in to comment.