Skip to content

Commit 1acdc60

Browse files
committed
fix bug
1 parent c90acad commit 1acdc60

File tree

4 files changed

+180
-126
lines changed

4 files changed

+180
-126
lines changed

src/agent/custom_agent.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ async def step(self, step_info: Optional[CustomAgentStepInfo] = None) -> None:
270270
self._last_result = result
271271
self._last_actions = actions
272272
if len(result) > 0 and result[-1].is_done:
273-
self.extracted_content += step_info.memory
273+
if not self.extracted_content:
274+
self.extracted_content = step_info.memory
274275
result[-1].extracted_content = self.extracted_content
275276
logger.info(f"📄 Result: {result[-1].extracted_content}")
276277

@@ -346,7 +347,10 @@ async def run(self, max_steps: int = 100) -> AgentHistoryList:
346347
break
347348
else:
348349
logger.info("❌ Failed to complete task in maximum steps")
349-
self.history.history[-1].result[-1].extracted_content = self.extracted_content
350+
if not self.extracted_content:
351+
self.history.history[-1].result[-1].extracted_content = step_info.memory
352+
else:
353+
self.history.history[-1].result[-1].extracted_content = self.extracted_content
350354

351355
return self.history
352356

src/controller/custom_controller.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import pdb
2+
13
import pyperclip
24
from typing import Optional, Type
35
from pydantic import BaseModel
@@ -21,10 +23,11 @@
2123

2224
logger = logging.getLogger(__name__)
2325

26+
2427
class CustomController(Controller):
2528
def __init__(self, exclude_actions: list[str] = [],
26-
output_model: Optional[Type[BaseModel]] = None
27-
):
29+
output_model: Optional[Type[BaseModel]] = None
30+
):
2831
super().__init__(exclude_actions=exclude_actions, output_model=output_model)
2932
self._register_custom_actions()
3033

@@ -44,20 +47,25 @@ async def paste_from_clipboard(browser: BrowserContext):
4447
await page.keyboard.type(text)
4548

4649
return ActionResult(extracted_content=text)
47-
50+
4851
@self.registry.action(
4952
'Extract page content to get the pure text or markdown with links if include_links is set to true',
5053
param_model=ExtractPageContentAction,
5154
requires_browser=True,
5255
)
5356
async def extract_content(params: ExtractPageContentAction, browser: BrowserContext):
5457
page = await browser.get_current_page()
58+
# use jina reader
59+
url = page.url
60+
jina_url = f"https://r.jina.ai/{url}"
61+
await page.goto(jina_url)
5562
output_format = 'markdown' if params.include_links else 'text'
5663
content = MainContentExtractor.extract( # type: ignore
5764
html=await page.content(),
5865
output_format=output_format,
5966
)
60-
title = await page.title()
61-
msg = f'📄 Page url: {page.url}, Page title: {title}, Extracted page content as {output_format}\n: {content}\n'
67+
# go back to org url
68+
await page.go_back()
69+
msg = f'📄 Extracted page content as {output_format}\n: {content}\n'
6270
logger.info(msg)
6371
return ActionResult(extracted_content=msg)

src/utils/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import time
44
from pathlib import Path
55
from typing import Dict, Optional
6+
import requests
67

78
from langchain_anthropic import ChatAnthropic
89
from langchain_mistralai import ChatMistralAI

0 commit comments

Comments
 (0)