docker compose重启后应用页面进去后流程是空白,对话记录也空白,但该应用接口正常,数据库正常更新
Bug Description
I have an content generator website using browser use i am trying out automation testing content generated are in below format if small object is given it is working and when object is huge it fails
Reproduction Steps
I am writing automation using browser use @controller.registry.action(" Only option 1 is mentioned .... pydantic object is able to extract content where entired object is give json failure and fails .. With use-vision = True and with use-vision false same story
please guide... how to get the entire object in final result
task = ( ..... 'get the generated content') model_id = "anthropic.claude-3-5-sonnet-20240620-v1:0"
, supporting_information: str, full_prescribing_information: str
@controller.registry.action("""Get all Banner Generated content {
"GeneratedContent": {
"option_1": {
"frames": [
str
],
"
Code Sample
import asyncio
import os
from typing import List, Dict
from browser_use.browser.context import BrowserContextConfig
from pprint import pprint
from src.utils.llm import getLLM
from browser_use import ActionResult, BrowserConfig,Browser
from browser_use.agent.service import Agent
from pydantic import BaseModel, SecretStr
from browser_use.browser.context import (
BrowserContextConfig,
BrowserContextWindowSize,
)
from browser_use.agent.views import AgentHistoryList
from browser_use.controller.service import Controller
class FrameOption(BaseModel):
frames: List[str]
somekey: str
class GeneratedContent(BaseModel):
option_1: FrameOption
option_2: FrameOption
somekey: int
somekey: str
somekey: str
somekey: List[str]
controller = Controller(output_model=FrameOption)
@controller.registry.action("""Get all some Generated content OPTION 1 { frames: List[str], somekey: str}, OPTION 2 { frames: List[str], somekey: str}""", param_model=FrameOption)
async def getOption1(params: GeneratedContent):
result = ActionResult(is_done=False, extracted_content=params.model_dump_json())
return result
@controller.registry.action("""Get all some Generated content OPTION 2 { frames: List[str], somekey: str}""", param_model=FrameOption)
async def getOption2(params: FrameOption):
result = ActionResult(is_done=False, extracted_content=params.model_dump_json())
return result
# , supporting_information: str, full_prescribing_information: str
@controller.registry.action("""Get all some Generated content {
"GeneratedContent": {
"option_1": {
"frames": [
str
],
"somekey": "str"
},
"option_2": {
"frames": [
"str"
],
"somekey": "str"
},
"somekey": "int",
"somekey": "str",
"somekey": "str",
"somekey": [
"str",
"str"
]
}
}""", param_model=GeneratedContent)
async def getOtherInfo(params: GeneratedContent):
result = ActionResult(is_done=True, extracted_content=params.model_dump_json())
return result
# Sometime it is not going to the exact website directly. It is searching in google & trying by self.
# But we can direct here - so that it will directly visit the url. So this is a fallback mechanism for opening browser step
@controller.action('open base website')
async def open_website(browser: BrowserConfig):
page = await browser.get_current_page()
await page.goto('<url>')
return ActionResult(extracted_content='browser opened')
task = (
open website
.....
'wait for confidence score > 0.25'
'get the generated content'
# 'Get all some Generated content OPTION 1'
# 'Get all some Generated content OPTION 2'
# 'Get all some Generated content rest all data'
)
async def main():
model = getLLM()
window_w, window_h = 1280, 720
use_vision = True
use_own_browser = False
if use_own_browser:
chrome_path = os.getenv("CHROME_PATH", None)
if chrome_path == "":
chrome_path = None
else:
chrome_path = None
tool_calling_method = "json_schema" # setting to json_schema when using ollma
browser = Browser(
config=BrowserConfig(
headless=False,
disable_security=True,
chrome_instance_path=chrome_path,
extra_chromium_args=[f"--window-size={window_w},{window_h}"],
)
)
async with await browser.new_context(
config=BrowserContextConfig(
trace_path="./tmp/traces",
save_recording_path="./tmp/recordings",
no_viewport=False,
browser_window_size=BrowserContextWindowSize(
width=window_w, height=window_h
),
)
) as browser_context:
agent = Agent(
task=task,
llm=getLLM(),
browser=browser,
browser_context=browser_context,
generate_gif=False,
use_vision=use_vision,
controller=controller,
save_conversation_path="./tmp/logs/conversation.json"
)
history: AgentHistoryList = await agent.run()
print("\nhistory.urls():")
print(history.urls() )
print("\nhistory.screenshots():")
print(history.screenshots())
print("\nhistory.action_names():")
print(history.action_names())
print("\nhistory.extracted_content():")
print(history.extracted_content())
print("Final Result:")
result = history.final_result()
pprint(history.final_result(), indent=4)
print("\nErrors:")
pprint(history.errors(), indent=4)
# e.g. xPaths the model clicked on
print("\nModel Outputs:")
pprint(history.model_actions(), indent=4)
print("\nThoughts:")
pprint(history.model_thoughts(), indent=4)
await browser.close()
if __name__ == '__main__':
asyncio.run(main())
Version
0.1.37
LLM Model
Claude 3.5 Sonnet
Operating System
macos
Relevant Log Output
JSON Parsed failed