-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb_agent.py
32 lines (24 loc) · 902 Bytes
/
web_agent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from playwright.sync_api import sync_playwright
import ollama
def get_ai_response(prompt):
response = ollama.chat(model='deepseek-r1:8b', messages=[{
'role': 'user',
'content': prompt
}])
return response['message']['content']
def browse_with_ai():
with sync_playwright() as p:
browser = p.chromium.launch(headless=False)
page = browser.new_page()
# Navigate to a website
page.goto('https://mkdir.dev')
# Get page content
content = page.content()
# Ask AI to analyze the content
prompt = f"Analyze this webpage content and give me a summary: {content}"
ai_analysis = get_ai_response(prompt)
print("AI Analysis:", ai_analysis)
# You can add more interactions here
browser.close()
if __name__ == "__main__":
browse_with_ai()