gregpr07 / browser-use

Make websites accessible for AI agents
https://link.browser-use.com/discord
MIT License
2.49k stars 178 forks source link

Strange Output #28

Open PierrunoYT opened 1 week ago

PierrunoYT commented 1 week ago

grafik

MagMueller commented 1 week ago

Hey which code did you run?

Could be the screenshot which we take

PierrunoYT commented 1 week ago

from browser_use import Agent
from dotenv import load_dotenv
import asyncio
import json
from datetime import datetime

# Load environment variables
load_dotenv()

def save_result(task: str, result: str):
    """Save the task and result to a JSON file"""
    data = {
        "timestamp": datetime.now().isoformat(),
        "task": task,
        "result": result
    }

    try:
        # Try to read existing data
        try:
            with open('results.json', 'r') as f:
                existing_data = json.load(f)
                if not isinstance(existing_data, list):
                    existing_data = []
        except (FileNotFoundError, json.JSONDecodeError):
            existing_data = []

        # Append new data
        existing_data.append(data)

        # Write back to file
        with open('results.json', 'w') as f:
            json.dump(existing_data, f, indent=4)

        print(f"Results saved to results.json")
    except Exception as e:
        print(f"Error saving results: {e}")

async def run_agent(task: str):
    agent = Agent(
        task=task,
        llm=ChatOpenAI(model="gpt-4o"),
    )
    return await agent.run()

if __name__ == '__main__':
    print("Enter your task:")
    task = input()
    result = asyncio.run(run_agent(task))
    print("\nResult:", result)

    # Save the results
    save_result(task, result)```
MagMueller commented 1 week ago

Thanks - i see - the reason is because you print the entire result (this is the entire history)

so it also contains the screenshots. Simply don't print the entire result

the output structure is here in AgentHistory

let me know if you look for anything specific.

https://github.com/gregpr07/browser-use/blob/main/browser_use/agent/views.py

PierrunoYT commented 2 days ago

Thanks - i see - the reason is because you print the entire result (this is the entire history)

so it also contains the screenshots. Simply don't print the entire result

the output structure is here in AgentHistory

let me know if you look for anything specific.

https://github.com/gregpr07/browser-use/blob/main/browser_use/agent/views.py

Can you make a template python script which people can use for the Browser Use Tool

MagMueller commented 2 days ago

you mean documentation or examples?

PierrunoYT commented 2 days ago

you mean documentation or examples?

I made a template script myself. Can I send it to you anywhere?