feat : latest docker attempt + fix attempt for #249
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
SEARXNG_BASE_URL="http://127.0.0.1:8080"
|
SEARXNG_BASE_URL="http://127.0.0.1:8080"
|
||||||
|
TOKENIZERS_PARALLELISM="false"
|
||||||
OPENAI_API_KEY='xxxxx'
|
OPENAI_API_KEY='xxxxx'
|
||||||
DEEPSEEK_API_KEY='xxxxx'
|
DEEPSEEK_API_KEY='xxxxx'
|
||||||
OPENROUTER_API_KEY='xxxxx'
|
OPENROUTER_API_KEY='xxxxx'
|
||||||
|
|||||||
+24
-22
@@ -60,33 +60,35 @@ COPY sources/ ./sources/
|
|||||||
COPY prompts/ ./prompts/
|
COPY prompts/ ./prompts/
|
||||||
COPY crx/ crx/
|
COPY crx/ crx/
|
||||||
COPY llm_router/ llm_router/
|
COPY llm_router/ llm_router/
|
||||||
COPY .env .
|
RUN ls
|
||||||
COPY config.ini .
|
COPY .env.example .env
|
||||||
|
|
||||||
# Install Chrome and ChromeDriver from chrome-for-testing
|
# Install Chrome and ChromeDriver from chrome-for-testing
|
||||||
RUN wget -O chrome-headless-shell-linux64.zip https://storage.googleapis.com/chrome-for-testing-public/137.0.7151.55/linux64/chrome-headless-shell-linux64.zip && \
|
#RUN wget -O chrome-headless-shell-linux64.zip https://storage.googleapis.com/chrome-for-testing-public/137.0.7151.55/linux64/chrome-headless-shell-linux64.zip && \
|
||||||
wget -O chromedriver-linux64.zip https://storage.googleapis.com/chrome-for-testing-public/137.0.7151.55/linux64/chromedriver-linux64.zip && \
|
# wget -O chromedriver-linux64.zip https://storage.googleapis.com/chrome-for-testing-public/137.0.7151.55/linux64/chromedriver-linux64.zip && \
|
||||||
unzip chrome-headless-shell-linux64.zip && \
|
# unzip chrome-headless-shell-linux64.zip && \
|
||||||
unzip chromedriver-linux64.zip && \
|
# unzip chromedriver-linux64.zip && \
|
||||||
mkdir -p /opt/google && \
|
# mkdir -p /opt/google && \
|
||||||
ls -la && \
|
# ls -la && \
|
||||||
mv chrome-headless-shell-linux64 /opt/google/chrome && \
|
# mv chrome-headless-shell-linux64 /opt/google/chrome && \
|
||||||
mv chromedriver-linux64/chromedriver /usr/local/bin/chromedriver && \
|
# mv chromedriver-linux64/chromedriver /usr/local/bin/chromedriver && \
|
||||||
chmod +x /opt/google/chrome/chrome-headless-shell && \
|
# chmod +x /opt/google/chrome/chrome-headless-shell && \
|
||||||
chmod +x /usr/local/bin/chromedriver
|
# chmod +x /usr/local/bin/chromedriver
|
||||||
|
|
||||||
RUN ln -s /opt/google/chrome/chrome /usr/local/bin/chrome
|
RUN wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add - && \
|
||||||
|
echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list && \
|
||||||
|
apt-get update && \
|
||||||
|
apt-get install -y google-chrome-stable && \
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Debug ChromeDriver
|
# Install matching ChromeDriver
|
||||||
RUN echo "=== ChromeDriver Debug ===" && \
|
RUN CHROME_VERSION=$(google-chrome --version | grep -oP '\d+\.\d+\.\d+') && \
|
||||||
/usr/local/bin/chromedriver --version && \
|
wget -O chromedriver.zip "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_VERSION%%.*}/chromedriver_linux64.zip" && \
|
||||||
echo "Chrome binary:" && \
|
unzip chromedriver.zip && \
|
||||||
/opt/google/chrome/chrome --version && \
|
mv chromedriver /usr/local/bin/ && \
|
||||||
echo "Testing ChromeDriver startup:" && \
|
chmod +x /usr/local/bin/chromedriver && \
|
||||||
timeout 5 /usr/local/bin/chromedriver --port=9999 || echo "ChromeDriver failed to start"
|
rm chromedriver.zip
|
||||||
|
|
||||||
ENV CHROME_BIN=/opt/google/chrome/chrome
|
|
||||||
ENV CHROMEDRIVER_PATH=/usr/local/bin/chromedriver
|
|
||||||
ENV DISPLAY=:99
|
ENV DISPLAY=:99
|
||||||
|
|
||||||
# Expose port
|
# Expose port
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class BrowserAgent(Agent):
|
|||||||
self.memory = Memory(self.load_prompt(prompt_path),
|
self.memory = Memory(self.load_prompt(prompt_path),
|
||||||
recover_last_session=False, # session recovery in handled by the interaction class
|
recover_last_session=False, # session recovery in handled by the interaction class
|
||||||
memory_compression=False,
|
memory_compression=False,
|
||||||
model_provider=provider.get_model_name())
|
model_provider=provider.get_model_name() if provider else None)
|
||||||
|
|
||||||
def get_today_date(self) -> str:
|
def get_today_date(self) -> str:
|
||||||
"""Get the date"""
|
"""Get the date"""
|
||||||
@@ -77,14 +77,14 @@ class BrowserAgent(Agent):
|
|||||||
def get_unvisited_links(self) -> List[str]:
|
def get_unvisited_links(self) -> List[str]:
|
||||||
return "\n".join([f"[{i}] {link}" for i, link in enumerate(self.navigable_links) if link not in self.search_history])
|
return "\n".join([f"[{i}] {link}" for i, link in enumerate(self.navigable_links) if link not in self.search_history])
|
||||||
|
|
||||||
def make_newsearch_prompt(self, user_prompt: str, search_result: dict) -> str:
|
def make_newsearch_prompt(self, prompt: str, search_result: dict) -> str:
|
||||||
search_choice = self.stringify_search_results(search_result)
|
search_choice = self.stringify_search_results(search_result)
|
||||||
self.logger.info(f"Search results: {search_choice}")
|
self.logger.info(f"Search results: {search_choice}")
|
||||||
return f"""
|
return f"""
|
||||||
Based on the search result:
|
Based on the search result:
|
||||||
{search_choice}
|
{search_choice}
|
||||||
Your goal is to find accurate and complete information to satisfy the user’s request.
|
Your goal is to find accurate and complete information to satisfy the user’s request.
|
||||||
User request: {user_prompt}
|
User request: {prompt}
|
||||||
To proceed, choose a relevant link from the search results. Announce your choice by saying: "I will navigate to <link>"
|
To proceed, choose a relevant link from the search results. Announce your choice by saying: "I will navigate to <link>"
|
||||||
Do not explain your choice.
|
Do not explain your choice.
|
||||||
"""
|
"""
|
||||||
@@ -235,13 +235,17 @@ class BrowserAgent(Agent):
|
|||||||
return links
|
return links
|
||||||
|
|
||||||
def select_link(self, links: List[str]) -> str | None:
|
def select_link(self, links: List[str]) -> str | None:
|
||||||
|
"""
|
||||||
|
Select the first unvisited link that is not the current page.
|
||||||
|
Preference is given to links not in search_history.
|
||||||
|
"""
|
||||||
for lk in links:
|
for lk in links:
|
||||||
if lk == self.current_page:
|
if lk == self.current_page or lk in self.search_history:
|
||||||
self.logger.info(f"Already visited {lk}. Skipping.")
|
self.logger.info(f"Skipping already visited or current link: {lk}")
|
||||||
continue
|
continue
|
||||||
self.logger.info(f"Selected link: {lk}")
|
self.logger.info(f"Selected link: {lk}")
|
||||||
return lk
|
return lk
|
||||||
self.logger.warning("No link selected.")
|
self.logger.warning("No suitable link selected.")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_page_text(self, limit_to_model_ctx = False) -> str:
|
def get_page_text(self, limit_to_model_ctx = False) -> str:
|
||||||
@@ -396,7 +400,10 @@ class BrowserAgent(Agent):
|
|||||||
if (link == None and len(extracted_form) < 3) or Action.GO_BACK.value in answer or link in self.search_history:
|
if (link == None and len(extracted_form) < 3) or Action.GO_BACK.value in answer or link in self.search_history:
|
||||||
pretty_print(f"Going back to results. Still {len(unvisited)}", color="status")
|
pretty_print(f"Going back to results. Still {len(unvisited)}", color="status")
|
||||||
self.status_message = "Going back to search results..."
|
self.status_message = "Going back to search results..."
|
||||||
prompt = self.make_newsearch_prompt(user_prompt, unvisited)
|
request_prompt = user_prompt
|
||||||
|
if link is None:
|
||||||
|
request_prompt += f"\nYou previously choosen:\n{self.last_answer} but the website is unavailable. Consider other options."
|
||||||
|
prompt = self.make_newsearch_prompt(request_prompt, unvisited)
|
||||||
self.search_history.append(link)
|
self.search_history.append(link)
|
||||||
self.current_page = link
|
self.current_page = link
|
||||||
continue
|
continue
|
||||||
|
|||||||
+4
-3
@@ -136,18 +136,21 @@ def create_driver(headless=False, stealth_mode=True, crx_path="./crx/nopecha.crx
|
|||||||
if headless:
|
if headless:
|
||||||
#chrome_options.add_argument("--headless")
|
#chrome_options.add_argument("--headless")
|
||||||
chrome_options.add_argument("--headless=new")
|
chrome_options.add_argument("--headless=new")
|
||||||
|
chrome_options.add_argument("--disable-dev-shm-usage")
|
||||||
chrome_options.add_argument("--disable-gpu")
|
chrome_options.add_argument("--disable-gpu")
|
||||||
chrome_options.add_argument("--disable-webgl")
|
chrome_options.add_argument("--disable-webgl")
|
||||||
|
chrome_options.add_argument("--remote-debugging-port=9222")
|
||||||
user_data_dir = tempfile.mkdtemp()
|
user_data_dir = tempfile.mkdtemp()
|
||||||
user_agent = get_random_user_agent()
|
user_agent = get_random_user_agent()
|
||||||
width, height = (1920, 1080)
|
width, height = (1920, 1080)
|
||||||
chrome_options.add_argument(f"--user-data-dir={user_data_dir}")
|
chrome_options.add_argument(f"--user-data-dir={user_data_dir}")
|
||||||
chrome_options.add_argument(f"--accept-lang={lang}-{lang.upper()},{lang};q=0.9")
|
chrome_options.add_argument(f"--accept-lang={lang}-{lang.upper()},{lang};q=0.9")
|
||||||
|
chrome_options.add_argument("--disable-extensions")
|
||||||
|
chrome_options.add_argument("--disable-background-timer-throttling")
|
||||||
chrome_options.add_argument("--timezone=Europe/Paris")
|
chrome_options.add_argument("--timezone=Europe/Paris")
|
||||||
chrome_options.add_argument("--no-sandbox")
|
chrome_options.add_argument("--no-sandbox")
|
||||||
chrome_options.add_argument('--disable-dev-shm-usage')
|
chrome_options.add_argument('--disable-dev-shm-usage')
|
||||||
chrome_options.add_argument('--remote-debugging-port=9222')
|
chrome_options.add_argument('--remote-debugging-port=9222')
|
||||||
chrome_options.add_argument('--disable-extensions')
|
|
||||||
chrome_options.add_argument('--disable-background-timer-throttling')
|
chrome_options.add_argument('--disable-background-timer-throttling')
|
||||||
chrome_options.add_argument('--disable-backgrounding-occluded-windows')
|
chrome_options.add_argument('--disable-backgrounding-occluded-windows')
|
||||||
chrome_options.add_argument('--disable-renderer-backgrounding')
|
chrome_options.add_argument('--disable-renderer-backgrounding')
|
||||||
@@ -721,8 +724,6 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
input("press enter to continue")
|
input("press enter to continue")
|
||||||
print("AntiCaptcha / Form Test")
|
print("AntiCaptcha / Form Test")
|
||||||
browser.go_to("https://www.google.com/recaptcha/api2/demo")
|
|
||||||
time.sleep(50)
|
|
||||||
browser.go_to("https://bot.sannysoft.com")
|
browser.go_to("https://bot.sannysoft.com")
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
#txt = browser.get_text()
|
#txt = browser.get_text()
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class TestBrowserAgentParsing(unittest.TestCase):
|
|||||||
"https://thriveonai.com/15-ai-startups-in-japan-to-take-note-of",
|
"https://thriveonai.com/15-ai-startups-in-japan-to-take-note-of",
|
||||||
"www.google.com",
|
"www.google.com",
|
||||||
"https://test.org/about?page=1",
|
"https://test.org/about?page=1",
|
||||||
"https://weatherstack.com/documentation",
|
"https://weatherstack.com/documentation"
|
||||||
]
|
]
|
||||||
result = self.agent.extract_links(test_text)
|
result = self.agent.extract_links(test_text)
|
||||||
self.assertEqual(result, expected)
|
self.assertEqual(result, expected)
|
||||||
|
|||||||
Reference in New Issue
Block a user