Spaces:
Runtime error
Runtime error
Update tools.py
Browse files
tools.py
CHANGED
@@ -13,6 +13,10 @@ openai.api_key = os.getenv("OPENAI_API_KEY")
|
|
13 |
|
14 |
SYSTEM_PROMPT = """You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template:
|
15 |
FINAL ANSWER: [YOUR FINAL ANSWER].
|
|
|
|
|
|
|
|
|
16 |
YOUR FINAL ANSWER should be:
|
17 |
- a number OR as few words as possible OR a comma separated list of numbers and/or strings.
|
18 |
- If you are asked for a number, don't use commas, symbols or units (e.g. %, $, km) unless explicitly asked.
|
@@ -64,7 +68,7 @@ class SpeechToTextTool(PipelineTool):
|
|
64 |
model="whisper-1",
|
65 |
response_format="text"
|
66 |
)
|
67 |
-
return response
|
68 |
|
69 |
class ExcelToTextTool(Tool):
|
70 |
"""Renders an Excel worksheet as Markdown text."""
|
@@ -80,8 +84,9 @@ class ExcelToTextTool(Tool):
|
|
80 |
path = Path(excel_path).expanduser().resolve()
|
81 |
if not path.exists():
|
82 |
return f"Error: Excel file not found at {path}"
|
83 |
-
|
84 |
-
|
|
|
85 |
df = pd.read_excel(path, sheet_name=sheet)
|
86 |
if hasattr(df, "to_markdown"):
|
87 |
return df.to_markdown(index=False)
|
|
|
13 |
|
14 |
SYSTEM_PROMPT = """You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template:
|
15 |
FINAL ANSWER: [YOUR FINAL ANSWER].
|
16 |
+
|
17 |
+
If you have enough confidence (≥70%) in your internal knowledge, answer directly without calling any other tool.
|
18 |
+
Otherwise, decide which tool (wiki, web search, python, audio, excel) is best and use it.
|
19 |
+
|
20 |
YOUR FINAL ANSWER should be:
|
21 |
- a number OR as few words as possible OR a comma separated list of numbers and/or strings.
|
22 |
- If you are asked for a number, don't use commas, symbols or units (e.g. %, $, km) unless explicitly asked.
|
|
|
68 |
model="whisper-1",
|
69 |
response_format="text"
|
70 |
)
|
71 |
+
return response
|
72 |
|
73 |
class ExcelToTextTool(Tool):
|
74 |
"""Renders an Excel worksheet as Markdown text."""
|
|
|
84 |
path = Path(excel_path).expanduser().resolve()
|
85 |
if not path.exists():
|
86 |
return f"Error: Excel file not found at {path}"
|
87 |
+
sheet = 0 if not sheet_name or sheet_name == "" else (
|
88 |
+
int(sheet_name) if sheet_name.isdigit() else sheet_name
|
89 |
+
)
|
90 |
df = pd.read_excel(path, sheet_name=sheet)
|
91 |
if hasattr(df, "to_markdown"):
|
92 |
return df.to_markdown(index=False)
|