browserUSEAPI / app.py
simoncck's picture
Create app.py
f6aaf19 verified
raw
history blame
739 Bytes
import os
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from langchain_google_genai import ChatGoogleGenerativeAI
from browser_use import Agent
app = FastAPI()
class Task(BaseModel):
task: str
def make_llm():
# LangChain helper; will raise if GOOGLE_API_KEY missing
return ChatGoogleGenerativeAI(model="gemini-2.0-flash-exp")
@app.post("/run")
async def run_task(t: Task):
try:
llm = make_llm()
agent = Agent(task=t.task, llm=llm) # Browser-Use agent
result = await agent.run_async() # async version
return result # Browser-Use returns dict
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))