Skip to content

Commit

Permalink
fix: remove exclusive mode (#423)
Browse files Browse the repository at this point in the history
* fix: improve emtpy string test

* fix: remove unecessary exclusive_mode flag
  • Loading branch information
jrmi authored Jan 25, 2025
1 parent b889107 commit 0c99cb8
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion gptme/llm/llm_anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def _handle_tools(message_dicts: Iterable[dict]) -> Generator[dict, None, None]:
if tooluse.call_id:
before_tool = text[: tooluse.start]

if before_tool:
if before_tool.strip():
content.append({"type": "text", "text": before_tool})

content.append(
Expand Down
2 changes: 1 addition & 1 deletion gptme/llm/llm_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def _handle_tools(message_dicts: Iterable[dict]) -> Generator[dict, None, None]:
if tooluse.call_id:
before_tool = text[: tooluse.start]

if before_tool.replace("\n", ""):
if before_tool.strip():
content.append({"type": "text", "text": before_tool})

tool_calls.append(
Expand Down
5 changes: 2 additions & 3 deletions gptme/tools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

# tooluse format
tool_format: ToolFormat = "markdown"
exclusive_mode = False

# Match tool name and start of JSON
toolcall_re = re.compile(r"^@(\w+)\(([\w_\-]+)\):\s*({.*)", re.M | re.S)
Expand Down Expand Up @@ -339,10 +338,10 @@ def iter_from_content(cls, content: str) -> Generator["ToolUse", None, None]:
"""Returns all ToolUse in a message, markdown or XML, in order."""
# collect all tool uses
tool_uses = []
if tool_format == "xml" or not exclusive_mode:
if tool_format == "xml":
for tool_use in cls._iter_from_xml(content):
tool_uses.append(tool_use)
if tool_format == "markdown" or not exclusive_mode:
if tool_format == "markdown":
for tool_use in cls._iter_from_markdown(content):
tool_uses.append(tool_use)

Expand Down
5 changes: 1 addition & 4 deletions tests/test_llm_anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ def test_message_conversion_with_tool_and_non_tool():

messages_dicts, _, _ = _prepare_messages_for_api(messages, [tool_save, tool_shell])

print(messages_dicts)

assert messages_dicts == [
{
"role": "user",
Expand All @@ -208,13 +206,12 @@ def test_message_conversion_with_tool_and_non_tool():
{
"role": "assistant",
"content": [
{"type": "text", "text": "\n"},
{
"type": "tool_use",
"id": "tool_call_id",
"name": "save",
"input": {"path": "path.txt", "content": "file_content"},
},
}
],
},
{
Expand Down

0 comments on commit 0c99cb8

Please sign in to comment.