mirror of
https://github.com/browser-use/browser-use
synced 2026-05-06 17:52:15 +02:00
* Add http_credentials to browser context. * Detect index change caused by page change in `multi_act` * Fix: Add sameSite cookie validation and auto-correction * added drag drop action * added drag drop action * pre-commit run -a (again) * added active_tab state management * add anthropic RateLimitError to list of defined rate limit errors * Add Retry handling to bedrock example * fix pydantic issue causing config to be overwritten * fix config setup * Add botocore, organize imports * ignore langchain beta warnings * silence pydantic deprecation warnings * Update bedrock_claude for ruff * ruff checks * Update pyproject.toml and bedrock_claude.py * ignore signal registration errors in edge case environments * ruff fixes * add example of getting 2FA code from 1password * add rebrowser and creepjs to stealth tests * Fix typos discovered by codespell * uv add --dev codespell * Update browser_use/browser/context.py * lint * Add explanations override_system_message and extend_system_message * Update custom-functions.mdx .get_current_page() is an async function which have to be awaited. * Fix: Remove unnecessary await from _verified_api_keys * Fix: Correct indentation for cookie loading log message in BrowserContext * Fix: resolve undefined response variable in Deepseek model raw tool calling mode * fix: increment consecutive_failure on every step error * Fix azure example not working due to agent memory changes * dont expose debug port on all addresses and keep security enabled by default * custom browser addition --------- Co-authored-by: Bartlomiej Wietrak <bartekwietrak@gmail.com> Co-authored-by: Alin Jiang <alineveryday@outlook.com> Co-authored-by: dipfocus <dipfocus@gmail.com> Co-authored-by: PaperBoardOfficial <hiremohitforsoftwarerole@gmail.com> Co-authored-by: Christian Clauss <cclauss@me.com> Co-authored-by: Alezander9 <alexander.j.yue@gmail.com> Co-authored-by: dheerajoruganty <db2winfb@gmail.com> Co-authored-by: Nick Sweeting <git@sweeting.me> Co-authored-by: Dheeraj Oruganty <53569374+dheerajoruganty@users.noreply.github.com> Co-authored-by: Bart <46058081+b0rgcube@users.noreply.github.com> Co-authored-by: Nick Sweeting <github@sweeting.me> Co-authored-by: pppp606 <ppppp303@gmail.com> Co-authored-by: Oswy <74738120+oswy-cpu@users.noreply.github.com> Co-authored-by: BurnyCoder <happymancz@email.cz> Co-authored-by: zhushijie <mr.zhushijie@gmail.com> Co-authored-by: john-rtr <jonathan.ratier@gmail.com> Co-authored-by: mathisarends-viadee <mathis.arends@viadee.de> Co-authored-by: lorenss-m <saeclmusic@gmail.com> Co-authored-by: Magnus Müller <67061560+MagMueller@users.noreply.github.com>
50 lines
1.2 KiB
Python
50 lines
1.2 KiB
Python
"""
|
|
Demonstrate output validator.
|
|
|
|
@dev You need to add OPENAI_API_KEY to your environment variables.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
import asyncio
|
|
|
|
from dotenv import load_dotenv
|
|
from langchain_openai import ChatOpenAI
|
|
from pydantic import BaseModel
|
|
|
|
from browser_use import ActionResult, Agent, Controller
|
|
|
|
load_dotenv()
|
|
|
|
controller = Controller()
|
|
|
|
|
|
class DoneResult(BaseModel):
|
|
title: str
|
|
comments: str
|
|
hours_since_start: int
|
|
|
|
|
|
# we overwrite done() in this example to demonstrate the validator
|
|
@controller.registry.action('Done with task', param_model=DoneResult)
|
|
async def done(params: DoneResult):
|
|
result = ActionResult(is_done=True, extracted_content=params.model_dump_json())
|
|
print(result)
|
|
# NOTE: this is clearly wrong - to demonstrate the validator
|
|
return 'blablabla'
|
|
|
|
|
|
async def main():
|
|
task = 'Go to hackernews hn and give me the top 1 post'
|
|
model = ChatOpenAI(model='gpt-4o')
|
|
agent = Agent(task=task, llm=model, controller=controller, validate_output=True)
|
|
# NOTE: this should fail to demonstrate the validator
|
|
await agent.run(max_steps=5)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
asyncio.run(main())
|