Skip to content

Commit

Permalink
fix: detect tooluses with common path characters when cleaning for sp…
Browse files Browse the repository at this point in the history
…eech (#412)

* fix: detect tooluses with common path characters when cleaning for speech

* fix: improved clean_for_speech and its testing
  • Loading branch information
ErikBjare authored Jan 21, 2025
1 parent 598f409 commit 9124640
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gptme/tools/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@


re_thinking = re.compile(r"<thinking>.*?(\n</thinking>|$)", flags=re.DOTALL)
re_tool_use = re.compile(r"```[\w\. ]+\n[^`]*(\n```|$)", flags=re.DOTALL)
re_tool_use = re.compile(r"```[\w\. ~/\-]+\n(.*?)(\n```|$)", flags=re.DOTALL)


def set_speed(speed):
Expand Down
12 changes: 11 additions & 1 deletion tests/test_tools_tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,18 @@ def test_clean_for_speech():
assert re_tool_use.search("```tool\ncontents\n```")

# with arg
assert re_tool_use.search("```save test.txt\ncontents\n```")
assert re_tool_use.search("```save ~/path_to/test-file1.txt\ncontents\n```")

# with `text` contents
assert re_tool_use.search("```file.md\ncontents with `code` string\n```")

# incomplete
assert re_thinking.search("\n<thinking>thinking")
assert re_tool_use.search("```savefile.txt\ncontents")

# make sure spoken content is correct
assert (
re_tool_use.sub("", "Using tool\n```tool\ncontents\n```").strip()
== "Using tool"
)
assert re_tool_use.sub("", "```tool\ncontents\n```\nRan tool").strip() == "Ran tool"

0 comments on commit 9124640

Please sign in to comment.