From dbae27d9acb1f67f1c2b5a17362952ef87b680a6 Mon Sep 17 00:00:00 2001 From: bishoy-at-pieces Date: Wed, 11 Dec 2024 23:56:58 +0200 Subject: [PATCH 1/2] feat: add failed phantom --- Pieces.sublime-settings | 2 +- copilot/__init__.py | 2 +- copilot/ask_command.py | 10 +++++++++- copilot/ask_view.py | 35 +++++++++++++++++++++++++++++++---- 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/Pieces.sublime-settings b/Pieces.sublime-settings index fb7145d..2cbb204 100644 --- a/Pieces.sublime-settings +++ b/Pieces.sublime-settings @@ -17,7 +17,7 @@ // "NeuralHermes-2.5-Mistral-7B GPU Chat Model", // "(PaLM2) Chat Model", // "Llama2 CPU Chat Model" - "auto_start_pieces_os":false, // Open PiecesOS automatically on startup + "auto_start_pieces_os":true, // Open PiecesOS automatically on startup "snippet.autocomplete":true, // auto complete via Pieces saved snippets or not "syntax" : {} // Langauge extension : syntax path } \ No newline at end of file diff --git a/copilot/__init__.py b/copilot/__init__.py index 5187839..5651787 100644 --- a/copilot/__init__.py +++ b/copilot/__init__.py @@ -1,4 +1,4 @@ -from .ask_command import PiecesAskStreamCommand,PiecesEnterResponseCommand,PiecesInsertTextCommand +from .ask_command import PiecesAskStreamCommand,PiecesEnterResponseCommand,PiecesInsertTextCommand,PiecesClearLineCommand from .explain import PiecesExplainCommand from .context_manager import PiecesContextManagerCommand from .ask_about_command import PiecesAskStreamAboutCommand diff --git a/copilot/ask_command.py b/copilot/ask_command.py index d5b65b9..83de042 100644 --- a/copilot/ask_command.py +++ b/copilot/ask_command.py @@ -80,4 +80,12 @@ def run(self,edit,text,point=None): self.view.window().focus_view(self.view) if not point: point = self.view.sel()[0].begin() - self.view.insert(edit,point,text) \ No newline at end of file + self.view.insert(edit,point,text) + + +class PiecesClearLineCommand(sublime_plugin.TextCommand): + def run(self, edit: sublime.Edit, line_point: int): + self.view.replace(edit,self.view.line(line_point), "") + + + diff --git a/copilot/ask_view.py b/copilot/ask_view.py index ec981f6..fd51ed2 100644 --- a/copilot/ask_view.py +++ b/copilot/ask_view.py @@ -19,6 +19,16 @@ """ +FAILED_PHANTOM_CONTENT = f""" +Something went wrong

+
+ Retry + Create a New Conversation + Create a GitHub Issue + Change current LLM +
+""" + class CopilotViewManager: def __init__(self): self._gpt_view = None @@ -134,6 +144,7 @@ def on_message_callback(self,message: QGPTStreamOutput): elif message.status == "FAILED": self.failed_regions.append(self.copilot_regions.pop()) self.show_failed() + self.gpt_view.run_command("pieces_clear_line",{"line_point": self.gpt_view.size()}) self.reset_view() if message.status != "IN-PROGRESS": @@ -148,9 +159,25 @@ def show_failed(self): flags=sublime.HIDDEN ) self.failed_phantom.update( - [sublime.Phantom(region,"Something went wrong",sublime.LAYOUT_BLOCK) for region in self.failed_regions] # TODO: Add retry + [sublime.Phantom(region,FAILED_PHANTOM_CONTENT,sublime.LAYOUT_BLOCK,self.on_nav_failed) for region in self.failed_regions] # TODO: Add retry ) + def on_nav_failed(self, href): + if href == "retry": + self.add_query(self.prev_query) + self.gpt_view.run_command("pieces_enter_response") + elif href == "create": + self.render_conversation("") # Render a new empty conversation + elif href == "github": + sublime.run_command("pieces_support",args={"support": "https://github.com/pieces-app/plugin_sublime/issues"}) + elif href == "llm": + sublime.active_window().run_command("edit_settings", + { + "base_file": f"{sublime.packages_path()}/Pieces/Pieces.sublime-settings", + "default": "\n{\n\t$0\n}\n" + } + ) + def add_context_phantom(self,region): self.context_phantom_region = region ui = sublime.ui_info()["theme"]["style"] @@ -188,8 +215,8 @@ def new_line(self,lines = 2) -> None: def ask(self,pipeline=None): - query = self.gpt_view.substr(Region(self.end_response,self.gpt_view.size())) - if not query.strip(): + self.prev_query = self.gpt_view.substr(Region(self.end_response,self.gpt_view.size())) + if not self.prev_query.strip(): return self.can_type = False self.select_end # got to the end of the text to enter the new lines @@ -197,7 +224,7 @@ def ask(self,pipeline=None): self.remove_context_phantom() self.add_role("Copilot") self.progress_bar.start() - sublime.set_timeout_async(lambda: PiecesSettings.api_client.copilot.stream_question(query,pipeline)) + sublime.set_timeout_async(lambda: PiecesSettings.api_client.copilot.stream_question(self.prev_query,pipeline)) def add_role(self,role): text = f'>>> **{role}**: ' From 502e4d1e1c53878fae31d8dc5b469097ffd06705 Mon Sep 17 00:00:00 2001 From: bishoy-at-pieces Date: Thu, 12 Dec 2024 16:29:32 +0200 Subject: [PATCH 2/2] run startup async to avoid freezing --- main.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index e59bb34..b456a16 100644 --- a/main.py +++ b/main.py @@ -47,17 +47,19 @@ def startup(): def plugin_loaded(): # Use the auth callback instead of the default one in the client PiecesSettings.api_client.user.on_user_callback = AuthUser.on_user_callback + sublime.set_timeout_async(run_async) + + +def run_async(): settings = PiecesSettings.get_settings() host = settings.get("host") - PiecesSettings.host_init(host) # Intilize the hosts url # callbacks needed onchange settings PiecesSettings.on_model_change_callbacks.append(copilot.update_status_bar) - health_ws = HealthWS(PiecesSettings.api_client, lambda x:startup()) health = PiecesSettings.api_client.is_pieces_running() if PiecesSettings.get_settings().get("auto_start_pieces_os"): health = PiecesSettings.api_client.open_pieces_os() - + health_ws = HealthWS(PiecesSettings.api_client, lambda x:startup()) if health: health_ws.start() else: