Denis Davydov commited on
Commit ·
913cae8
1
Parent(s): 52ee323
use bing as search engine
Browse files11 unmodified lines1213141516171870 unmodified lines89909192939495969711 unmodified linesfrom langgraph.prebuilt import tools_conditionfrom langchain_openai import ChatOpenAIfrom tools import agent_toolsfrom utils import format_gaia_answer, create_execution_plan, log_agent_step# Initialize OpenAI LLM with GPT-4o (most capable model)chat = ChatOpenAI(70 unmodified linestry:print(f"\n🎯 Processing question: {question[:100]}...")plan = create_execution_plan(question, task_id)print(f"📋 Execution plan: {plan}")enhanced_question = questionif task_id:enhanced_question = f"Task ID: {task_id}\n\nQuestion: {question}"11 unmodified lines1213141516171870 unmodified lines89909192939411 unmodified linesfrom langgraph.prebuilt import tools_conditionfrom langchain_openai import ChatOpenAIfrom tools import agent_toolsfrom utils import format_gaia_answer, log_agent_step# Initialize OpenAI LLM with GPT-4o (most capable model)chat = ChatOpenAI(70 unmodified linestry:print(f"\n🎯 Processing question: {question[:100]}...")enhanced_question = questionif task_id:enhanced_question = f"Task ID: {task_id}\n\nQuestion: {question}"
181 unmodified lines182183184185186187188189190191192193194195196197198199200201202203204181 unmodified linestry:with DDGS() as ddgs:# Create Wikipedia-specific search querieswikipedia_queries = [f"site:en.wikipedia.org {query}",f"{query} site:en.wikipedia.org"]search_results = []seen_urls = set()for wiki_query in wikipedia_queries:try:results = list(ddgs.text(wiki_query, max_results=2))for result in results:url = result.get('href', '')# Only include Wikipedia URLs and avoid duplicatesif 'en.wikipedia.org' in url and url not in seen_urls:search_results.append({'url': url,'title': result.get('title', 'No title'),181 unmodified lines182183184185186187188189190191192193194195196197198199200201202181 unmodified linestry:with DDGS() as ddgs:# Create Wikipedia-specific search queriesqueries = [f"{query} site:en.wikipedia.org"]search_results = []seen_urls = set()for wiki_query in queries:try:results = list(ddgs.text(wiki_query, max_results=10, region="us-en", backend="bing", safesearch="on"))for result in results:url = result.get('href', '')if url not in seen_urls:search_results.append({'url': url,'title': result.get('title', 'No title'),
83 unmodified lines8485868788899091929394959697989910010110210310410510683 unmodified linesreturn answerdef create_execution_plan(question: str, task_id: str = None) -> List[str]:"""Create a simple execution plan - let GPT-4o decide what tools to use."""plan = []# Always start with understanding the questionplan.append("Analyze the question to understand what information is needed")# Add file processing if task_id is providedif task_id:plan.append(f"Check for and process any files associated with task {task_id}")# Let the LLM decide what other tools to useplan.append("Use appropriate tools (web search, calculations, etc.) as needed")plan.append("Synthesize all information to provide the final answer")return plandef log_agent_step(step: str, result: str, step_number: int = None):"""Log agent execution steps for debugging."""prefix = f"Step {step_number}: " if step_number else ""83 unmodified lines84858687888983 unmodified linesreturn answerdef log_agent_step(step: str, result: str, step_number: int = None):"""Log agent execution steps for debugging."""prefix = f"Step {step_number}: " if step_number else ""
agent.py+1-4
tools.py+4-6
utils.py-17