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

snippet refactor #85

Closed
wants to merge 2 commits into from
Closed
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
13 changes: 10 additions & 3 deletions GPT/gpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,20 @@ def gpt_apply_prompt(prompt: str, text_to_process: str | list[str]) -> str:
else text_to_process
)

# Ask is a special case, where the text to process is the prompted question, not the selected text
"""
Handle special prompts that require arbitrary text.

These prompts treat <user.text> as the source by setting
text_to_process to the natural language request.
"""

if prompt.startswith("ask"):
text_to_process = prompt.removeprefix("ask")
prompt = """Generate text that satisfies the question or request given in the input."""
# If the user is just moving the source to the destination, we don't need to apply a query
elif prompt.startswith("snip"):
text_to_process = prompt.removeprefix("snip")
prompt = "Please return the response as a textmate snippet for insertion into an editor with placeholders that the user should edit. Return just the snippet content - no XML and no heading."
elif prompt == "pass":
return text_to_process

Expand Down Expand Up @@ -220,8 +229,6 @@ def gpt_insert_response(
actions.user.tts(result)
except KeyError:
notify("GPT Failure: text to speech is not installed")
# Although we can insert to a cursorless dpestination, the cursorless_target capture
# Greatly increases DFA compliation times and should be avoided if possible
case "cursorless":
actions.user.cursorless_insert(cursorless_destination, result)
case "paste" | _:
Expand Down
3 changes: 2 additions & 1 deletion lib/talonSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

# model prompts can be either static and predefined by this repo or custom outside of it
@mod.capture(
rule="{user.staticPrompt} | {user.customPrompt} | (please <user.text>) | (ask <user.text>) | pass"
rule="{user.staticPrompt} | {user.customPrompt} | (please <user.text>) | (ask <user.text>) | snip <user.text> | pass"
)
def modelPrompt(matched_prompt) -> str:
return str(matched_prompt)
Expand All @@ -40,6 +40,7 @@ def modelPrompt(matched_prompt) -> str:
desc="The endpoint to send the model requests to",
)


mod.setting(
"model_system_prompt",
type=str,
Expand Down