JatinAutonomousLabs commited on
Commit
da63e19
·
verified ·
1 Parent(s): e386094

Update graph.py

Browse files
Files changed (1) hide show
  1. graph.py +50 -36
graph.py CHANGED
@@ -24,6 +24,20 @@ from docx import Document
24
  from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer
25
  from reportlab.lib.styles import getSampleStyleSheet
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  # --- Configuration ---
28
  OUT_DIR = os.environ.get("OUT_DIR", "/tmp")
29
  os.makedirs(OUT_DIR, exist_ok=True)
@@ -220,23 +234,23 @@ def parse_json_from_llm(llm_output: str) -> Optional[dict]:
220
  # --- Artifact detection ---
221
  KNOWN_ARTIFACT_TYPES = {"notebook","excel","word","pdf","image","repo","script"}
222
 
223
- def detect_requested_output_types(text: str) -> Dict:
224
- if not text:
225
- return {"requires_artifact": False, "artifact_type": None, "artifact_hint": None}
226
- t = text.lower()
227
- if any(k in t for k in ["jupyter notebook", "jupyter", "notebook", "ipynb"]):
228
- return {"requires_artifact": True, "artifact_type": "notebook", "artifact_hint": "jupyter notebook"}
229
- if any(k in t for k in ["excel", ".xlsx", "spreadsheet", "csv"]):
230
- return {"requires_artifact": True, "artifact_type": "excel", "artifact_hint": "Excel file"}
231
- if any(k in t for k in ["word document", ".docx", "docx"]):
232
- return {"requires_artifact": True, "artifact_type": "word", "artifact_hint": "Word document"}
233
- if any(k in t for k in ["pdf", "pdf file"]):
234
- return {"requires_artifact": True, "artifact_type": "pdf", "artifact_hint": "PDF document"}
235
- if any(k in t for k in ["repo", "repository", "app repo", "backend", "codebase"]):
236
- return {"requires_artifact": True, "artifact_type": "repo", "artifact_hint": "application repository"}
237
- if any(k in t for k in [".py", "python script", "script"]):
238
- return {"requires_artifact": True, "artifact_type": "script", "artifact_hint": "Python script"}
239
- return {"requires_artifact": False, "artifact_type": None, "artifact_hint": None}
240
 
241
  def normalize_experiment_type(exp_type: Optional[str], goal_text: str) -> str:
242
  if not exp_type:
@@ -284,25 +298,25 @@ def write_notebook_from_text(llm_text: str, out_dir: Optional[str]=None) -> str:
284
  nbformat.write(nb, filename)
285
  return filename
286
 
287
- def write_script(code_text: str, language_hint: Optional[str]=None, out_dir: Optional[str]=None) -> str:
288
- out_dir = out_dir or OUT_DIR
289
- os.makedirs(out_dir, exist_ok=True)
290
- ext = ".txt"
291
- if language_hint:
292
- l = language_hint.lower()
293
- if "python" in l:
294
- ext = ".py"
295
- elif "r" in l:
296
- ext = ".R"
297
- elif "java" in l:
298
- ext = ".java"
299
- elif "javascript" in l:
300
- ext = ".js"
301
- uid = uuid.uuid4().hex[:10]
302
- filename = os.path.join(out_dir, f"generated_script_{uid}{ext}")
303
- with open(filename, "w", encoding="utf-8") as f:
304
- f.write(code_text)
305
- return filename
306
 
307
  def write_docx_from_text(text: str, out_dir: Optional[str]=None) -> str:
308
  out_dir = out_dir or OUT_DIR
 
24
  from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer
25
  from reportlab.lib.styles import getSampleStyleSheet
26
 
27
+ # Add after other imports
28
+ from multi_language_support import (
29
+ detect_language,
30
+ extract_code_blocks_multi_lang,
31
+ execute_code,
32
+ detect_requested_output_types_enhanced,
33
+ write_script_multi_lang,
34
+ LANGUAGES
35
+ )
36
+
37
+ # Replace existing functions
38
+ detect_requested_output_types = detect_requested_output_types_enhanced
39
+ write_script = write_script_multi_lang
40
+
41
  # --- Configuration ---
42
  OUT_DIR = os.environ.get("OUT_DIR", "/tmp")
43
  os.makedirs(OUT_DIR, exist_ok=True)
 
234
  # --- Artifact detection ---
235
  KNOWN_ARTIFACT_TYPES = {"notebook","excel","word","pdf","image","repo","script"}
236
 
237
+ #def detect_requested_output_types(text: str) -> Dict:
238
+ # if not text:
239
+ # return {"requires_artifact": False, "artifact_type": None, "artifact_hint": None}
240
+ # t = text.lower()
241
+ # if any(k in t for k in ["jupyter notebook", "jupyter", "notebook", "ipynb"]):
242
+ # return {"requires_artifact": True, "artifact_type": "notebook", "artifact_hint": "jupyter notebook"}
243
+ # if any(k in t for k in ["excel", ".xlsx", "spreadsheet", "csv"]):
244
+ # return {"requires_artifact": True, "artifact_type": "excel", "artifact_hint": "Excel file"}
245
+ # if any(k in t for k in ["word document", ".docx", "docx"]):
246
+ # return {"requires_artifact": True, "artifact_type": "word", "artifact_hint": "Word document"}
247
+ # if any(k in t for k in ["pdf", "pdf file"]):
248
+ # return {"requires_artifact": True, "artifact_type": "pdf", "artifact_hint": "PDF document"}
249
+ # if any(k in t for k in ["repo", "repository", "app repo", "backend", "codebase"]):
250
+ # return {"requires_artifact": True, "artifact_type": "repo", "artifact_hint": "application repository"}
251
+ # if any(k in t for k in [".py", "python script", "script"]):
252
+ # return {"requires_artifact": True, "artifact_type": "script", "artifact_hint": "Python script"}
253
+ # return {"requires_artifact": False, "artifact_type": None, "artifact_hint": None}
254
 
255
  def normalize_experiment_type(exp_type: Optional[str], goal_text: str) -> str:
256
  if not exp_type:
 
298
  nbformat.write(nb, filename)
299
  return filename
300
 
301
+ #def write_script(code_text: str, language_hint: Optional[str]=None, out_dir: Optional[str]=None) -> str:
302
+ # out_dir = out_dir or OUT_DIR
303
+ # os.makedirs(out_dir, exist_ok=True)
304
+ # ext = ".txt"
305
+ # if language_hint:
306
+ # l = language_hint.lower()
307
+ # if "python" in l:
308
+ # ext = ".py"
309
+ # elif "r" in l:
310
+ # ext = ".R"
311
+ # elif "java" in l:
312
+ # ext = ".java"
313
+ # elif "javascript" in l:
314
+ # ext = ".js"
315
+ # uid = uuid.uuid4().hex[:10]
316
+ # filename = os.path.join(out_dir, f"generated_script_{uid}{ext}")
317
+ # with open(filename, "w", encoding="utf-8") as f:
318
+ # f.write(code_text)
319
+ # return filename
320
 
321
  def write_docx_from_text(text: str, out_dir: Optional[str]=None) -> str:
322
  out_dir = out_dir or OUT_DIR