Skip to content

Commit

Permalink
Anthropic client improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Aman Rusia committed Nov 14, 2024
1 parent 048a86b commit 7f385ca
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
25 changes: 22 additions & 3 deletions src/wcgw/client/anthropic_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@
from typer import Typer
import uuid

from ..types_ import BashCommand, BashInteraction, ReadImage, Writefile, ResetShell
from ..types_ import (
BashCommand,
BashInteraction,
FileEditFindReplace,
ReadImage,
Writefile,
ResetShell,
)

from .common import Models, discard_input
from .common import CostData
Expand Down Expand Up @@ -163,12 +170,19 @@ def loop(
input_schema=BashInteraction.model_json_schema(),
name="BashInteraction",
description="""
- Interact with running program using this tool.""",
- Interact with running program using this tool
- Special keys like arrows, interrupts, enter, etc.
- Send text input to the running program.
- Send send_specials=["Enter"] to recheck status of a running program.
""",
),
ToolParam(
input_schema=Writefile.model_json_schema(),
name="WriteFile",
description="Write content to a file. Provide file path and content. Use this instead of BashCommand for writing files.",
description="""
- Write content to a file. Provide file path and content. Use this instead of BashCommand for writing files.
- This doesn't create any directories, please create directories using `mkdir -p` BashCommand.
- Provide absolute file path only.""",
),
ToolParam(
input_schema=ReadImage.model_json_schema(),
Expand All @@ -180,6 +194,11 @@ def loop(
name="ResetShell",
description="Resets the shell. Use only if all interrupts and prompt reset attempts have failed repeatedly.",
),
ToolParam(
input_schema=FileEditFindReplace.model_json_schema(),
name="FileEditFindReplace",
description="Find and replace text in a file. Use absolute file path only.",
),
]
uname_sysname = os.uname().sysname
uname_machine = os.uname().machine
Expand Down
9 changes: 7 additions & 2 deletions src/wcgw/client/openai_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,16 @@ def loop(
openai.pydantic_function_tool(
BashInteraction,
description="""
- Interact with running program using this tool.""",
- Interact with running program using this tool
- Special keys like arrows, interrupts, enter, etc.
- Send text input to the running program.""",
),
openai.pydantic_function_tool(
Writefile,
description="Write content to a file. Provide file path and content. Use this instead of BashCommand for writing files.",
description="""
- Write content to a file. Provide file path and content. Use this instead of BashCommand for writing files.
- This doesn't create any directories, please create directories using `mkdir -p` BashCommand.
- Provide absolute file path only.""",
),
openai.pydantic_function_tool(
ReadImage, description="Read an image from the shell."
Expand Down
2 changes: 1 addition & 1 deletion src/wcgw/client/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def find_least_edit_distance_substring(content: str, find_str: str) -> str:

def file_edit(file_edit: FileEditFindReplace) -> str:
if not os.path.isabs(file_edit.file_path):
path_ = os.path.join(CWD, file_edit.file_path)
return "Failure: file_path should be absolute path"
else:
path_ = file_edit.file_path

Expand Down

0 comments on commit 7f385ca

Please sign in to comment.