40 lines
1.2 KiB
PHP
40 lines
1.2 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
header('Access-Control-Allow-Origin: *');
|
|
$data = json_decode(file_get_contents('php://input'), true);
|
|
$url = $data['url'] ?? '';
|
|
$task = $data['task'] ?? 'extract';
|
|
$query = $data['query'] ?? '';
|
|
|
|
if (empty($url)) { echo json_encode(['error'=>'URL required']); exit; }
|
|
|
|
// Browser Use via Python subprocess
|
|
$py = <<<PY
|
|
import asyncio, json, sys
|
|
from browser_use import Agent
|
|
from langchain_openai import ChatOpenAI
|
|
|
|
async def run():
|
|
try:
|
|
# Use Groq as LLM backend
|
|
import os
|
|
os.environ['OPENAI_API_KEY'] = 'dummy'
|
|
|
|
agent = Agent(
|
|
task="{$task}: {$query} from {$url}",
|
|
llm=ChatOpenAI(
|
|
model="llama-3.3-70b-versatile",
|
|
base_url="https://api.groq.com/openai/v1",
|
|
api_key="gsk_placeholder"
|
|
)
|
|
)
|
|
result = await agent.run()
|
|
print(json.dumps({"ok": True, "result": str(result)}))
|
|
except Exception as e:
|
|
print(json.dumps({"ok": False, "error": str(e)}))
|
|
|
|
asyncio.run(run())
|
|
PY;
|
|
$result = shell_exec("timeout 30 python3 -c " . escapeshellarg($py) . " 2>&1");
|
|
echo $result ?: json_encode(['error'=>'timeout']);
|