Spaces:
Build error
Build error
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -20,7 +20,11 @@ class Agent:
|
|
| 20 |
prompt: Optional[str] = None,
|
| 21 |
):
|
| 22 |
logger.info("Initializing Agent")
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
self.tools = tools
|
| 25 |
self.imports = [
|
| 26 |
"pandas",
|
|
@@ -41,35 +45,26 @@ class Agent:
|
|
| 41 |
add_base_tools=True,
|
| 42 |
additional_authorized_imports=self.imports,
|
| 43 |
)
|
|
|
|
| 44 |
self.prompt = prompt or (
|
| 45 |
-
"""
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
- Use code if needed. For calculations, parsing, or transformations, generate Python code and execute it. But be careful, some questions contains time-consuming tasks, so you should be careful with the code you run. Better analyze the question and think about the best way to solve it.
|
| 54 |
-
IMPORTANT: When giving the final answer, output only the direct required result without any extra text like "Final Answer:" or explanations. YOU MUST RESPOND IN THE EXACT FORMAT AS THE QUESTION.
|
| 55 |
QUESTION: {question}
|
| 56 |
-
|
| 57 |
-
ANSWER:
|
| 58 |
-
"""
|
| 59 |
)
|
| 60 |
logger.info("Agent initialized")
|
| 61 |
|
| 62 |
def __call__(self, question: str, file_path: Optional[str] = None) -> str:
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
Args:
|
| 66 |
-
question (str): The question to answer.
|
| 67 |
-
file_path (Optional[str]): Path to a file to use as context (if any).
|
| 68 |
-
Returns:
|
| 69 |
-
str: The agent's answer as a string.
|
| 70 |
-
"""
|
| 71 |
answer = self.agent.run(
|
| 72 |
-
self.prompt.format(question=question, context=
|
| 73 |
)
|
| 74 |
-
|
| 75 |
-
return answer
|
|
|
|
| 20 |
prompt: Optional[str] = None,
|
| 21 |
):
|
| 22 |
logger.info("Initializing Agent")
|
| 23 |
+
# Verify correct parameter name for the inference client (e.g. api_provider)
|
| 24 |
+
self.model = InferenceClientModel(
|
| 25 |
+
model_id="deepseek-ai/DeepSeek-R1",
|
| 26 |
+
api_provider="together" # Changed parameter to api_provider
|
| 27 |
+
)
|
| 28 |
self.tools = tools
|
| 29 |
self.imports = [
|
| 30 |
"pandas",
|
|
|
|
| 45 |
add_base_tools=True,
|
| 46 |
additional_authorized_imports=self.imports,
|
| 47 |
)
|
| 48 |
+
# Improved prompt with clearer context handling instructions
|
| 49 |
self.prompt = prompt or (
|
| 50 |
+
"""You are an advanced AI assistant specialized in solving complex tasks using tools.
|
| 51 |
+
|
| 52 |
+
Key Instructions:
|
| 53 |
+
1. ALWAYS use tools for file paths in the context:
|
| 54 |
+
- Use read_file for text files
|
| 55 |
+
- Use extract_text_from_image for images (.png, .jpg)
|
| 56 |
+
2. Final answer must ONLY contain the requested result in the EXACT format needed.
|
| 57 |
+
|
|
|
|
|
|
|
| 58 |
QUESTION: {question}
|
| 59 |
+
{context}
|
| 60 |
+
ANSWER:"""
|
|
|
|
| 61 |
)
|
| 62 |
logger.info("Agent initialized")
|
| 63 |
|
| 64 |
def __call__(self, question: str, file_path: Optional[str] = None) -> str:
|
| 65 |
+
# Handle context more cleanly
|
| 66 |
+
context = f"CONTEXT: File available at: {file_path}" if file_path else ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
answer = self.agent.run(
|
| 68 |
+
self.prompt.format(question=question, context=context)
|
| 69 |
)
|
| 70 |
+
return str(answer).strip("'").strip('"').strip()
|
|
|