Spaces:
Sleeping
Sleeping
Mudança para Invoke
Browse files
agent.py
CHANGED
@@ -44,7 +44,7 @@ class Agent:
|
|
44 |
|
45 |
|
46 |
|
47 |
-
def
|
48 |
print(f"Agent received question({task_id}) (first 50 chars): {question[:50]}...")
|
49 |
|
50 |
file_prefix = ""
|
@@ -74,4 +74,37 @@ class Agent:
|
|
74 |
final_answer = re.sub(r"^FINAL ANSWER:\s*", "", agent_answer, flags=re.IGNORECASE)
|
75 |
print(f"Agent returning answer for task {task_id}: {final_answer}")
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
return final_answer
|
|
|
44 |
|
45 |
|
46 |
|
47 |
+
def _call_antiga(self, question: str, task_id: str, task_file_name: str) -> str:
|
48 |
print(f"Agent received question({task_id}) (first 50 chars): {question[:50]}...")
|
49 |
|
50 |
file_prefix = ""
|
|
|
74 |
final_answer = re.sub(r"^FINAL ANSWER:\s*", "", agent_answer, flags=re.IGNORECASE)
|
75 |
print(f"Agent returning answer for task {task_id}: {final_answer}")
|
76 |
|
77 |
+
return final_answer
|
78 |
+
|
79 |
+
|
80 |
+
def __call__(self, question: str, task_id: str, task_file_name: str) -> str:
|
81 |
+
print(f"Agent (nova forma de invocar) received question({task_id}) (first 50 chars): {question[:50]}...")
|
82 |
+
|
83 |
+
file_prefix = ""
|
84 |
+
if task_file_name:
|
85 |
+
print(f"Task com arquivo {task_file_name}")
|
86 |
+
File_Util.baixa_arquivo_task(task_file_name)
|
87 |
+
file_prefix = f"File: {task_file_name} . "
|
88 |
+
|
89 |
+
# Chamando sem stream
|
90 |
+
response = self.supervisor.invoke(
|
91 |
+
{
|
92 |
+
"messages": [
|
93 |
+
{
|
94 |
+
"role": "user",
|
95 |
+
"content": f"{file_prefix}{question}",
|
96 |
+
}
|
97 |
+
]
|
98 |
+
}
|
99 |
+
)
|
100 |
+
|
101 |
+
messages = response.get("supervisor", {}).get("messages", [])
|
102 |
+
if not messages:
|
103 |
+
print(f"Nenhuma mensagem retornada para task {task_id}.")
|
104 |
+
return "Desculpe, não houve resposta."
|
105 |
+
|
106 |
+
last_msg = messages[-1]["content"]
|
107 |
+
final_answer = re.sub(r"^FINAL ANSWER:\s*", "", last_msg.strip(), flags=re.IGNORECASE)
|
108 |
+
print(f"Agent returning answer for task {task_id}: {final_answer}")
|
109 |
+
|
110 |
return final_answer
|