Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -95,6 +95,43 @@ def read_task_file(file_path):
|
|
| 95 |
return df.to_string(index=False)
|
| 96 |
|
| 97 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
class BasicAgent:
|
| 100 |
def __init__(self):
|
|
|
|
| 95 |
return df.to_string(index=False)
|
| 96 |
|
| 97 |
return None
|
| 98 |
+
def extract_raw_text(output):
|
| 99 |
+
if output is None:
|
| 100 |
+
raise ValueError("Agent returned None")
|
| 101 |
+
|
| 102 |
+
if isinstance(output, str):
|
| 103 |
+
return output.strip()
|
| 104 |
+
|
| 105 |
+
if isinstance(output, (int, float)):
|
| 106 |
+
return str(output)
|
| 107 |
+
|
| 108 |
+
if isinstance(output, dict):
|
| 109 |
+
if "output" in output:
|
| 110 |
+
return extract_raw_text(output["output"])
|
| 111 |
+
|
| 112 |
+
if "content" in output:
|
| 113 |
+
return extract_raw_text(output["content"])
|
| 114 |
+
|
| 115 |
+
if "text" in output:
|
| 116 |
+
return extract_raw_text(output["text"])
|
| 117 |
+
|
| 118 |
+
raise ValueError(f"No text field in output: {output}")
|
| 119 |
+
|
| 120 |
+
if isinstance(output, list):
|
| 121 |
+
texts = []
|
| 122 |
+
|
| 123 |
+
for item in output:
|
| 124 |
+
if isinstance(item, dict) and item.get("type") not in (None, "text"):
|
| 125 |
+
continue
|
| 126 |
+
|
| 127 |
+
text = extract_raw_text(item)
|
| 128 |
+
|
| 129 |
+
if text:
|
| 130 |
+
texts.append(text)
|
| 131 |
+
|
| 132 |
+
return "\n".join(texts).strip()
|
| 133 |
+
|
| 134 |
+
raise TypeError(f"Unsupported output type: {type(output).__name__}")
|
| 135 |
|
| 136 |
class BasicAgent:
|
| 137 |
def __init__(self):
|