4cd2d4af2b
Test Browser Use CLI Install / uv pip install (macos-latest) (push) Waiting to run
Test Browser Use CLI Install / uv pip install (windows-latest) (push) Waiting to run
Test Browser Use CLI Install / uv pip install (ubuntu-latest) (push) Failing after 1s
Test Browser Use CLI Install / uvx browser-use from local wheel (push) Failing after 1s
Test Browser Use CLI Install / uvx browser-use[cli] from PyPI (push) Failing after 1s
package / pip-install-on-macos-latest-py-3.11 (push) Has been skipped
package / pip-install-on-macos-latest-py-3.13 (push) Has been skipped
package / pip-install-on-ubuntu-latest-py-3.11 (push) Has been skipped
package / pip-install-on-windows-latest-py-3.13 (push) Has been skipped
cloud_evals / trigger_cloud_eval_image_build (push) Failing after 1s
docker / build_publish_image (push) Failing after 1s
Test Browser Use CLI Install / browser-use skill sync (push) Failing after 1s
lint / code-style (push) Failing after 0s
lint / type-checker (push) Failing after 1s
package / pip-build (push) Failing after 1s
lint / syntax-errors (push) Failing after 3s
package / pip-install-on-ubuntu-latest-py-3.13 (push) Has been skipped
package / pip-install-on-windows-latest-py-3.11 (push) Has been skipped
test / ${{ matrix.test_filename }} (push) Has been skipped
test / evaluate-tasks (push) Has been skipped
test / setup-chromium (push) Failing after 2s
test / find_tests (push) Failing after 2s
56 lines
1.2 KiB
Python
56 lines
1.2 KiB
Python
"""
|
|
Show how to use custom outputs.
|
|
|
|
@dev You need to add OPENAI_API_KEY to your environment variables.
|
|
"""
|
|
|
|
import asyncio
|
|
import os
|
|
import sys
|
|
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
|
|
from pydantic import BaseModel
|
|
|
|
from browser_use import Agent, ChatOpenAI
|
|
|
|
|
|
class Post(BaseModel):
|
|
post_title: str
|
|
post_url: str
|
|
num_comments: int
|
|
hours_since_post: int
|
|
|
|
|
|
class Posts(BaseModel):
|
|
posts: list[Post]
|
|
|
|
|
|
async def main():
|
|
task = 'Go to hackernews show hn and give me the first 5 posts'
|
|
model = ChatOpenAI(model='gpt-4.1-mini')
|
|
agent = Agent(task=task, llm=model, output_model_schema=Posts)
|
|
|
|
history = await agent.run()
|
|
|
|
result = history.final_result()
|
|
if result:
|
|
parsed: Posts = Posts.model_validate_json(result)
|
|
|
|
for post in parsed.posts:
|
|
print('\n--------------------------------')
|
|
print(f'Title: {post.post_title}')
|
|
print(f'URL: {post.post_url}')
|
|
print(f'Comments: {post.num_comments}')
|
|
print(f'Hours since post: {post.hours_since_post}')
|
|
else:
|
|
print('No result')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
asyncio.run(main())
|