Spaces:
Sleeping
Sleeping
EtienneB commited on
Commit ·
0bb6942
1
Parent(s): 6044144
updates
Browse files4 unmodified lines56789101142 unmodified lines545556575859604 unmodified linesimport pandas as pdimport requests# Additional librariesfrom langchain_core.messages import HumanMessagefrom agent import build_graph42 unmodified lines# The answer is expected to be in the 'content' of the last message.answer = response_messages['messages'][-1].contentprint(f"Agent full response: {answer}")return answer4 unmodified lines56789101142 unmodified lines54555657585960616263646566676869707172737475767778798081828384858687884 unmodified linesimport pandas as pdimport requests# Additional librariesfrom langchain_core.messages import AIMessage, HumanMessagefrom agent import build_graph42 unmodified lines# The answer is expected to be in the 'content' of the last message.answer = response_messages['messages'][-1].contentprint(f"Agent full response: {answer}")final_answer = ""if not messages:print(f"No messages found in the result state for task {task_id}.")return "AGENT ERROR: No messages returned by the agent."for msg in reversed(messages):if hasattr(msg, "content") and msg.content:content = msg.contentif isinstance(content, str):if "FINAL ANSWER:" in content:final_answer = content.split("FINAL ANSWER:", 1)[1].strip()breakelif isinstance(msg, AIMessage):# If it's an AIMessage and no "FINAL ANSWER:" has been found yet,# tentatively set it. This will be overridden if a "FINAL ANSWER:" is found later.if not final_answer:final_answer = content# If after checking all messages, final_answer is still from a non-"FINAL ANSWER:" AIMessage, that's our best guess.# If final_answer is empty, it means no AIMessage with content or "FINAL ANSWER:" was found.if not final_answer: # This means no "FINAL ANSWER:" and no AIMessage content was suitablefinal_answer = "AGENT ERROR: Could not extract a final answer from the agent's messages."print(f"Could not extract final answer for task {task_id}. Messages: {messages}")print(f"FinalAgent returning answer for task_id '{task_id}': {final_answer[:100]}...")return final_answer# return answer
9 unmodified lines1011121314151617181920219 unmodified linesimport pytzimport torchfrom bs4 import BeautifulSoupfrom langchain.schema import HumanMessagefrom langchain_community.document_loaders import (ArxivLoader, AssemblyAIAudioTranscriptLoader, WikipediaLoader)from langchain_community.document_loaders.generic import GenericLoaderfrom langchain_community.document_loaders.parsers import LanguageParserfrom langchain_community.tools import DuckDuckGoSearchRunfrom langchain_core.tools import toolfrom langchain_google_genai import ChatGoogleGenerativeAIfrom langchain_tavily import TavilySearch9 unmodified lines1011121314151617181920219 unmodified linesimport pytzimport torchfrom bs4 import BeautifulSoupfrom langchain_community.document_loaders import (ArxivLoader, AssemblyAIAudioTranscriptLoader, WikipediaLoader)from langchain_community.document_loaders.generic import GenericLoaderfrom langchain_community.document_loaders.parsers import LanguageParserfrom langchain_core.messages import HumanMessage# from langchain_community.tools import DuckDuckGoSearchRunfrom langchain_core.tools import toolfrom langchain_google_genai import ChatGoogleGenerativeAIfrom langchain_tavily import TavilySearch
app.py+30-2
tools.py+2-2