Skip to content

Commit

Permalink
Merge pull request #28 from FrancescoCaracciolo/nyarch-sync-0.5.1
Browse files Browse the repository at this point in the history
Nyarch sync 0.5.1
  • Loading branch information
FrancescoCaracciolo authored Dec 27, 2024
2 parents fffe37d + 610f054 commit a63a5fb
Show file tree
Hide file tree
Showing 16 changed files with 690 additions and 90 deletions.
2 changes: 2 additions & 0 deletions data/icons/check-plain-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions data/icons/circle-crossed-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions data/icons/document-edit-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions data/icons/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ install_data(
symbolic_dir = join_paths(get_option('datadir'), 'icons/hicolor/symbolic/apps')
install_data (
'internet-symbolic.svg',
'plus-symbolic.svg',
'attach-symbolic.svg',
'circle-crossed-symbolic.svg',
'check-plain-symbolic.svg',
'user-trash-symbolic.svg',
'info-outline-symbolic.svg',
'document-edit-symbolic.svg',
install_dir: symbolic_dir
)
install_data (
Expand Down
2 changes: 2 additions & 0 deletions data/icons/plus-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions data/icons/user-trash-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.4.2" date="2024-12-21">
<description>
<p>Added new features and bug fixes</p>
</description>
</release>
<release version="0.4.1" date="2024-11-16">
<description>
Updated the g4f library with versioning, added user guides, improved extension browsing, and enhanced model handling.
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.0',
version: '0.5.5',
meson_version: '>= 0.62.0',
default_options: [ 'warning_level=2', 'werror=false', ],
)
Expand Down
2 changes: 1 addition & 1 deletion modules/python3-openai.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "python3-openai",
"buildsystem": "simple",
"build-commands": [
"pip3 install --verbose --prefix=${FLATPAK_DEST} openai==1.41.0"
"pip3 install --verbose --prefix=${FLATPAK_DEST} openai==1.58.1"
],
"build-options": {
"build-args": [
Expand Down
1 change: 1 addition & 0 deletions moe.nyarchlinux.assistant.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"*.la",
"*.a"
],

"modules" : [
"modules/git.json",
"modules/python3-requests.json",
Expand Down
9 changes: 5 additions & 4 deletions src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,22 @@
"local": {
"key": "local",
"title": _("Local Model"),
"description": _("Run a LLM model locally, more privacy but slower"),
"description": _("NO GPU SUPPORT, USE OLLAMA INSTEAD. Run a LLM model locally, more privacy but slower"),
"class": GPT4AllHandler,
},
"ollama": {
"key": "ollama",
"title": _("Ollama Instance"),
"description": _("Easily run multiple LLM models on your own hardware"),
"class": OllamaHandler,
"website": "https://ollama.com/",
},
"groq": {
"key": "groq",
"title": _("Groq"),
"description": "Official Groq API",
"website": "https://console.groq.com/",
"description": "Groq.com Free and fast API using open source models. Suggested for free use.",
"class": GroqHandler,
"website": "https://console.groq.com/",
},
"gemini": {
"key": "gemini",
Expand Down Expand Up @@ -283,7 +284,7 @@
Assistant: Hello, how can I assist you today?
User: Can you help me?
Assistant: Yes, of course, what do you need help with?""",
"get_suggestions_prompt": """Suggest a few questions that the user would ask and put them in a JSON array. You have to write ONLY the JSON array an nothing else""",
"get_suggestions_prompt": """Suggest a few questions that the user would ask and put them in a JSON array. You have to write ONLY the JSON array of strings an nothing else.""",
"custom_prompt": "",
"expression_prompt": """You can show expressions by writing (expression) in parenthesis.
You can ONLY show the following expressions:
Expand Down
76 changes: 76 additions & 0 deletions src/extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re, base64, io
import os, sys
import xml.dom.minidom, html
import json
import importlib, subprocess, functools


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

def get_streaming_extra_setting():
return {
"key": "streaming",
Expand All @@ -334,6 +336,7 @@ def get_streaming_extra_setting():
"type": "toggle",
"default": True
}

def override_prompts(override_setting, PROMPTS):
prompt_list = {}
for prompt in PROMPTS:
Expand All @@ -344,6 +347,79 @@ def override_prompts(override_setting, PROMPTS):
return prompt_list


def extract_json(input_string: str) -> str:
"""Extract JSON string from input string
Args:
input_string (): The input string
Returns:
str: The JSON string
"""
# Regular expression to find JSON objects or arrays
json_pattern = re.compile(r'\{.*?\}|\[.*?\]', re.DOTALL)

# Find all JSON-like substrings
matches = json_pattern.findall(input_string)
# Parse each match and return the first valid JSON
for match in matches:
try:
json_data = json.loads(match)
return match
except json.JSONDecodeError:
continue
print("Wrong JSON", input_string)
return []


def remove_markdown(text: str) -> str:
"""
Remove markdown from text
Args:
text: The text to remove markdown from
Returns:
str: The text without markdown
"""
# Remove headers
text = re.sub(r'^#{1,6}\s*', '', text, flags=re.MULTILINE)

# Remove emphasis (bold and italic)
text = re.sub(r'\*\*(.*?)\*\*', r'\1', text) # Bold
text = re.sub(r'__(.*?)__', r'\1', text) # Bold
text = re.sub(r'\*(.*?)\*', r'\1', text) # Italic
text = re.sub(r'_(.*?)_', r'\1', text) # Italic

# Remove inline code
text = re.sub(r'`([^`]*)`', r'\1', text)

# Remove code blocks
text = re.sub(r'```[\s\S]*?```', '', text)

# Remove links, keep the link text
text = re.sub(r'\[([^\]]+)\]\([^\)]+\)', r'\1', text)

# Remove images, keep the alt text
text = re.sub(r'!\[([^\]]*)\]\([^\)]+\)', r'\1', text)

# Remove strikethrough
text = re.sub(r'~~(.*?)~~', r'\1', text)

# Remove blockquotes
text = re.sub(r'^>\s*', '', text, flags=re.MULTILINE)

# Remove unordered list markers
text = re.sub(r'^\s*[-+*]\s+', '', text, flags=re.MULTILINE)

# Remove ordered list markers
text = re.sub(r'^\s*\d+\.\s+', '', text, flags=re.MULTILINE)

# Remove extra newlines
text = re.sub(r'\n{2,}', '\n', text)

return text.strip()

def force_async(fn):
'''
turns a sync function to async function using threads
Expand Down
24 changes: 23 additions & 1 deletion src/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,32 @@ def get_extra_settings(self) -> list:
- range: for number input with a slider
- min: minimum value
- max: maximum value
- round: how many digits to round
- round: how many digits to round
- nested: an expander row with nested extra settings
- extra_settings: list of extra_settings
- download: install something showing the downoad process
- is_installed: bool, true if the module is installed, false otherwise
- callback: the function to run on press to download/delete. The download must happen in sync
- download_percentage: callable that takes the key and returns the download percentage as float
Optional parameters:
- folder: add a button that opens a folder with the specified path
- website: add a button that opens a website with the specified path
- update_settings (bool) if reload the settings in the settings page for the specified handler after that setting change
- refresh (callable) adds a refresh button in the row to reload the settings in the settings page for the specified handler
- refresh_icon(str): name of the icon for the refresh button
"""
return []

def get_extra_settings_list(self) -> list:
"""Get the list of extra settings"""
res = []
for setting in self.get_extra_settings():
if setting["type"] == "nested":
res += setting["extra_settings"]
else:
res.append(setting)
return res

@staticmethod
def get_extra_requirements() -> list:
"""The list of extra pip requirements needed by the handler"""
Expand Down Expand Up @@ -102,6 +120,10 @@ def get_default_setting(self, key) -> object:
"""
extra_settings = self.get_extra_settings()
for s in extra_settings:
if s["type"] == "nested":
for setting in s["extra_settings"]:
if setting["key"] == key:
return setting["default"]
if s["key"] == key:
return s["default"]
return None
Expand Down
Loading

0 comments on commit a63a5fb

Please sign in to comment.