Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Newelle API #100

Merged
merged 7 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/io.github.qwersyk.Newelle.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<default>false</default>
</key>
<key name="language-model" type="s">
<default>"GPT3Any"</default>
<default>"newelle"</default>
</key>
<key name="local-model" type="s">
<default>""</default>
Expand Down
2 changes: 0 additions & 2 deletions io.github.qwersyk.Newelle.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@

"modules/python3-requests.json",
"modules/python3-expandvars.json",
"modules/python3-g4f.json",
"modules/python3-gpt4all.json",
"modules/python3-gtts.json",
"modules/python3-pip.json",
"modules/portaudio.json",
"modules/python3-pyaudio.json",
"modules/python3-speechrecognition.json",
"modules/python3-openai.json",
"modules/python3-pygame.json",
{
"name" : "newelle",
Expand Down
12 changes: 0 additions & 12 deletions modules/python3-g4f.json

This file was deleted.

12 changes: 0 additions & 12 deletions modules/python3-openai.json

This file was deleted.

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
Expand Up @@ -3,9 +3,8 @@ expandvars
curl_cffi
pillow
g4f==0.3.3.3
gpt4all
gtts
pyaudio
speechrecognition
openai
pygame
pygame
9 changes: 8 additions & 1 deletion src/constants.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@

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

AVAILABLE_LLMS = {
"newelle": {
"key": "newelle",
"title": _("Newelle Demo API"),
"description": "Newelle Demo API, limited to 10 requests per day, demo purposes only",
"class": NewelleAPIHandler,
},
"GPT3Any": {
"key": "GPT3Any",
"title": _("Any free Provider"),
"description": "Automatically chooses a free provider using a GPT3.5-Turbo or better model",
"class": GPT3AnyHandler,
"secondary": True,
},
"local": {
"key": "local",
Expand Down
4 changes: 3 additions & 1 deletion src/extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,11 @@ def convert_history_openai(history: list, prompts: list, vision_support : bool =
"role": "user" if message["User"] == "User" else "assistant",
"content": message["Message"]
})
print(result)
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
23 changes: 19 additions & 4 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 @@ -57,18 +61,21 @@ def is_installed(self) -> bool:
return False
return True

def get_setting(self, key: str) -> Any:
def get_setting(self, key: str, search_default = 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.
Returns:
object: value of the setting
"""
j = json.loads(self.settings.get_string(self.schema_key))
if self.key not in j or key not in j[self.key]:
return self.get_default_setting(key)
if search_default:
return self.get_default_setting(key)
else:
return None
return j[self.key][key]

def set_setting(self, key : str, value):
Expand Down Expand Up @@ -99,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