Skip to content

Commit

Permalink
Merge pull request #29 from FrancescoCaracciolo/nyarch-sync-0.5.5
Browse files Browse the repository at this point in the history
Nyarch sync 0.5.5
  • Loading branch information
FrancescoCaracciolo authored Jan 1, 2025
2 parents 165126d + 6f25f5d commit 94e7a76
Show file tree
Hide file tree
Showing 15 changed files with 1,072 additions and 205 deletions.
70 changes: 65 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,50 @@ Nyarch Assistant supports extensions to enhance its functionality. You can eithe

# Installation

![builder](https://raw.githubusercontent.com/qwersyk/Assets/main/builder.svg#gh-light-mode-only)
![builder](https://raw.githubusercontent.com/qwersyk/Assets/main/builder-dark.svg#gh-dark-mode-only)
<a href="https://github.com/qwersyk/Newelle/archive/refs/heads/master.zip">
<picture>
<source srcset="https://raw.githubusercontent.com/qwersyk/Assets/main/builder.svg" media="(prefers-color-scheme: light)">
<source srcset="https://raw.githubusercontent.com/qwersyk/Assets/main/builder-dark.svg" media="(prefers-color-scheme: dark)">
<img src="https://raw.githubusercontent.com/qwersyk/Assets/main/builder.svg" alt="builder">
</picture>
</a>

1. Install GNOME Builder on your system.
2. Clone the nyarchassistant repository from GitHub.
3. Open the project in GNOME Builder and compile it.
4. Once compiled, you can run the program from the compiled executable.

![beta](https://raw.githubusercontent.com/qwersyk/Assets/main/beta.svg#gh-light-mode-only)
![beta](https://raw.githubusercontent.com/qwersyk/Assets/main/beta-dark.svg#gh-dark-mode-only)
<a href="https://github.com/qwersyk/Newelle/actions">
<picture>
<source srcset="https://raw.githubusercontent.com/qwersyk/Assets/main/beta.svg" media="(prefers-color-scheme: light)">
<source srcset="https://raw.githubusercontent.com/qwersyk/Assets/main/beta-dark.svg" media="(prefers-color-scheme: dark)">
<img src="https://raw.githubusercontent.com/qwersyk/Assets/main/beta.svg" alt="beta">
</picture>
</a>

1. Download the latest release from the [Github Actions](https://github.com/nyarchlinux/nyarchassistant/actions)
2. Extract the downloaded package.
3. Install a flatpak package.

<<<<<<< HEAD
<a href="https://flathub.org/apps/io.github.qwersyk.Newelle">
<picture>
<source srcset="https://raw.githubusercontent.com/qwersyk/Assets/main/flathub.svg" media="(prefers-color-scheme: light)">
<source srcset="https://raw.githubusercontent.com/qwersyk/Assets/main/flathub-dark.svg" media="(prefers-color-scheme: dark)">
<img src="https://raw.githubusercontent.com/qwersyk/Assets/main/flathub.svg" alt="flathub">
</picture>
</a>

1. Ensure you have Flatpak installed on your system.
2. Install Newelle by executing: `flatpak install flathub io.github.qwersyk.Newelle`

# Permission

> [!IMPORTANT]
> The Flathub version of Newelle is restricted to the `.var/app/io.github.qwersyk.Newelle` folder and operates within a
> Flatpak virtualized environment, limiting its capabilities.
=======
# Permission

To extend functionality, you can either temporarily grant access with:
Expand All @@ -60,4 +89,35 @@ or adjust settings permanently using Flatseal:
- Open Flatseal, find "nyarchassistant," enable "All user files" and "Session Bus," and add `org.freedesktop.Flatpak` to run outside the sandbox.

> [!WARNING]
> Be cautious when enabling these options. They reduce security by exposing your data and terminal. Avoid sharing personal information, and understand that we can't guarantee the privacy of your chat data or prevent potential risks from proprietary models.
> Be cautious when enabling these options. They reduce security by exposing your data and terminal. Avoid sharing
> personal information, and understand that we can't guarantee the privacy of your chat data or prevent potential risks
> from proprietary models.
# Alternative Versions

<a href="https://github.com/qwersyk/Newelle/tree/aarch64">
<picture>
<source srcset="https://raw.githubusercontent.com/qwersyk/Assets/main/aarch64.svg" media="(prefers-color-scheme: light)">
<source srcset="https://raw.githubusercontent.com/qwersyk/Assets/main/aarch64-dark.svg" media="(prefers-color-scheme: dark)">
<img src="https://raw.githubusercontent.com/qwersyk/Assets/main/aarch64.svg" alt="aarch64">
</picture>
</a>


**[Newelle Lite](https://github.com/qwersyk/Newelle/tree/aarch64)** - Your Virtual Assistant for aarch64

<a href="https://github.com/NyarchLinux/NyarchAssistant">
<picture>
<source srcset="https://raw.githubusercontent.com/qwersyk/Assets/main/nyarch.svg" media="(prefers-color-scheme: light)">
<source srcset="https://raw.githubusercontent.com/qwersyk/Assets/main/nyarch-dark.svg" media="(prefers-color-scheme: dark)">
<img src="https://raw.githubusercontent.com/qwersyk/Assets/main/nyarch.svg" alt="nyarch">
</picture>
</a>

**[Nyarch Assistant](https://github.com/NyarchLinux/NyarchAssistant)** - Your ultimate Waifu AI Assistant

<picture>
<source srcset="https://raw.githubusercontent.com/NyarchLinux/NyarchAssistant/refs/heads/master/screenshots/1w.png" media="(prefers-color-scheme: light)">
<source srcset="https://raw.githubusercontent.com/NyarchLinux/NyarchAssistant/refs/heads/master/screenshots/1b.png" media="(prefers-color-scheme: dark)">
<img src="https://raw.githubusercontent.com/NyarchLinux/NyarchAssistant/refs/heads/master/screenshots/1w.png" alt="screenshot">
</picture>
5 changes: 5 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,11 @@
<url type="bugtracker">https://github.com/nyarchlinux/nyarchassistant/issues</url>
<content_rating type="oars-1.0" />
<releases>
<release version="0.5.0" date="2024-12-27">
<description>
<p>Added new features and bug fixes</p>
</description>
</release>
<release version="0.4.2" date="2024-12-21">
<description>
<p>Added new features and bug fixes</p>
Expand Down
12 changes: 12 additions & 0 deletions data/moe.nyarchlinux.assistant.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
<key name="hidden-files" type="b">
<default>false</default>
</key>
<key name="reverse-order" type="b">
<default>false</default>
</key>
<key name="auto-generate-name" type="b">
<default>false</default>
</key>
<key name="path" type="s">
<default>"~"</default>
</key>
Expand Down Expand Up @@ -94,6 +100,12 @@
<key name="extensions-settings" type="s">
<default>"{}"</default>
</key>
<key name="profiles" type="s">
<default>"{}"</default>
</key>
<key name="current-profile" type="s">
<default>"Assistant"</default>
</key>
<key name="translator" type="s">
<default>"LibreTranslate"</default>
</key>
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.5.5',
version: '0.6.0',
meson_version: '>= 0.62.0',
default_options: [ 'warning_level=2', 'werror=false', ],
)
Expand Down
3 changes: 2 additions & 1 deletion moe.nyarchlinux.assistant.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"--socket=wayland",
"--talk-name=org.freedesktop.Flatpak",
"--filesystem=home",
"--socket=pulseaudio"
"--socket=pulseaudio",
"--talk-name=org.gnome.Shell.Screencast"
],
"cleanup" : [
"/include",
Expand Down
12 changes: 9 additions & 3 deletions src/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

from .llm import BingHandler, GPT4AllHandler, GroqHandler, NyarchApiHandler, OllamaHandler, OpenAIHandler, CustomLLMHandler, GPT3AnyHandler, GeminiHandler, MistralHandler, OpenRouterHandler
from .llm import BingHandler, ClaudeHandler, GPT4AllHandler, GroqHandler, NyarchApiHandler, OllamaHandler, OpenAIHandler, CustomLLMHandler, GPT3AnyHandler, GeminiHandler, MistralHandler, OpenRouterHandler
from .tts import VoiceVoxHanlder,ElevenLabs, gTTSHandler, EspeakHandler, CustomTTSHandler, VitsHandler, EdgeTTSHandler
from .stt import GroqSRHandler, OpenAISRHandler, SphinxHandler, GoogleSRHandler, WhisperHandler, WitAIHandler, VoskHandler, CustomSRHandler

Expand Down Expand Up @@ -46,7 +45,7 @@
"gemini": {
"key": "gemini",
"title": _("Google Gemini API"),
"description": "Official APIs for google gemini, requires an API Key",
"description": "Official APIs for Google Gemini, requires an API Key",
"class": GeminiHandler,
},
"openai": {
Expand All @@ -55,6 +54,13 @@
"description": _("OpenAI API"),
"class": OpenAIHandler,
},
"claude": {
"key": "claude",
"title": _("Anthropic Claude"),
"description": _("Official APIs for Anthropic Claude's models, with image and file support, requires an API key"),
"class": ClaudeHandler,
"secondary": True
},
"mistral": {
"key": "mistral",
"title": _("Mistral"),
Expand Down
84 changes: 80 additions & 4 deletions src/extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import os, sys
import xml.dom.minidom, html
import json
from gi.repository import GLib

import importlib, subprocess, functools


Expand Down Expand Up @@ -103,6 +105,27 @@ def get_desktop_environment() -> str:
desktop = "Unknown"
return desktop

def get_settings_dict(settings, blacklisted_keys:list = []):
"""
Return a dictionary containing all settings from a Gio.Settings object.
"""
settings_dict = {}
for key in settings.list_keys():
if key in blacklisted_keys:
continue
value = settings.get_value(key)
settings_dict[key] = value.unpack()
return settings_dict

def restore_settings_from_dict(settings, settings_dict):
"""
Restore settings from a dictionary into a Gio.Settings object.
"""
for key, value in settings_dict.items():
current_value = settings.get_value(key)
variant = GLib.Variant(current_value.get_type_string(), value)
settings.set_value(key, variant)

def get_spawn_command() -> list:
"""
Get the spawn command to run commands on the user system
Expand Down Expand Up @@ -197,10 +220,25 @@ def convert_history_openai(history: list, prompts: list, vision_support : bool =
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")
return "data:image/jpeg;base64," + encoded_string

def encode_image_base64(file_path):
mime_types = {
'.jpg': 'image/jpeg',
'.jpeg': 'image/jpeg',
'.png': 'image/png',
'.webp': 'image/webp',
'.mp4': 'video/mp4',
'.avi': 'video/x-msvideo',
'.mov': 'video/quicktime'
}

ext = os.path.splitext(file_path)[1].lower()
mime_type = mime_types.get(ext, 'image/jpeg')

with open(file_path, "rb") as file:
encoded = base64.b64encode(file.read()).decode("utf-8")

return f"data:{mime_type};base64,{encoded}"

def extract_image(message: str) -> tuple[str | None, str]:
"""
Expand All @@ -221,6 +259,44 @@ def extract_image(message: str) -> tuple[str | None, str]:
text = message
return img, text

def extract_video(message: str) -> tuple[str | None, str]:
"""
Extract video from message
Args:
message: message string
Returns:
tuple[str, str]: image and text, if no image, image is None
"""
img = None
if message.startswith("```video"):
img = message.split("\n")[1]
text = message.split("\n")[3:]
text = "\n".join(text)
else:
text = message
return img, text

def extract_file(message: str) -> tuple[str | None, str]:
"""
Extract file from message
Args:
message: message string
Returns:
tuple[str, str]: file and text, if no file, file is None
"""
file = None
if message.startswith("```file"):
file = message.split("\n")[1]
text = message.split("\n")[3:]
text = "\n".join(text)
else:
text = message
return file, text

def quote_string(s):
if "'" in s:
return "'" + s.replace("'", "'\\''") + "'"
Expand Down
54 changes: 54 additions & 0 deletions src/gtkobj.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Callable
import gi, os, subprocess

from gi.repository import Gtk, Pango, Gio, Gdk, GtkSource, GObject, Adw, GLib
Expand All @@ -16,6 +17,59 @@ def apply_css_to_widget(widget, css_string):
context.add_provider(provider, Gtk.STYLE_PROVIDER_PRIORITY_USER)


class ProfileRow(Adw.ActionRow):
def __init__(self, profile, picture, selected, add=False, allow_delete=False):
super().__init__(height_request=50, width_request=250, use_markup=False, activatable=False)
self.profile = profile
self.add = add
# Set properties
self.on_forget_f = lambda _: None
self.set_name(profile)
self.set_title(profile)
# Create prefix widget (GtkOverlay)
overlay = Gtk.Overlay(width_request=40)
self.add_prefix(overlay)

# Create avatar widget
if add:
avatar = Adw.Avatar(size=36, text=profile, icon_name="plus-symbolic")
elif picture is not None:
avatar = Adw.Avatar(custom_image=Gdk.Texture.new_from_filename(picture), text=profile, show_initials=True, size=36)
avatar.get_last_child().get_last_child().set_icon_size(Gtk.IconSize.NORMAL)
else:
avatar = Adw.Avatar(text=profile, show_initials=True, size=36)
avatar.set_tooltip_text(_("Select profile"))
# Signal handler for avatar clicked
overlay.add_overlay(avatar)

# Create checkmark widget
if selected:
checkmark = Gtk.Image(focusable=False, halign=Gtk.Align.END, valign=Gtk.Align.END)
checkmark.set_from_icon_name("check-plain-symbolic")
checkmark.set_pixel_size(11)
# Apply style to checkmark
checkmark.add_css_class("blue-checkmark")
overlay.add_overlay(checkmark)

if allow_delete:
# Create suffix widget (GtkButton)
forget_button = Gtk.Button()
forget_button.set_icon_name("user-trash-symbolic")
forget_button.set_valign(Gtk.Align.CENTER)
forget_button.set_tooltip_text("Delete Profile")
# Signal handler for forget button clicked
forget_button.connect("clicked", self.on_forget)
# Apply style to forget button
forget_button.add_css_class("circular")
self.add_suffix(forget_button)

def set_on_forget(self, f : Callable):
self.on_forget_f = f

def on_forget(self, widget):
self.on_forget_f(self.profile)


class File(Gtk.Image):
def __init__(self, path, file_name):
if os.path.isdir(os.path.join(os.path.expanduser(path), file_name)):
Expand Down
Loading

0 comments on commit 94e7a76

Please sign in to comment.