Skip to content

Commit

Permalink
Merge pull request #230 from pieces-app/add-failed-phantom
Browse files Browse the repository at this point in the history
feat: add failed phantom
  • Loading branch information
bishoy-at-pieces authored Dec 18, 2024
2 parents df55548 + 502e4d1 commit 78075a1
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Pieces.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion copilot/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 9 additions & 1 deletion copilot/ask_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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), "")



35 changes: 31 additions & 4 deletions copilot/ask_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
</div>
"""

FAILED_PHANTOM_CONTENT = f"""
Something went wrong <br><br>
<div style="padding-right:2px;padding-left:2px;padding-buttom:2px">
<a style="{PHANTOM_A_TAG_STYLE}" href = "retry">Retry</a>
<a style="{PHANTOM_A_TAG_STYLE}" href = "create">Create a New Conversation</a>
<a style="{PHANTOM_A_TAG_STYLE}" href = "github">Create a GitHub Issue</a>
<a style="{PHANTOM_A_TAG_STYLE}" href = "llm">Change current LLM</a>
</div>
"""

class CopilotViewManager:
def __init__(self):
self._gpt_view = None
Expand Down Expand Up @@ -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":
Expand All @@ -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"]
Expand Down Expand Up @@ -188,16 +215,16 @@ 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
self.new_line()
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}**: '
Expand Down
8 changes: 5 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 78075a1

Please sign in to comment.