Spaces:
Runtime error
Runtime error
Update tools.py
Browse files
tools.py
CHANGED
@@ -1,55 +1,55 @@
|
|
1 |
-
# tools.py
|
2 |
-
|
3 |
-
from smolagents import tool
|
4 |
-
from retriever import
|
5 |
-
|
6 |
-
def clean_answer_with_prompt(agent_output: str) -> str:
|
7 |
-
"""
|
8 |
-
Extracts and cleans the final answer from the agent output.
|
9 |
-
For GAIA, ensure no 'FINAL ANSWER:' prefix is returned — just the answer.
|
10 |
-
"""
|
11 |
-
if "FINAL ANSWER:" in agent_output:
|
12 |
-
return agent_output.split("FINAL ANSWER:")[-1].strip()
|
13 |
-
return agent_output.strip()
|
14 |
-
|
15 |
-
@tool
|
16 |
-
def guest_info_tool(name: str) -> str:
|
17 |
-
"""
|
18 |
-
Retrieves background info about a guest using the document store.
|
19 |
-
|
20 |
-
Args:
|
21 |
-
name (str): The name of the guest to retrieve context for.
|
22 |
-
|
23 |
-
Returns:
|
24 |
-
str: Relevant background information from the document store.
|
25 |
-
"""
|
26 |
-
return
|
27 |
-
|
28 |
-
@tool
|
29 |
-
def greeting_tool(name: str) -> str:
|
30 |
-
"""
|
31 |
-
Generates a custom greeting for the guest.
|
32 |
-
|
33 |
-
Args:
|
34 |
-
name (str): The name of the guest to greet.
|
35 |
-
|
36 |
-
Returns:
|
37 |
-
str: A friendly greeting message.
|
38 |
-
"""
|
39 |
-
return f"Welcome to the gala, {name}! We're honored to have you with us."
|
40 |
-
|
41 |
-
def build_prompt(question: str, context: str = "") -> str:
|
42 |
-
"""
|
43 |
-
Constructs a prompt for the agent using a question and optional context.
|
44 |
-
|
45 |
-
Args:
|
46 |
-
question (str): The user query to be answered.
|
47 |
-
context (str): Optional supporting context or retrieved documents.
|
48 |
-
|
49 |
-
Returns:
|
50 |
-
str: A formatted prompt for the LLM.
|
51 |
-
"""
|
52 |
-
if context:
|
53 |
-
return f"Here is some context: {context}\n\nQuestion: {question}\n\nAnswer:"
|
54 |
-
else:
|
55 |
-
return f"Question: {question}\n\nAnswer:"
|
|
|
1 |
+
# tools.py
|
2 |
+
|
3 |
+
from smolagents import tool
|
4 |
+
from retriever import retrieve_relevant_context
|
5 |
+
|
6 |
+
def clean_answer_with_prompt(agent_output: str) -> str:
|
7 |
+
"""
|
8 |
+
Extracts and cleans the final answer from the agent output.
|
9 |
+
For GAIA, ensure no 'FINAL ANSWER:' prefix is returned — just the answer.
|
10 |
+
"""
|
11 |
+
if "FINAL ANSWER:" in agent_output:
|
12 |
+
return agent_output.split("FINAL ANSWER:")[-1].strip()
|
13 |
+
return agent_output.strip()
|
14 |
+
|
15 |
+
@tool
|
16 |
+
def guest_info_tool(name: str) -> str:
|
17 |
+
"""
|
18 |
+
Retrieves background info about a guest using the document store.
|
19 |
+
|
20 |
+
Args:
|
21 |
+
name (str): The name of the guest to retrieve context for.
|
22 |
+
|
23 |
+
Returns:
|
24 |
+
str: Relevant background information from the document store.
|
25 |
+
"""
|
26 |
+
return retrieve_relevant_context(name)
|
27 |
+
|
28 |
+
@tool
|
29 |
+
def greeting_tool(name: str) -> str:
|
30 |
+
"""
|
31 |
+
Generates a custom greeting for the guest.
|
32 |
+
|
33 |
+
Args:
|
34 |
+
name (str): The name of the guest to greet.
|
35 |
+
|
36 |
+
Returns:
|
37 |
+
str: A friendly greeting message.
|
38 |
+
"""
|
39 |
+
return f"Welcome to the gala, {name}! We're honored to have you with us."
|
40 |
+
|
41 |
+
def build_prompt(question: str, context: str = "") -> str:
|
42 |
+
"""
|
43 |
+
Constructs a prompt for the agent using a question and optional context.
|
44 |
+
|
45 |
+
Args:
|
46 |
+
question (str): The user query to be answered.
|
47 |
+
context (str): Optional supporting context or retrieved documents.
|
48 |
+
|
49 |
+
Returns:
|
50 |
+
str: A formatted prompt for the LLM.
|
51 |
+
"""
|
52 |
+
if context:
|
53 |
+
return f"Here is some context: {context}\n\nQuestion: {question}\n\nAnswer:"
|
54 |
+
else:
|
55 |
+
return f"Question: {question}\n\nAnswer:"
|