johann22 commited on
Commit
2302e9d
·
1 Parent(s): 6a9395c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -135
app.py CHANGED
@@ -50,7 +50,6 @@ def run_gpt(
50
  prompt_template,
51
  stop_tokens,
52
  max_tokens,
53
- module_summary,
54
  purpose,
55
  **prompt_kwargs,
56
  ):
@@ -89,12 +88,10 @@ def run_gpt(
89
 
90
 
91
  def compress_history(purpose, task, history, directory):
92
- module_summary, _, _ = read_python_module_structure(directory)
93
  resp = run_gpt(
94
  COMPRESS_HISTORY_PROMPT,
95
  stop_tokens=["observation:", "task:", "action:", "thought:"],
96
  max_tokens=512,
97
- module_summary=module_summary,
98
  purpose=purpose,
99
  task=task,
100
  history=history,
@@ -123,12 +120,10 @@ def call_search(purpose, task, history, directory, action_input):
123
  return "MAIN", None, history, task
124
 
125
  def call_main(purpose, task, history, directory, action_input):
126
- module_summary, _, _ = read_python_module_structure(directory)
127
  resp = run_gpt(
128
  ACTION_PROMPT,
129
  stop_tokens=["observation:", "task:"],
130
- max_tokens=256,
131
- module_summary=module_summary,
132
  purpose=purpose,
133
  task=task,
134
  history=history,
@@ -160,46 +155,11 @@ def call_main(purpose, task, history, directory, action_input):
160
  return "MAIN", None, history, task
161
 
162
 
163
- def call_test(purpose, task, history, directory, action_input):
164
- result = subprocess.run(
165
- ["python", "-m", "pytest", "--collect-only", directory],
166
- capture_output=True,
167
- text=True,
168
- )
169
- if result.returncode != 0:
170
- history += "observation: there are no tests! Test should be written in a test folder under {}\n".format(
171
- directory
172
- )
173
- return "MAIN", None, history, task
174
- result = subprocess.run(
175
- ["python", "-m", "pytest", directory], capture_output=True, text=True
176
- )
177
- if result.returncode == 0:
178
- history += "observation: tests pass\n"
179
- return "MAIN", None, history, task
180
- module_summary, content, _ = read_python_module_structure(directory)
181
- resp = run_gpt(
182
- UNDERSTAND_TEST_RESULTS_PROMPT,
183
- stop_tokens=[],
184
- max_tokens=256,
185
- module_summary=module_summary,
186
- purpose=purpose,
187
- task=task,
188
- history=history,
189
- stdout=result.stdout[:5000], # limit amount of text
190
- stderr=result.stderr[:5000], # limit amount of text
191
- )
192
- history += "observation: tests failed: {}\n".format(resp)
193
- return "MAIN", None, history, task
194
-
195
-
196
  def call_set_task(purpose, task, history, directory, action_input):
197
- module_summary, content, _ = read_python_module_structure(directory)
198
  task = run_gpt(
199
  TASK_PROMPT,
200
  stop_tokens=[],
201
  max_tokens=64,
202
- module_summary=module_summary,
203
  purpose=purpose,
204
  task=task,
205
  history=history,
@@ -207,100 +167,6 @@ def call_set_task(purpose, task, history, directory, action_input):
207
  history += "observation: task has been updated to: {}\n".format(task)
208
  return "MAIN", None, history, task
209
 
210
-
211
- def call_read(purpose, task, history, directory, action_input):
212
- if not os.path.exists(action_input):
213
- history += "observation: file does not exist\n"
214
- return "MAIN", None, history, task
215
- module_summary, content, _ = read_python_module_structure(directory)
216
- f_content = (
217
- content[action_input] if content[action_input] else "< document is empty >"
218
- )
219
- resp = run_gpt(
220
- READ_PROMPT,
221
- stop_tokens=[],
222
- max_tokens=256,
223
- module_summary=module_summary,
224
- purpose=purpose,
225
- task=task,
226
- history=history,
227
- file_path=action_input,
228
- file_contents=f_content,
229
- ).strip("\n")
230
- history += "observation: {}\n".format(resp)
231
- return "MAIN", None, history, task
232
-
233
-
234
- def call_modify(purpose, task, history, directory, action_input):
235
- if not os.path.exists(action_input):
236
- history += "observation: file does not exist\n"
237
- return "MAIN", None, history, task
238
- (
239
- module_summary,
240
- content,
241
- _,
242
- ) = read_python_module_structure(directory)
243
- f_content = (
244
- content[action_input] if content[action_input] else "< document is empty >"
245
- )
246
- resp = run_gpt(
247
- MODIFY_PROMPT,
248
- stop_tokens=["action:", "thought:", "observation:"],
249
- max_tokens=2048,
250
- module_summary=module_summary,
251
- purpose=purpose,
252
- task=task,
253
- history=history,
254
- file_path=action_input,
255
- file_contents=f_content,
256
- )
257
- new_contents, description = parse_file_content(resp)
258
- if new_contents is None:
259
- history += "observation: failed to modify file\n"
260
- return "MAIN", None, history, task
261
-
262
- with open(action_input, "w") as f:
263
- f.write(new_contents)
264
-
265
- history += "observation: file successfully modified\n"
266
- history += "observation: {}\n".format(description)
267
- return "MAIN", None, history, task
268
-
269
-
270
- def call_add(purpose, task, history, directory, action_input):
271
- d = os.path.dirname(action_input)
272
- if not d.startswith(directory):
273
- history += "observation: files must be under directory {}\n".format(directory)
274
- elif not action_input.endswith(".py"):
275
- history += "observation: can only write .py files\n"
276
- else:
277
- if d and not os.path.exists(d):
278
- os.makedirs(d)
279
- if not os.path.exists(action_input):
280
- module_summary, _, _ = read_python_module_structure(directory)
281
- resp = run_gpt(
282
- ADD_PROMPT,
283
- stop_tokens=["action:", "thought:", "observation:"],
284
- max_tokens=2048,
285
- module_summary=module_summary,
286
- purpose=purpose,
287
- task=task,
288
- history=history,
289
- file_path=action_input,
290
- )
291
- new_contents, description = parse_file_content(resp)
292
- if new_contents is None:
293
- history += "observation: failed to write file\n"
294
- return "MAIN", None, history, task
295
-
296
- with open(action_input, "w") as f:
297
- f.write(new_contents)
298
-
299
- history += "observation: file successfully written\n"
300
- history += "obsertation: {}\n".format(description)
301
- else:
302
- history += "observation: file already exists\n"
303
- return "MAIN", None, history, task
304
  def end_fn(purpose, task, history, directory, action_input):
305
  task = "END"
306
  return "COMPLETE", None, history, task
 
50
  prompt_template,
51
  stop_tokens,
52
  max_tokens,
 
53
  purpose,
54
  **prompt_kwargs,
55
  ):
 
88
 
89
 
90
  def compress_history(purpose, task, history, directory):
 
91
  resp = run_gpt(
92
  COMPRESS_HISTORY_PROMPT,
93
  stop_tokens=["observation:", "task:", "action:", "thought:"],
94
  max_tokens=512,
 
95
  purpose=purpose,
96
  task=task,
97
  history=history,
 
120
  return "MAIN", None, history, task
121
 
122
  def call_main(purpose, task, history, directory, action_input):
 
123
  resp = run_gpt(
124
  ACTION_PROMPT,
125
  stop_tokens=["observation:", "task:"],
126
+ max_tokens=1024,
 
127
  purpose=purpose,
128
  task=task,
129
  history=history,
 
155
  return "MAIN", None, history, task
156
 
157
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  def call_set_task(purpose, task, history, directory, action_input):
 
159
  task = run_gpt(
160
  TASK_PROMPT,
161
  stop_tokens=[],
162
  max_tokens=64,
 
163
  purpose=purpose,
164
  task=task,
165
  history=history,
 
167
  history += "observation: task has been updated to: {}\n".format(task)
168
  return "MAIN", None, history, task
169
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  def end_fn(purpose, task, history, directory, action_input):
171
  task = "END"
172
  return "COMPLETE", None, history, task