From 764cba5e276077aaf7c22bccb42ef59e2bb86530 Mon Sep 17 00:00:00 2001 From: 0xMRTT <0xMRTT@proton.me> Date: Sat, 6 May 2023 19:24:25 +0200 Subject: [PATCH] format: black --- src/main.py | 27 ++++++++------------ src/provider/baichat.py | 1 + src/provider/bard.py | 10 ++++---- src/provider/base.py | 14 +++++----- src/provider/catgpt.py | 1 + src/provider/hfgoogleflant5xxl.py | 2 +- src/provider/hfgoogleflanu12.py | 2 +- src/provider/hfgpt2.py | 2 +- src/provider/hfopenassistantsft1pythia12b.py | 2 +- src/provider/huggingface.py | 1 - src/provider/openai.py | 13 +++++++--- src/provider/openaigpt4.py | 2 +- 12 files changed, 39 insertions(+), 38 deletions(-) diff --git a/src/main.py b/src/main.py index af96f07..f1b7b80 100644 --- a/src/main.py +++ b/src/main.py @@ -41,6 +41,7 @@ from .provider import PROVIDERS import platform import os + class BavarderApplication(Adw.Application): """The main application singleton class.""" @@ -62,7 +63,9 @@ class BavarderApplication(Adw.Application): self.clear_after_send = self.settings.get_boolean("clear-after-send") - self.enabled_providers = sorted(set(self.settings.get_strv("enabled-providers"))) + self.enabled_providers = sorted( + set(self.settings.get_strv("enabled-providers")) + ) self.latest_provider = self.settings.get_string("latest-provider") def quitting(self, *args, **kwargs): @@ -84,10 +87,7 @@ class BavarderApplication(Adw.Application): for k, p in self.providers.items(): r[p.slug] = json.dumps(p.save()) print(r) - data = GLib.Variant( - "a{ss}", - r - ) + data = GLib.Variant("a{ss}", r) self.settings.set_value("providers-data", data) def get_provider(self): @@ -122,9 +122,7 @@ class BavarderApplication(Adw.Application): print("Loading provider", provider) self.provider_selector_model.append(PROVIDERS[provider].name) - self.providers[i] = PROVIDERS[provider]( - self.win, self - ) + self.providers[i] = PROVIDERS[provider](self.win, self) self.load() @@ -136,8 +134,8 @@ class BavarderApplication(Adw.Application): if p.slug == self.latest_provider: print("Setting selected provider to", k) self.win.provider_selector.set_selected(k) - break - + break + self.win.prompt_text_view.grab_focus() def load(self): @@ -145,10 +143,9 @@ class BavarderApplication(Adw.Application): print(self.providers_data) try: p.load(data=json.loads(self.providers_data[p.slug])) - except KeyError: # provider not in data + except KeyError: # provider not in data pass - def on_provider_selector_notify(self, _unused, pspec): self.win.banner.set_revealed(False) @@ -178,7 +175,6 @@ class BavarderApplication(Adw.Application): website="https://bavarder.codeberg.page", issue_url="https://github.com/Bavarder/Bavarder/issues", support_url="https://codeberg.org/Bavarder/Bavarder/issues", - copyright="© 2023 0xMRTT", ) @@ -196,7 +192,6 @@ Python: {platform.python_version()} OS: {platform.system()} {platform.release()} {platform.version()} Providers: {self.enabled_providers} """ - ) about.present() @@ -284,7 +279,7 @@ Providers: {self.enabled_providers} # def on_speak_action(self, widget, _): # """Callback for the app.speak action.""" # print("app.speak action activated") - # + # # try: # # with NamedTemporaryFile() as file_to_play: @@ -295,7 +290,7 @@ Providers: {self.enabled_providers} # self._play_audio(file_to_play.name) # except Exception as exc: # print(exc) - # + # # def _play_audio(self, path): # uri = "file://" + path # self.player.set_property("uri", uri) diff --git a/src/provider/baichat.py b/src/provider/baichat.py index 75a5202..9d041d5 100644 --- a/src/provider/baichat.py +++ b/src/provider/baichat.py @@ -5,6 +5,7 @@ import socket from gi.repository import Gtk, Adw, GLib + class BAIChatProvider(BavarderProvider): name = "BAI Chat" slug = "baichat" diff --git a/src/provider/bard.py b/src/provider/bard.py index 3795605..03f95c3 100644 --- a/src/provider/bard.py +++ b/src/provider/bard.py @@ -6,6 +6,7 @@ from googlebardpy import BardChat from gi.repository import Gtk, Adw, GLib + class BardProvider(BavarderProvider): name = "Bard" slug = "bard" @@ -44,8 +45,7 @@ class BardProvider(BavarderProvider): about_button.set_label("About") about_button.connect("clicked", self.about) about_button.set_valign(Gtk.Align.CENTER) - self.expander.add_action(about_button) # TODO: in Adw 1.4, use add_suffix - + self.expander.add_action(about_button) # TODO: in Adw 1.4, use add_suffix self.api_row = Adw.PasswordEntryRow() self.api_row.connect("apply", self.on_apply) @@ -81,13 +81,13 @@ class BardProvider(BavarderProvider): def save(self): try: return {"api_key": self.api_key} - except AttributeError: # no api key + except AttributeError: # no api key return {} def load(self, data): try: - self.chat = BardChat(data['api_key']) - self.api_key = data['api_key'] + self.chat = BardChat(data["api_key"]) + self.api_key = data["api_key"] except AttributeError: self.chat = None self.api_key = None diff --git a/src/provider/base.py b/src/provider/base.py index d0ac020..1dd9494 100644 --- a/src/provider/base.py +++ b/src/provider/base.py @@ -2,7 +2,9 @@ from gettext import gettext as _ from gi.repository import Gtk, Adw -import json +import json + + class BavarderProvider: name = None slug = None @@ -29,8 +31,8 @@ class BavarderProvider: if title: self.win.banner.props.title = title else: - self.win.banner.props.title = ( - _("No API key provided, you can provide one in settings") + self.win.banner.props.title = _( + "No API key provided, you can provide one in settings" ) self.win.banner.props.button_label = _("Open settings") self.win.banner.connect("button-clicked", self.app.on_preferences_action) @@ -57,8 +59,7 @@ class BavarderProvider: about_button.set_label("About") about_button.connect("clicked", self.about) about_button.set_valign(Gtk.Align.CENTER) - self.expander.add_action(about_button) # TODO: in Adw 1.4, use add_suffix - + self.expander.add_action(about_button) # TODO: in Adw 1.4, use add_suffix self.no_pref_row = Adw.ActionRow() self.no_pref_row.props.title = "No preferences available" @@ -75,6 +76,5 @@ class BavarderProvider: def chunk(self, prompt, n=4000): if len(prompt) > n: print("Chuncking prompt") - prompt = [(prompt[i:i+n]) for i in range(0, len(prompt), n)] + prompt = [(prompt[i : i + n]) for i in range(0, len(prompt), n)] return prompt - \ No newline at end of file diff --git a/src/provider/catgpt.py b/src/provider/catgpt.py index a542785..4c0648c 100644 --- a/src/provider/catgpt.py +++ b/src/provider/catgpt.py @@ -4,6 +4,7 @@ from random import choice, randint from gi.repository import Gtk, Adw, GLib + class CatGPTProvider(BavarderProvider): name = _("Cat GPT") slug = "catgpt" diff --git a/src/provider/hfgoogleflant5xxl.py b/src/provider/hfgoogleflant5xxl.py index d5208f8..cdb3952 100644 --- a/src/provider/hfgoogleflant5xxl.py +++ b/src/provider/hfgoogleflant5xxl.py @@ -8,4 +8,4 @@ class HuggingFaceGoogleFlanT5XXLProvider(BaseHFProvider): @property def require_api_key(self): - return False \ No newline at end of file + return False diff --git a/src/provider/hfgoogleflanu12.py b/src/provider/hfgoogleflanu12.py index 8c9e109..cc6b6df 100644 --- a/src/provider/hfgoogleflanu12.py +++ b/src/provider/hfgoogleflanu12.py @@ -8,4 +8,4 @@ class HuggingFaceGoogleFlanU12Provider(BaseHFProvider): @property def require_api_key(self): - return False \ No newline at end of file + return False diff --git a/src/provider/hfgpt2.py b/src/provider/hfgpt2.py index 14fbab1..3264673 100644 --- a/src/provider/hfgpt2.py +++ b/src/provider/hfgpt2.py @@ -8,4 +8,4 @@ class HuggingFaceGPT2Provider(BaseHFProvider): @property def require_api_key(self): - return False \ No newline at end of file + return False diff --git a/src/provider/hfopenassistantsft1pythia12b.py b/src/provider/hfopenassistantsft1pythia12b.py index 9e5465e..62d5f9a 100644 --- a/src/provider/hfopenassistantsft1pythia12b.py +++ b/src/provider/hfopenassistantsft1pythia12b.py @@ -8,4 +8,4 @@ class HuggingFaceOpenAssistantSFT1PythiaProvider(BaseHFProvider): @property def require_api_key(self): - return False \ No newline at end of file + return False diff --git a/src/provider/huggingface.py b/src/provider/huggingface.py index e7c06ae..8d2e141 100644 --- a/src/provider/huggingface.py +++ b/src/provider/huggingface.py @@ -94,4 +94,3 @@ class BaseHFProvider(BavarderProvider): def load(self, data): if self.require_api_key: self.api_key = data["api_key"] - diff --git a/src/provider/openai.py b/src/provider/openai.py index 7d35b67..c6717e6 100644 --- a/src/provider/openai.py +++ b/src/provider/openai.py @@ -27,9 +27,14 @@ class BaseOpenAIProvider(BavarderProvider): self.win.banner.set_revealed(True) response = "" for chunk in prompt: - response += self.chat.create( - model=self.model, messages=[{"role": "user", "content": chunk}] - ).choices[0].message.content + response += ( + self.chat.create( + model=self.model, + messages=[{"role": "user", "content": chunk}], + ) + .choices[0] + .message.content + ) else: response = self.chat.create( model=self.model, messages=[{"role": "user", "content": prompt}] @@ -70,7 +75,7 @@ class BaseOpenAIProvider(BavarderProvider): about_button.set_label("About") about_button.connect("clicked", self.about) about_button.set_valign(Gtk.Align.CENTER) - self.expander.add_action(about_button) # TODO: in Adw 1.4, use add_suffix + self.expander.add_action(about_button) # TODO: in Adw 1.4, use add_suffix self.api_row = Adw.PasswordEntryRow() self.api_row.connect("apply", self.on_apply) diff --git a/src/provider/openaigpt4.py b/src/provider/openaigpt4.py index c5db59f..30b7ee1 100644 --- a/src/provider/openaigpt4.py +++ b/src/provider/openaigpt4.py @@ -5,4 +5,4 @@ class OpenAIGPT4Provider(BaseOpenAIProvider): name = "OpenAI GPT 4" slug = "openaigpt4" model = "gpt-4" - api_key_title = "API Key (Require a plan with access to the GPT-4 model)" \ No newline at end of file + api_key_title = "API Key (Require a plan with access to the GPT-4 model)"