morikotikk commited on
Commit
9ce48a8
·
verified ·
1 Parent(s): 0801ad0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from fastapi import FastAPI
3
+ from browser_use import Agent
4
+ from langchain_nvidia_ai_endpoints import ChatNVIDIA
5
+ from pydantic import BaseModel
6
+
7
+ app = FastAPI()
8
+
9
+ # Модель данных для запроса из n8n
10
+ class Task(BaseModel):
11
+ instruction: str
12
+
13
+ @app.get("/")
14
+ def home():
15
+ return {"status": "Browser AI is running"}
16
+
17
+ @app.post("/run")
18
+ async def run_browser(task: Task):
19
+ # Подключаем мозги от Nvidia
20
+ # Убедитесь, что добавили NVIDIA_API_KEY в Settings -> Secrets вашего Space
21
+ llm = ChatNVIDIA(
22
+ model="meta/llama-3.1-70b-instruct",
23
+ nvidia_api_key=os.getenv("NVIDIA_API_KEY")
24
+ )
25
+
26
+ # Создаем агента
27
+ agent = Agent(
28
+ task=task.instruction,
29
+ llm=llm,
30
+ )
31
+
32
+ # Выполняем задачу
33
+ history = await agent.run()
34
+
35
+ return {"result": history.final_result()}