-
Notifications
You must be signed in to change notification settings - Fork 80
/
actions.py
158 lines (130 loc) · 3.96 KB
/
actions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
from typing import Literal, Optional, Union
from autopr.agents.codegen_agent.autonomous_v1.action_utils.context import ContextFile
from autopr.models.artifacts import Issue
from autopr.models.prompt_rails import PromptRail
from autopr.models.rail_objects import RailObject, PullRequestDescription, CommitPlan
###
# Action decision objects
###
class NewFileAction(RailObject):
output_spec = f"""<string
name="filepath"
description="Path to the newly created file."
required="true"
/>
<string
name="description"
description="Description of the contents of the new file."
required="true"
/>
"""
filepath: str
description: str
def __str__(self):
return f"Created file {self.filepath}"
class EditFileAction(RailObject):
output_spec = f"""<string
name="filepath"
description="Path to the file to be edited."
required="true"
/>
<string
name="description"
description="Description of the changes to be made to the file."
required="true"
/>
<integer
name="start_line"
description="The line number of the first line of the hunk to be edited."
format="positive"
required="false"
on-fail="noop"
/>
<integer
name="end_line"
description="The line number of the last line of the hunk to be edited. Keep the hunk as short as possible while fulfilling the description."
format="positive"
required="false"
on-fail="noop"
/>"""
filepath: str
description: str
start_line: Optional[int] = None
end_line: Optional[int] = None
def __str__(self):
s = self.filepath
if self.start_line is not None:
s += f":L{self.start_line}"
if self.end_line is not None:
s += f"-L{self.end_line}"
return s
ActionUnion = Union[NewFileAction, EditFileAction]
###
# Action choice rail
###
class Action(RailObject):
output_spec = f"""<choice
name="action"
on-fail-choice="reask"
>
<case
name="new_file"
>
<object
name="new_file"
>
{NewFileAction.output_spec}
</object>
</case>
<case
name="edit_file"
>
<object
name="edit_file"
>
{EditFileAction.output_spec}
</object>
</case>
<case
name="finished"
>
<string
name="commit_message"
description="A more appropriate commit message based on the actions taken."
required="false"
/>
</case>
</choice>"""
action: Literal["new_file", "edit_file", "finished"]
new_file: Optional[NewFileAction]
edit_file: Optional[EditFileAction]
commit_message: Optional[str]
class MakeDecision(PromptRail):
two_step = False
output_type = Action
prompt_template = f"""You are about to make a decision on what to do next.
This is the issue that was opened:
```{{issue}}```
This is the pull request we're creating:
```{{pull_request_description}}```
This is the commit we're writing:
```{{commit}}```
This is the codebase subset we decided to look at:
```{{context_hunks}}```
These are the actions we've taken so far:
```{{past_actions}}```
In our pursuit of implementing this commit, please make a decision on what to do next.
If a new file should be created, respond with `new_file` and the file path and description.
If one of the files in the codebase subset should be edited, respond with `edit_file` and the file path, description, and line numbers of the hunk to edit. When picking the line numbers, keep the hunk as short as possible while fulfilling the description. If you don't know which line numbers to pick, leave them blank.
If you're done, respond with `finished` and the commit message describing the past actions."""
issue: Issue
pull_request_description: PullRequestDescription
commit: CommitPlan
context_hunks: list[ContextFile]
past_actions: list[tuple[ActionUnion, str]] # Action and effect
def get_string_params(self) -> dict[str, str]:
params = super().get_string_params()
params["past_actions"] = "\n".join(
f"{action}: {effect}" for action, effect in self.past_actions
)
return params