Skip to content

Commit 01e5432

Browse files
author
Aman Rusia
committed
Instructions improvement. Removed possibility of wrong type of tool model getting parsed
1 parent 5c4da74 commit 01e5432

File tree

7 files changed

+136
-83
lines changed

7 files changed

+136
-83
lines changed

gpt_action_json_schema.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,14 @@
255255
"schemas": {
256256
"BashInteractionWithUUID": {
257257
"properties": {
258+
"type": {
259+
"type": "string",
260+
"enum": [
261+
"BashInteraction"
262+
],
263+
"const": "BashInteraction",
264+
"title": "Type"
265+
},
258266
"send_text": {
259267
"anyOf": [
260268
{
@@ -312,7 +320,8 @@
312320
},
313321
"type": "object",
314322
"required": [
315-
"user_id"
323+
"user_id",
324+
"type"
316325
],
317326
"title": "BashInteractionWithUUID"
318327
},
@@ -443,7 +452,8 @@
443452
},
444453
"type": "object",
445454
"required": [
446-
"user_id"
455+
"user_id",
456+
"should_reset"
447457
],
448458
"title": "ResetShellWithUUID"
449459
},

gpt_instructions.txt

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,35 @@ Instructions for `FileEdit`:
3939
- Use absolute file path only.
4040
- Use SEARCH/REPLACE blocks to edit the file.
4141
Only edit the files using the following SEARCH/REPLACE blocks.
42+
4243
```
4344
<<<<<<< SEARCH
44-
// Original code
45+
def hello():
46+
"print a greeting"
47+
48+
print("hello")
4549
=======
46-
// New code
50+
from hello import hello as hello_renamed
51+
>>>>>>> REPLACE
52+
<<<<<<< SEARCH
53+
def call_hello():
54+
"call hello"
55+
56+
hello()
57+
=======
58+
def call_hello_renamed():
59+
"call hello renamed"
60+
61+
hello_renamed()
4762
>>>>>>> REPLACE
4863
<<<<<<< SEARCH
49-
// Original code further down in the file
64+
impl1()
65+
hello()
66+
impl2()
5067
=======
51-
// New code to replace
68+
impl1()
69+
hello_renamed()
70+
impl2()
5271
>>>>>>> REPLACE
5372
```
5473

src/wcgw/client/anthropic_client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,10 @@ def loop(
223223
224224
Instructions:
225225
226-
- You should use the provided bash execution tool to run script to complete objective.
227-
- First understand about the project by understanding the folder structure (ignoring node_modules or venv, etc.)
228-
- Always read relevant files before making any changes.
226+
- You should use the provided bash execution, reading and writing file tools to complete objective.
227+
- First understand about the project by getting the folder structure (ignoring .git, node_modules, venv, etc.)
228+
- Always read relevant files before editing.
229+
- Do not provide code snippets unless asked by the user, instead directly edit the code.
229230
230231
System information:
231232
- System: {uname_sysname}

src/wcgw/client/diff-instructions.txt

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11

2-
Instructions for
2+
Instructions for editing files.
3+
4+
35
Only edit the files using the following SEARCH/REPLACE blocks.
46
```
57
<<<<<<< SEARCH
@@ -8,7 +10,27 @@ def hello():
810

911
print("hello")
1012
=======
11-
from hello import hello
13+
from hello import hello as hello_renamed
14+
>>>>>>> REPLACE
15+
<<<<<<< SEARCH
16+
def call_hello():
17+
"call hello"
18+
19+
hello()
20+
=======
21+
def call_hello_renamed():
22+
"call hello renamed"
23+
24+
hello_renamed()
25+
>>>>>>> REPLACE
26+
<<<<<<< SEARCH
27+
impl1()
28+
hello()
29+
impl2()
30+
=======
31+
impl1()
32+
hello_renamed()
33+
impl2()
1234
>>>>>>> REPLACE
1335
```
1436

src/wcgw/client/openai_client.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,11 @@ def loop(
227227
228228
Instructions:
229229
230-
- You should use the provided bash execution tool to run script to complete objective.
231-
- First understand about the project by understanding the folder structure (ignoring node_modules or venv, etc.)
232-
- Always read relevant files before making any changes.
233-
230+
- You should use the provided bash execution, reading and writing file tools to complete objective.
231+
- First understand about the project by getting the folder structure (ignoring .git, node_modules, venv, etc.)
232+
- Always read relevant files before editing.
233+
- Do not provide code snippets unless asked by the user, instead directly edit the code.
234+
234235
System information:
235236
- System: {uname_sysname}
236237
- Machine: {uname_machine}

src/wcgw/client/tools.py

Lines changed: 66 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -251,55 +251,71 @@ def execute_bash(
251251
)
252252

253253
SHELL.sendline(command)
254-
elif bash_arg.send_specials:
255-
console.print(f"Sending special sequence: {bash_arg.send_specials}")
256-
for char in bash_arg.send_specials:
257-
if char == "Key-up":
258-
SHELL.send("\033[A")
259-
elif char == "Key-down":
260-
SHELL.send("\033[B")
261-
elif char == "Key-left":
262-
SHELL.send("\033[D")
263-
elif char == "Key-right":
264-
SHELL.send("\033[C")
265-
elif char == "Enter":
266-
SHELL.send("\n")
267-
elif char == "Ctrl-c":
268-
SHELL.sendintr()
269-
is_interrupt = True
270-
elif char == "Ctrl-d":
271-
SHELL.sendintr()
272-
is_interrupt = True
273-
elif char == "Ctrl-z":
274-
SHELL.send("\x1a")
275-
else:
276-
raise Exception(f"Unknown special character: {char}")
277-
elif bash_arg.send_ascii:
278-
console.print(f"Sending ASCII sequence: {bash_arg.send_ascii}")
279-
for ascii_char in bash_arg.send_ascii:
280-
SHELL.send(chr(ascii_char))
281-
if ascii_char == 3:
282-
is_interrupt = True
254+
283255
else:
284-
if bash_arg.send_text is None:
256+
if (
257+
sum(
258+
[
259+
int(bool(bash_arg.send_text)),
260+
int(bool(bash_arg.send_specials)),
261+
int(bool(bash_arg.send_ascii)),
262+
]
263+
)
264+
!= 1
265+
):
285266
return (
286-
"Failure: at least one of send_text, send_specials or send_ascii should be provided",
267+
"Failure: exactly one of send_text, send_specials or send_ascii should be provided",
287268
0.0,
288269
)
270+
if bash_arg.send_specials:
271+
console.print(f"Sending special sequence: {bash_arg.send_specials}")
272+
for char in bash_arg.send_specials:
273+
if char == "Key-up":
274+
SHELL.send("\033[A")
275+
elif char == "Key-down":
276+
SHELL.send("\033[B")
277+
elif char == "Key-left":
278+
SHELL.send("\033[D")
279+
elif char == "Key-right":
280+
SHELL.send("\033[C")
281+
elif char == "Enter":
282+
SHELL.send("\n")
283+
elif char == "Ctrl-c":
284+
SHELL.sendintr()
285+
is_interrupt = True
286+
elif char == "Ctrl-d":
287+
SHELL.sendintr()
288+
is_interrupt = True
289+
elif char == "Ctrl-z":
290+
SHELL.send("\x1a")
291+
else:
292+
raise Exception(f"Unknown special character: {char}")
293+
elif bash_arg.send_ascii:
294+
console.print(f"Sending ASCII sequence: {bash_arg.send_ascii}")
295+
for ascii_char in bash_arg.send_ascii:
296+
SHELL.send(chr(ascii_char))
297+
if ascii_char == 3:
298+
is_interrupt = True
299+
else:
300+
if bash_arg.send_text is None:
301+
return (
302+
"Failure: at least one of send_text, send_specials or send_ascii should be provided",
303+
0.0,
304+
)
289305

290-
updated_repl_mode = update_repl_prompt(bash_arg.send_text)
291-
if updated_repl_mode:
292-
BASH_STATE = "repl"
293-
response = (
294-
"Prompt updated, you can execute REPL lines using BashCommand now"
295-
)
296-
console.print(response)
297-
return (
298-
response,
299-
0,
300-
)
301-
console.print(f"Interact text: {bash_arg.send_text}")
302-
SHELL.sendline(bash_arg.send_text)
306+
updated_repl_mode = update_repl_prompt(bash_arg.send_text)
307+
if updated_repl_mode:
308+
BASH_STATE = "repl"
309+
response = (
310+
"Prompt updated, you can execute REPL lines using BashCommand now"
311+
)
312+
console.print(response)
313+
return (
314+
response,
315+
0,
316+
)
317+
console.print(f"Interact text: {bash_arg.send_text}")
318+
SHELL.sendline(bash_arg.send_text)
303319

304320
BASH_STATE = "repl"
305321

@@ -520,6 +536,12 @@ def do_diff_edit(fedit: FileEdit) -> str:
520536
apply_diff_to = f.read()
521537

522538
lines = fedit.file_edit_using_search_replace_blocks.split("\n")
539+
540+
if not lines or not re.match(r"^<<<<<<+\s*SEARCH\s*$", lines[0]):
541+
raise Exception(
542+
"Error: first line should be `<<<<<< SEARCH` to start a search-replace block"
543+
)
544+
523545
n_lines = len(lines)
524546
i = 0
525547
replacement_count = 0

src/wcgw/types_.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,11 @@ class BashCommand(BaseModel):
1313

1414

1515
class BashInteraction(BaseModel):
16+
type: Literal["BashInteraction"]
1617
send_text: Optional[str] = None
1718
send_specials: Optional[Sequence[Specials]] = None
1819
send_ascii: Optional[Sequence[int]] = None
1920

20-
def model_post_init(self, __context: object) -> None:
21-
# Ensure only one of the fields is set
22-
if (
23-
sum(
24-
[
25-
int(bool(self.send_text)),
26-
int(bool(self.send_specials)),
27-
int(bool(self.send_ascii)),
28-
]
29-
)
30-
!= 1
31-
):
32-
raise ValueError(
33-
"Exactly one of 'send_text', 'send_specials', or 'send_ascii' must be set"
34-
)
35-
3621

3722
class ReadImage(BaseModel):
3823
file_path: str
@@ -61,16 +46,9 @@ class FileEditFindReplace(BaseModel):
6146

6247

6348
class ResetShell(BaseModel):
64-
should_reset: Literal[True] = True
49+
should_reset: Literal[True]
6550

6651

6752
class FileEdit(BaseModel):
6853
file_path: str
6954
file_edit_using_search_replace_blocks: str
70-
71-
def model_post_init(self, __context: object) -> None:
72-
# Ensure first line is "<<<<<<< SEARCH"
73-
74-
if not re.match(r"^<<<<<<+\s*SEARCH\s*$", self.file_edit_using_search_replace_blocks.split("\n")[0]):
75-
76-
raise ValueError("First line of file_edit_using_search_replace_blocks must be '<<<<<<< SEARCH'")

0 commit comments

Comments
 (0)