refactor(docker): simplify Dockerfile and remove custom browser component
- Simplified Dockerfile by removing system dependencies, Playwright installation, and unnecessary Python packages - Removed custom browser_use_component.py (now using custom_components directory) - Updated docker-compose to build from Dockerfile and mount custom_components - Retained only essential dependencies: browser-use and langchain-openai
This commit is contained in:
1 parent
1f7d15a151
commit
0b91ee5481
5 files changed
+87
-304
No files matched your search
@@ -0,0 +1,75 @@
|
||||
"""
|
||||
Browser Use Custom Component для Langflow
|
||||
"""
|
||||
import os
|
||||
from typing import Dict, Any
|
||||
|
||||
from lfx.custom import Component
|
||||
from lfx.io import SecretStrInput, StrInput
|
||||
from lfx.template import Output
|
||||
|
||||
|
||||
class BrowserUseComponent(Component):
|
||||
"""Browser Use компонент с browserless + OpenRouter"""
|
||||
display_name = "Browser Use"
|
||||
description = "browser-use с browserless + OpenRouter"
|
||||
icon = "Globe"
|
||||
|
||||
inputs = [
|
||||
SecretStrInput(
|
||||
name="browserless_url",
|
||||
display_name="Browserless URL",
|
||||
value=os.getenv("BROWSERLESS_API_URL", "http://browserless.home"),
|
||||
required=True,
|
||||
),
|
||||
StrInput(
|
||||
name="task",
|
||||
display_name="Задача",
|
||||
required=True,
|
||||
placeholder="Например: найди информацию о...",
|
||||
),
|
||||
StrInput(
|
||||
name="model",
|
||||
display_name="OpenRouter Модель",
|
||||
value="arcee-ai/trinity-large-preview:free",
|
||||
advanced=True,
|
||||
),
|
||||
]
|
||||
|
||||
outputs = [
|
||||
Output(name="result", display_name="Результат", method="run_browser"),
|
||||
]
|
||||
|
||||
def run_browser(self) -> str:
|
||||
"""Запускает browser-use агент"""
|
||||
try:
|
||||
from browser_use import Agent, Browser
|
||||
from langchain_openai import ChatOpenAI
|
||||
|
||||
browserless_url = self.browserless_url or "http://browserless.home"
|
||||
cdp_url = browserless_url.replace("http://", "ws://").replace("https://", "wss://")
|
||||
cdp_url = f"{cdp_url}/playwright"
|
||||
|
||||
browser = Browser(cdp_url=cdp_url, headless=True)
|
||||
|
||||
api_key = os.getenv("OPENROUTER_API_KEY", "")
|
||||
|
||||
llm = ChatOpenAI(
|
||||
model=self.model,
|
||||
api_key=api_key,
|
||||
base_url="https://openrouter.ai/api/v1",
|
||||
default_headers={
|
||||
"HTTP-Referer": "http://langflow.home",
|
||||
"X-Title": "Langflow",
|
||||
},
|
||||
)
|
||||
|
||||
agent = Agent(task=self.task, llm=llm, browser=browser)
|
||||
result = agent.run()
|
||||
|
||||
return str(result)
|
||||
|
||||
except ImportError as e:
|
||||
return f"Ошибка импорта: {e}. Установите browser-use"
|
||||
except Exception as e:
|
||||
return f"Ошибка: {e}"
|
||||
Reference in new issue
Block a user