refactor : message for status

This commit is contained in:
martin legrand 2025-04-18 18:31:11 +02:00
parent 5ac7df1854
commit 0f09ef92dd
6 changed files with 33 additions and 15 deletions

2
api.py
View File

@ -175,7 +175,7 @@ async def process_query(request: QueryRequest):
agent_name="Unknown",
success="false",
blocks={},
status="No agent working.",
status="Agent working...",
timestamp=str(time.time())
)
if is_generating:

View File

@ -14,13 +14,15 @@ function App() {
const messagesEndRef = useRef(null);
useEffect(() => {
const intervalId = setInterval(() => {
checkHealth();
fetchLatestAnswer();
fetchScreenshot();
}, 1500);
return () => clearInterval(intervalId);
}, [messages]);
if (!isLoading) {
const intervalId = setInterval(() => {
checkHealth();
fetchLatestAnswer();
fetchScreenshot();
}, 1500);
return () => clearInterval(intervalId);
}
}, [isLoading, messages]);
const checkHealth = async () => {
try {
@ -71,21 +73,35 @@ function App() {
try {
const res = await axios.get('http://0.0.0.0:8000/latest_answer');
const data = res.data;
if (!data.answer || data.answer.trim() === '') {
return;
}
const answerExists = messages.some(
(msg) => msg.timestamp === data.timestamp || data.answer === undefined
(msg) =>
msg.timestamp === data.timestamp &&
normalizeAnswer(msg.content) === normalizeAnswer(data.answer)
);
console.log('Fetched latest answer:', data.answer);
if (!answerExists) {
setMessages((prev) => [
...prev,
{ type: 'agent', content: data.answer, agentName: data.agent_name, status: data.status, timestamp: data.timestamp },
{
type: 'agent',
content: data.answer,
agentName: data.agent_name,
status: data.status,
timestamp: data.timestamp,
},
]);
setStatus(data.status);
scrollToBottom();
}
} catch (error) {
console.error("Error fetching latest answer:", error);
console.error('Error fetching latest answer:', error);
}
};
const handleSubmit = async (e) => {
e.preventDefault();
@ -100,10 +116,12 @@ function App() {
try {
console.log('Sending query:', query);
setQuery('waiting for response...');
const res = await axios.post('http://0.0.0.0:8000/query', {
query,
tts_enabled: false
});
setQuery('Enter your query...');
console.log('Response:', res.data);
const data = res.data;
setResponseData(data);

View File

@ -372,7 +372,7 @@ class BrowserAgent(Agent):
self.status_message = "Summarizing findings..."
answer, reasoning = await self.llm_request()
pretty_print(answer, color="output")
self.status_message = "Done"
self.status_message = "Ready"
return answer, reasoning
if __name__ == "__main__":

View File

@ -23,7 +23,7 @@ class CasualAgent(Agent):
animate_thinking("Thinking...", color="status")
answer, reasoning = await self.llm_request()
self.last_answer = answer
self.status_message = "Done"
self.status_message = "Ready"
return answer, reasoning
if __name__ == "__main__":

View File

@ -69,7 +69,7 @@ class CoderAgent(Agent):
self.status_message = "Correcting code..."
self.show_answer()
attempt += 1
self.status_message = "Done"
self.status_message = "Ready"
if attempt == max_attempts:
return "I'm sorry, I couldn't find a solution to your problem. How would you like me to proceed ?", reasoning
return answer, reasoning

View File

@ -30,7 +30,7 @@ class FileAgent(Agent):
exec_success, _ = self.execute_modules(answer)
answer = self.remove_blocks(answer)
self.last_answer = answer
self.status_message = "Done"
self.status_message = "Ready"
return answer, reasoning
if __name__ == "__main__":