Spaces:
Sleeping
Sleeping
Essi
commited on
Commit
·
2f99f18
1
Parent(s):
315ed41
perf: enhance search functionality and update prompt guidelines for clarity
Browse files- app.py +5 -3
- prompts.yaml +15 -9
- tools.py +11 -6
app.py
CHANGED
@@ -138,12 +138,14 @@ def gather_context(state: AgentState) -> AgentState:
|
|
138 |
if matched_obj:
|
139 |
url = matched_obj[0]
|
140 |
state["context"] = youtube_transcript.invoke({"url": url})
|
141 |
-
|
142 |
-
print("[TOOL]
|
143 |
search_json = web_multi_search.invoke({"query": question})
|
144 |
wiki_text = wiki_search.invoke({"query": question})
|
145 |
state["context"] = f"{search_json}\n\n{wiki_text}"
|
146 |
-
|
|
|
|
|
147 |
return state
|
148 |
|
149 |
|
|
|
138 |
if matched_obj:
|
139 |
url = matched_obj[0]
|
140 |
state["context"] = youtube_transcript.invoke({"url": url})
|
141 |
+
elif label == "search":
|
142 |
+
print("[TOOL] web search")
|
143 |
search_json = web_multi_search.invoke({"query": question})
|
144 |
wiki_text = wiki_search.invoke({"query": question})
|
145 |
state["context"] = f"{search_json}\n\n{wiki_text}"
|
146 |
+
else:
|
147 |
+
print("[TOOL] reasoning only (no search)")
|
148 |
+
state["context"] = ""
|
149 |
return state
|
150 |
|
151 |
|
prompts.yaml
CHANGED
@@ -8,13 +8,19 @@ router: |
|
|
8 |
|
9 |
Guidelines
|
10 |
----------
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
~~~
|
20 |
User question:
|
@@ -46,8 +52,8 @@ excel_system: |
|
|
46 |
|
47 |
Context
|
48 |
-------
|
49 |
-
|
50 |
-
|
51 |
|
52 |
Preview
|
53 |
-------
|
|
|
8 |
|
9 |
Guidelines
|
10 |
----------
|
11 |
+
- **math**: the question is a pure arithmetic/numeric expression.
|
12 |
+
- **youtube**: the question contains a YouTube URL and asks about its content.
|
13 |
+
- **code**: the task references attached Python code; caller wants its output.
|
14 |
+
- **excel**: the task references an attached .xlsx/.xls/.csv and asks for a sum, average, etc.
|
15 |
+
- **audio**: the task references an attached audio file and asks for its transcript or facts in it.
|
16 |
+
- **image**: the task could be either generic like "what is in the picture (e.g. Which animal is shown?) or could be a puzzle like asking for a *move, count, coordinate,* or other board-game tactic that needs an exact piece layout (e.g. "What is Black's winning move?").
|
17 |
+
- **search** : needs external factual information from the web
|
18 |
+
- **reason** : answer can be produced by analyzing the question text alone
|
19 |
+
|
20 |
+
Examples
|
21 |
+
----------
|
22 |
+
(search) What is the last name of the person who founded Mercedes Benz company?
|
23 |
+
(reasoning) what is the third item of following list that is a fruit after sorting it alphabetically: ['parsley', 'orange', 'apple', 'coriander', 'lettuce', 'kiwi', 'apricot']" Answer is 'kiwi'
|
24 |
|
25 |
~~~
|
26 |
User question:
|
|
|
52 |
|
53 |
Context
|
54 |
-------
|
55 |
+
- A full DataFrame named `df` is already loaded.
|
56 |
+
- Only the preview below is shown for reference; use column names from it.
|
57 |
|
58 |
Preview
|
59 |
-------
|
tools.py
CHANGED
@@ -87,17 +87,22 @@ def web_multi_search(query: str, k: int = 6) -> str:
|
|
87 |
pass
|
88 |
|
89 |
try:
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
91 |
print(
|
92 |
-
f"[TOOL] TAVILY search is triggered with following response: {
|
93 |
)
|
94 |
formatted = [
|
95 |
{
|
96 |
-
"title": d.
|
97 |
-
"snippet": d.
|
98 |
-
"link": d.
|
99 |
}
|
100 |
-
for d in
|
101 |
]
|
102 |
return json.dumps(formatted, ensure_ascii=False)
|
103 |
except Exception as exc:
|
|
|
87 |
pass
|
88 |
|
89 |
try:
|
90 |
+
tavily_results = TavilySearchResults(
|
91 |
+
max_results=5,
|
92 |
+
# include_answer=True,
|
93 |
+
# search_depth="advanced",
|
94 |
+
)
|
95 |
+
search_result = tavily_results.invoke({"query": query})
|
96 |
print(
|
97 |
+
f"[TOOL] TAVILY search is triggered with following response: {search_result}"
|
98 |
)
|
99 |
formatted = [
|
100 |
{
|
101 |
+
"title": d.get("title", "")[:500],
|
102 |
+
"snippet": d.get("content", "")[:750],
|
103 |
+
"link": d.get("url", "")[:300],
|
104 |
}
|
105 |
+
for d in search_result
|
106 |
]
|
107 |
return json.dumps(formatted, ensure_ascii=False)
|
108 |
except Exception as exc:
|