Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -258,69 +258,6 @@ def call_set_task(purpose, task, history, action_input):
|
|
258 |
return "MAIN", None, history, task
|
259 |
|
260 |
|
261 |
-
NAME_TO_FUNC = {
|
262 |
-
"MAIN": call_main,
|
263 |
-
"UPDATE-TASK": call_set_task,
|
264 |
-
"SEARCH_ENGINE": find_all,
|
265 |
-
"WEBSITE_SCRAPE": find_all,
|
266 |
-
|
267 |
-
|
268 |
-
}
|
269 |
-
|
270 |
-
|
271 |
-
def run_action(purpose, task, history, action_name, action_input):
|
272 |
-
if action_name == "COMPLETE":
|
273 |
-
print("Complete - Exiting")
|
274 |
-
#exit(0)
|
275 |
-
return "COMPLETE", None, history, task
|
276 |
-
|
277 |
-
# compress the history when it is long
|
278 |
-
if len(history.split("\n")) > MAX_HISTORY:
|
279 |
-
if VERBOSE:
|
280 |
-
print("COMPRESSING HISTORY")
|
281 |
-
history = compress_history(purpose, task, history)
|
282 |
-
if action_name in NAME_TO_FUNC:
|
283 |
-
|
284 |
-
assert action_name in NAME_TO_FUNC
|
285 |
-
|
286 |
-
print("RUN: ", action_name, action_input)
|
287 |
-
return NAME_TO_FUNC[action_name](purpose, task, history, action_input)
|
288 |
-
else:
|
289 |
-
history += "observation: The TOOL I tried to use returned an error, I need to select a tool from: (UPDATE-TASK, SEARCH, COMPLETE)\n"
|
290 |
-
|
291 |
-
return "MAIN", None, history, task
|
292 |
-
|
293 |
-
def run(purpose,history):
|
294 |
-
task=None
|
295 |
-
history = ""
|
296 |
-
#if not history:
|
297 |
-
# history = []
|
298 |
-
action_name = "SEARCH" if task is None else "MAIN"
|
299 |
-
action_input = None
|
300 |
-
while True:
|
301 |
-
print("")
|
302 |
-
print("")
|
303 |
-
print("---")
|
304 |
-
#print("purpose:", purpose)
|
305 |
-
print("task:", task)
|
306 |
-
print("---")
|
307 |
-
#print(history)
|
308 |
-
print("---")
|
309 |
-
|
310 |
-
action_name, action_input, history, task = run_action(
|
311 |
-
purpose,
|
312 |
-
task,
|
313 |
-
history,
|
314 |
-
action_name,
|
315 |
-
action_input,
|
316 |
-
)
|
317 |
-
yield history
|
318 |
-
if action_name == "COMPLETE":
|
319 |
-
return history
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
|
325 |
###########################################################
|
326 |
def search_all(url):
|
@@ -423,6 +360,69 @@ def find_it2(url):
|
|
423 |
return e
|
424 |
#################################
|
425 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
426 |
examples =[
|
427 |
"find the most popular model that I can use to generate an image by providing a text prompt",
|
428 |
"return the top 10 models that I can use to identify objects in images",
|
|
|
258 |
return "MAIN", None, history, task
|
259 |
|
260 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
261 |
|
262 |
###########################################################
|
263 |
def search_all(url):
|
|
|
360 |
return e
|
361 |
#################################
|
362 |
|
363 |
+
NAME_TO_FUNC = {
|
364 |
+
"MAIN": call_main,
|
365 |
+
"UPDATE-TASK": call_set_task,
|
366 |
+
"SEARCH_ENGINE": find_all,
|
367 |
+
"WEBSITE_SCRAPE": find_all,
|
368 |
+
|
369 |
+
|
370 |
+
}
|
371 |
+
|
372 |
+
|
373 |
+
def run_action(purpose, task, history, action_name, action_input):
|
374 |
+
if action_name == "COMPLETE":
|
375 |
+
print("Complete - Exiting")
|
376 |
+
#exit(0)
|
377 |
+
return "COMPLETE", None, history, task
|
378 |
+
|
379 |
+
# compress the history when it is long
|
380 |
+
if len(history.split("\n")) > MAX_HISTORY:
|
381 |
+
if VERBOSE:
|
382 |
+
print("COMPRESSING HISTORY")
|
383 |
+
history = compress_history(purpose, task, history)
|
384 |
+
if action_name in NAME_TO_FUNC:
|
385 |
+
|
386 |
+
assert action_name in NAME_TO_FUNC
|
387 |
+
|
388 |
+
print("RUN: ", action_name, action_input)
|
389 |
+
return NAME_TO_FUNC[action_name](purpose, task, history, action_input)
|
390 |
+
else:
|
391 |
+
history += "observation: The TOOL I tried to use returned an error, I need to select a tool from: (UPDATE-TASK, SEARCH, COMPLETE)\n"
|
392 |
+
|
393 |
+
return "MAIN", None, history, task
|
394 |
+
|
395 |
+
def run(purpose,history):
|
396 |
+
task=None
|
397 |
+
history = ""
|
398 |
+
#if not history:
|
399 |
+
# history = []
|
400 |
+
action_name = "SEARCH" if task is None else "MAIN"
|
401 |
+
action_input = None
|
402 |
+
while True:
|
403 |
+
print("")
|
404 |
+
print("")
|
405 |
+
print("---")
|
406 |
+
#print("purpose:", purpose)
|
407 |
+
print("task:", task)
|
408 |
+
print("---")
|
409 |
+
#print(history)
|
410 |
+
print("---")
|
411 |
+
|
412 |
+
action_name, action_input, history, task = run_action(
|
413 |
+
purpose,
|
414 |
+
task,
|
415 |
+
history,
|
416 |
+
action_name,
|
417 |
+
action_input,
|
418 |
+
)
|
419 |
+
yield history
|
420 |
+
if action_name == "COMPLETE":
|
421 |
+
return history
|
422 |
+
|
423 |
+
|
424 |
+
|
425 |
+
|
426 |
examples =[
|
427 |
"find the most popular model that I can use to generate an image by providing a text prompt",
|
428 |
"return the top 10 models that I can use to identify objects in images",
|