lgaleana commited on
Commit
cffb5aa
1 Parent(s): 8d878e6

Fix code gen

Browse files
Files changed (2) hide show
  1. actions.py +6 -1
  2. components.py +21 -15
actions.py CHANGED
@@ -41,7 +41,9 @@ def execute_task(task_id: int, active_index: int, error_value, *args):
41
  # We need to return outputs for all tasks in the row.
42
  outputs = [""] * n_avail_tasks
43
 
44
- if active_index is None or error_value: # Active index could be 0 == not active_index
 
 
45
  return outputs + [
46
  gr.HighlightedText.update(
47
  value=error_value, visible=error_value is not None
@@ -108,6 +110,9 @@ def execute_task(task_id: int, active_index: int, error_value, *args):
108
  )
109
  ]
110
  except Exception as e:
 
 
 
111
  outputs[active_index] = "ERROR"
112
  return outputs + [
113
  gr.HighlightedText.update(
 
41
  # We need to return outputs for all tasks in the row.
42
  outputs = [""] * n_avail_tasks
43
 
44
+ if (
45
+ active_index is None or error_value
46
+ ): # Active index could be 0 == not active_index
47
  return outputs + [
48
  gr.HighlightedText.update(
49
  value=error_value, visible=error_value is not None
 
110
  )
111
  ]
112
  except Exception as e:
113
+ import traceback
114
+
115
+ print(traceback.format_tb(e.__traceback__))
116
  outputs[active_index] = "ERROR"
117
  return outputs + [
118
  gr.HighlightedText.update(
components.py CHANGED
@@ -1,3 +1,4 @@
 
1
  from abc import ABC, abstractmethod
2
  from typing import Any, Dict, List, Union
3
 
@@ -184,26 +185,25 @@ class CodeTask(TaskComponent):
184
  {code_prompt}
185
 
186
  Do't save anything to disk. Instead, the function should return the necessary data.
187
- Include all the necessary imports.
188
  """,
189
  }
190
  ],
191
  temperature=0,
192
  )
193
 
194
- parsed_output = json.loads(
195
- ai.llm.next(
196
- [
197
- {
198
- "role": "user",
199
- "content": f"""
200
  The following text should have a python function with some imports that might need to be installed:
201
  {raw_prompt_output}
202
 
203
- Extract all the python packages that need to be installed with pip.
204
- Also extract the function and the imports as a single python script.
205
 
206
- Write a JSON as follows:
207
  ```
208
  {{
209
  "packages": Python list of packages to be parsed with eval(). If no packages, the list should be empty.
@@ -211,12 +211,18 @@ class CodeTask(TaskComponent):
211
  }}
212
  ```
213
  """,
214
- }
215
- ],
216
- temperature=0,
217
- )
 
 
218
  )
219
  except Exception as e:
 
 
 
 
220
  error_message = gr.HighlightedText.update(
221
  value=[(str(e), "ERROR")], visible=True
222
  )
@@ -224,7 +230,7 @@ class CodeTask(TaskComponent):
224
  return (
225
  raw_prompt_output,
226
  parsed_output["packages"],
227
- parsed_output["script"],
228
  error_message,
229
  accordion,
230
  )
 
1
+ import re
2
  from abc import ABC, abstractmethod
3
  from typing import Any, Dict, List, Union
4
 
 
185
  {code_prompt}
186
 
187
  Do't save anything to disk. Instead, the function should return the necessary data.
188
+ Include all the necessary imports. Make sure that the package names are correct.
189
  """,
190
  }
191
  ],
192
  temperature=0,
193
  )
194
 
195
+ raw_parsed_output = ai.llm.next(
196
+ [
197
+ {
198
+ "role": "user",
199
+ "content": f"""
 
200
  The following text should have a python function with some imports that might need to be installed:
201
  {raw_prompt_output}
202
 
203
+ Extract all the python packages that need to be installed with pip, nothing else.
204
+ Extract the function and the imports as a single python script, nothing else.
205
 
206
+ Write a JSON:
207
  ```
208
  {{
209
  "packages": Python list of packages to be parsed with eval(). If no packages, the list should be empty.
 
211
  }}
212
  ```
213
  """,
214
+ }
215
+ ],
216
+ temperature=0,
217
+ )
218
+ parsed_output = json.loads(
219
+ re.search("({.*})", raw_parsed_output, re.DOTALL).group(1)
220
  )
221
  except Exception as e:
222
+ import traceback
223
+
224
+ print(str(e))
225
+ print(traceback.format_exc())
226
  error_message = gr.HighlightedText.update(
227
  value=[(str(e), "ERROR")], visible=True
228
  )
 
230
  return (
231
  raw_prompt_output,
232
  parsed_output["packages"],
233
+ parsed_output["script"].replace("```python", "").replace("```", ""),
234
  error_message,
235
  accordion,
236
  )