Skip to content

Commit

Permalink
fix: improved clean_for_speech and its testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Jan 21, 2025
1 parent 6028c44 commit 89486b3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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
10 changes: 10 additions & 0 deletions tests/test_tools_tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ def test_clean_for_speech():
# with arg
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 89486b3

Please sign in to comment.