Spaces:
Runtime error
Runtime error
Update tools.py
Browse files
tools.py
CHANGED
|
@@ -3,6 +3,7 @@
|
|
| 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.
|
|
@@ -12,6 +13,18 @@ def clean_answer_with_prompt(agent_output: str) -> str:
|
|
| 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 |
"""
|
|
@@ -38,18 +51,4 @@ def greeting_tool(name: str) -> str:
|
|
| 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:"
|
|
|
|
| 3 |
from smolagents import tool
|
| 4 |
from retriever import retrieve_relevant_context
|
| 5 |
|
| 6 |
+
|
| 7 |
def clean_answer_with_prompt(agent_output: str) -> str:
|
| 8 |
"""
|
| 9 |
Extracts and cleans the final answer from the agent output.
|
|
|
|
| 13 |
return agent_output.split("FINAL ANSWER:")[-1].strip()
|
| 14 |
return agent_output.strip()
|
| 15 |
|
| 16 |
+
def build_prompt(question: str, context: str) -> str:
|
| 17 |
+
"""
|
| 18 |
+
Combine the system instruction, context, and question to build the LLM prompt.
|
| 19 |
+
"""
|
| 20 |
+
system_instruction = (
|
| 21 |
+
"You are an intelligent assistant helping answer complex real-world questions. "
|
| 22 |
+
"Use the provided context to reason and provide a concise factual answer. "
|
| 23 |
+
"Only answer what is asked. Do not include 'FINAL ANSWER:' or extra explanation.\n\n"
|
| 24 |
+
)
|
| 25 |
+
return f"{system_instruction}Context:\n{context}\n\nQuestion: {question}\nAnswer:"
|
| 26 |
+
|
| 27 |
+
|
| 28 |
@tool
|
| 29 |
def guest_info_tool(name: str) -> str:
|
| 30 |
"""
|
|
|
|
| 51 |
"""
|
| 52 |
return f"Welcome to the gala, {name}! We're honored to have you with us."
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|