Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Aman Rusia committed Nov 20, 2024
1 parent 65dbbde commit 04ec4f5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 86 deletions.
69 changes: 0 additions & 69 deletions gpt_action_json_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,46 +50,6 @@
}
}
},
"/v1/file_edit_find_replace": {
"post": {
"x-openai-isConsequential": false,
"summary": "File Edit Find Replace",
"operationId": "file_edit_find_replace_v1_file_edit_find_replace_post",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/FileEditFindReplaceWithUUID"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"type": "string",
"title": "Response File Edit Find Replace V1 File Edit Find Replace Post"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/v1/reset_shell": {
"post": {
"x-openai-isConsequential": false,
Expand Down Expand Up @@ -295,35 +255,6 @@
],
"title": "CommandWithUUID"
},
"FileEditFindReplaceWithUUID": {
"properties": {
"file_path": {
"type": "string",
"title": "File Path"
},
"find_lines": {
"type": "string",
"title": "Find Lines"
},
"replace_with_lines": {
"type": "string",
"title": "Replace With Lines"
},
"user_id": {
"type": "string",
"format": "uuid",
"title": "User Id"
}
},
"type": "object",
"required": [
"file_path",
"find_lines",
"replace_with_lines",
"user_id"
],
"title": "FileEditFindReplaceWithUUID"
},
"HTTPValidationError": {
"properties": {
"detail": {
Expand Down
6 changes: 0 additions & 6 deletions gpt_instructions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ Instructions for `BashInteraction`
- Send text input to the running program.
- Only one of send_text, send_specials, send_ascii should be provided.

Instructions for `FileEditFindReplace`
- Find and replace multiple lines in a file.
- Use absolute file path only.
- Replaces complete lines.
- Prefer this over WriteFile if edits are to be made on large files.

Instructions for `ResetShell`
- Resets the shell. Use only if all interrupts and prompt reset attempts have failed repeatedly.

Expand Down
6 changes: 4 additions & 2 deletions src/wcgw/client/anthropic_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
get_tool_output,
SHELL,
start_shell,
which_tool,
which_tool_name,
)
import tiktoken

Expand Down Expand Up @@ -326,7 +326,9 @@ def loop(
elif type_ == "content_block_stop":
if tool_calls and not tool_calls[-1]["done"]:
tc = tool_calls[-1]
tool_parsed = which_tool(tc["input"])
tool_parsed = which_tool_name(
tc["name"]
).model_validate_json(tc["input"])
system_console.print(
f"\n---------------------------------------\n# Assistant invoked tool: {tool_parsed}"
)
Expand Down
9 changes: 0 additions & 9 deletions src/wcgw/client/openai_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,6 @@ def loop(
ResetShell,
description="Resets the shell. Use only if all interrupts and prompt reset attempts have failed repeatedly.",
),
openai.pydantic_function_tool(
FileEditFindReplace,
description="""
- Find and replace multiple lines in a file.
- Use absolute file path only.
- Replaces complete lines.
- Prefer this over WriteFile if any edits are to be made.""",
),
]
uname_sysname = os.uname().sysname
uname_machine = os.uname().machine
Expand Down Expand Up @@ -239,7 +231,6 @@ def loop(
assistant_console = rich.console.Console(
style="white bold", highlight=False, markup=False
)

while True:
if cost > limit:
system_console.print(
Expand Down
27 changes: 27 additions & 0 deletions src/wcgw/client/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
NewType,
Optional,
ParamSpec,
Type,
TypeVar,
TypedDict,
)
Expand Down Expand Up @@ -541,6 +542,7 @@ def take_help_of_ai_assistant(
| BashInteraction
| ResetShell
| Writefile
| CreateFileNew
| FileEditFindReplace
| AIAssistant
| DoneFlag
Expand All @@ -553,6 +555,31 @@ def which_tool(args: str) -> TOOLS:
return adapter.validate_python(json.loads(args))


def which_tool_name(name: str) -> Type[TOOLS]:
if name == "Confirmation":
return Confirmation
elif name == "BashCommand":
return BashCommand
elif name == "BashInteraction":
return BashInteraction
elif name == "ResetShell":
return ResetShell
elif name == "Writefile":
return Writefile
elif name == "CreateFileNew":
return CreateFileNew
elif name == "FileEditFindReplace":
return FileEditFindReplace
elif name == "AIAssistant":
return AIAssistant
elif name == "DoneFlag":
return DoneFlag
elif name == "ReadImage":
return ReadImage
else:
raise ValueError(f"Unknown tool name: {name}")


def get_tool_output(
args: dict[object, object]
| Confirmation
Expand Down

0 comments on commit 04ec4f5

Please sign in to comment.