Fix : searxng now failing gracefully

This commit is contained in:
martin legrand 2025-03-18 12:17:41 +01:00
parent 0616f39e35
commit 372da19f30
4 changed files with 10 additions and 10 deletions

View File

@ -3,7 +3,7 @@ from sources.utility import pretty_print, animate_thinking
from sources.agents.agent import Agent
from sources.agents.code_agent import CoderAgent
from sources.agents.file_agent import FileAgent
from sources.agents.casual_agent import CasualAgent
from sources.agents.browser_agent import BrowserAgent
from sources.tools.tools import Tools
class PlannerAgent(Agent):
@ -19,9 +19,9 @@ class PlannerAgent(Agent):
self.agents = {
"coder": CoderAgent(model, name, prompt_path, provider),
"file": FileAgent(model, name, prompt_path, provider),
"web": CasualAgent(model, name, prompt_path, provider)
"web": BrowserAgent(model, name, prompt_path, provider)
}
self.role = "complex programming tasks and web research"
self.role = "Manage complex tasks"
self.tag = "json"
def parse_agent_tasks(self, text):

View File

@ -38,12 +38,10 @@ class Browser:
chrome_options.add_argument("--disable-dev-shm-usage")
# Automatically find ChromeDriver path
chromedriver_path = shutil.which("chromedriver")
if not chromedriver_path:
raise FileNotFoundError("ChromeDriver not found. Please install it or add it to your PATH.")
service = Service(chromedriver_path)
if chromedriver_path:
self.driver = webdriver.Chrome(service=service, options=chrome_options)
else:
self.driver = webdriver.Chrome(service=service)
#raise FileNotFoundError("ChromeDriver not found. Please install it or add it to your PATH.")
self.driver = webdriver.Chrome(service=service, options=chrome_options)
self.wait = WebDriverWait(self.driver, 10)
self.logger = logging.getLogger(__name__)
self.logger.info("Browser initialized successfully")
@ -115,6 +113,7 @@ class Browser:
return None
def clean_url(self, url):
"""Clean URL to keep only the part needed for navigation to the page"""
clean = url.split('#')[0]
parts = clean.split('?', 1)
base_url = parts[0]

View File

@ -102,6 +102,7 @@ class Interaction:
self.current_agent = agent
# get history from previous agent, good ?
self.current_agent.memory.push('user', self.last_query)
self.current_agent.memory.push('assistant', self.last_answer)
self.last_answer, _ = agent.process(self.last_query, self.speech)
def show_answer(self) -> None:

View File

@ -91,10 +91,10 @@ class searxSearch(Tools):
description = article.find('p', class_='content').text.strip() if article.find('p', class_='content') else "No Description"
results.append(f"Title:{title}\nSnippet:{description}\nLink:{url}")
if len(results) == 0:
raise Exception("Searx search failed. did you run start_services.sh? Did docker die?")
return "No search results, web search failed."
return "\n\n".join(results) # Return results as a single string, separated by newlines
except requests.exceptions.RequestException as e:
return f"Error during search: {str(e)}"
raise Exception("\nSearxng search failed. did you run start_services.sh? is docker still running?") from e
def execution_failure_check(self, output: str) -> bool:
"""