Skip to content

Commit

Permalink
Split insertion destination case statement
Browse files Browse the repository at this point in the history
- since only some destination support images, it makes sense to handle them in a separate case
- this will now print an error message of someone tries to 'pass clip to window' with an image in their clipboard
  • Loading branch information
jaresty committed Aug 12, 2024
1 parent 4e37f63 commit a5407dd
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions GPT/gpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,21 @@ def gpt_insert_response(
# Skip inserting the response if the user is just viewing the thread in the window
actions.user.confirmation_gui_refresh_thread()

match method:
case "thread":
GPTState.push_thread(format_messages("user", [gpt_message]))
return
case "newThread":
GPTState.new_thread()
GPTState.push_thread(format_messages("user", [gpt_message]))
return

if gpt_message.get("type") != "text":
actions.app.notify(
f"Tried to insert an image to {method}, but that is not currently supported. To insert an image to this destination use a prompt to convert it to text."
)
return

message_text_no_images = extract_message(gpt_message)
match method:
case "above":
Expand All @@ -228,11 +243,6 @@ def gpt_insert_response(
case "newContext":
GPTState.clear_context()
GPTState.push_context(gpt_message)
case "thread":
GPTState.push_thread(format_messages("user", [gpt_message]))
case "newThread":
GPTState.new_thread()
GPTState.push_thread(format_messages("user", [gpt_message]))
case "appendClipboard":
if clip.text() is not None:
clip.set_text(clip.text() + "\n" + message_text_no_images) # type: ignore Unclear why this is throwing a type error in pylance
Expand Down

0 comments on commit a5407dd

Please sign in to comment.