lgaleana commited on
Commit
5dacd91
1 Parent(s): 3bea00c

Allow reference other task outputs

Browse files
Files changed (2) hide show
  1. actions.py +10 -8
  2. app.py +10 -6
actions.py CHANGED
@@ -55,8 +55,8 @@ def execute_task(task_id: int, active_index: int, error_value, *args):
55
  # - start_inputs: Where the active task inputs start within args.
56
  # - end_inputs: End of the active task inputs.
57
  # - task_inputs: The active task inputs.
58
- # - prev_active_indexes: Indexes of the active tasks in the previous tasks.
59
- # - prev_task_outputs: Outputs of the previous tasks.
60
  start_inputs = 0
61
  end_inputs = 0
62
  end_all_inputs = sum(inner_n_inputs)
@@ -66,8 +66,8 @@ def execute_task(task_id: int, active_index: int, error_value, *args):
66
  break
67
  start_inputs += n
68
  task_inputs = args[start_inputs:end_inputs]
69
- prev_active_indexes = args[end_all_inputs : end_all_inputs + task_id]
70
- prev_task_outputs = args[end_all_inputs + task_id :]
71
 
72
  # If no inputs, skip
73
  non_empty_inputs = [i for i in task_inputs if i]
@@ -76,10 +76,12 @@ def execute_task(task_id: int, active_index: int, error_value, *args):
76
 
77
  # Put task outputs in a dictionary with names.
78
  vars_in_scope = {}
79
- for i, prev_active_index in enumerate(prev_active_indexes):
80
- vars_in_scope[f"{Task.vname}{i}"] = prev_task_outputs[
81
- i * n_avail_tasks + int(prev_active_index)
82
- ]
 
 
83
 
84
  try:
85
  # Task logic gets inserted into the right index
 
55
  # - start_inputs: Where the active task inputs start within args.
56
  # - end_inputs: End of the active task inputs.
57
  # - task_inputs: The active task inputs.
58
+ # - other_active_indexes: Indexes of the active tasks in the other tasks.
59
+ # - other_task_outputs: Outputs of every other task.
60
  start_inputs = 0
61
  end_inputs = 0
62
  end_all_inputs = sum(inner_n_inputs)
 
66
  break
67
  start_inputs += n
68
  task_inputs = args[start_inputs:end_inputs]
69
+ other_active_indexes = args[end_all_inputs : end_all_inputs + MAX_TASKS - 1]
70
+ other_task_outputs = args[end_all_inputs + MAX_TASKS - 1 :]
71
 
72
  # If no inputs, skip
73
  non_empty_inputs = [i for i in task_inputs if i]
 
76
 
77
  # Put task outputs in a dictionary with names.
78
  vars_in_scope = {}
79
+ for i, other_active_index in enumerate(other_active_indexes):
80
+ if other_active_index is not None:
81
+ other_task_id = i if i < task_id else i + 1
82
+ vars_in_scope[f"{Task.vname}{other_task_id}"] = other_task_outputs[
83
+ i * n_avail_tasks + int(other_active_index)
84
+ ]
85
 
86
  try:
87
  # Task logic gets inserted into the right index
app.py CHANGED
@@ -1,7 +1,13 @@
1
  import gradio as gr
2
 
3
  import actions as a
4
- from examples import authenticate_google, best_clubs, generate_ad, seo, summarize_website
 
 
 
 
 
 
5
  from components import all_tasks, Tasks
6
 
7
 
@@ -17,7 +23,7 @@ with gr.Blocks() as demo:
17
  <br>**Code Task**: You will need code to do certain things that ChatGPT can't do, like access the internet or iterate over 4k+ tokens.
18
  <br> With this task, ChatGPT will generate code and then execute it. The code must be generated before executing all tasks.
19
  <br>
20
- <br>Output from previous tasks can be referenced in subsequen tasks with {tn}. Max 10 tasks allowed (for now).
21
  """
22
  )
23
  with gr.Tab("Toolkit"):
@@ -48,17 +54,15 @@ with gr.Blocks() as demo:
48
  inputs=[],
49
  outputs=[error_message],
50
  )
51
- prev_tasks = []
52
  for i, task in all_tasks.items():
53
  execution_event = execution_event.then(
54
  a.execute_task,
55
  inputs=[task.component_id, task.active_index, error_message]
56
  + task.inputs
57
- + [t.active_index for t in prev_tasks]
58
- + [o for t in prev_tasks for o in t.outputs],
59
  outputs=task.outputs + [error_message],
60
  )
61
- prev_tasks.append(task)
62
 
63
  # Examples
64
  summarize_website.render()
 
1
  import gradio as gr
2
 
3
  import actions as a
4
+ from examples import (
5
+ authenticate_google,
6
+ best_clubs,
7
+ generate_ad,
8
+ seo,
9
+ summarize_website,
10
+ )
11
  from components import all_tasks, Tasks
12
 
13
 
 
23
  <br>**Code Task**: You will need code to do certain things that ChatGPT can't do, like access the internet or iterate over 4k+ tokens.
24
  <br> With this task, ChatGPT will generate code and then execute it. The code must be generated before executing all tasks.
25
  <br>
26
+ <br>Output from other tasks can be referenced in the current task with {tn}. Max 10 tasks allowed (for now).
27
  """
28
  )
29
  with gr.Tab("Toolkit"):
 
54
  inputs=[],
55
  outputs=[error_message],
56
  )
 
57
  for i, task in all_tasks.items():
58
  execution_event = execution_event.then(
59
  a.execute_task,
60
  inputs=[task.component_id, task.active_index, error_message]
61
  + task.inputs
62
+ + [t.active_index for t in all_tasks.values() if t != task]
63
+ + [o for t in all_tasks.values() if t != task for o in t.outputs],
64
  outputs=task.outputs + [error_message],
65
  )
 
66
 
67
  # Examples
68
  summarize_website.render()