75 lines
3.3 KiB
Python
75 lines
3.3 KiB
Python
|
|
#pip install browser-use langchain-openai langchain-ollama playwright
|
|
#playwright install
|
|
|
|
## comandi da CLI
|
|
"""
|
|
browser-use open https://example.com # Navigate to URL
|
|
browser-use state # See clickable elements
|
|
browser-use click 5 # Click element by index
|
|
browser-use type "Hello" # Type text
|
|
browser-use screenshot page.png # Take screenshot
|
|
browser-use close # Close browser
|
|
"""
|
|
|
|
|
|
"""
|
|
import asyncio
|
|
import os
|
|
from browser_use import Agent
|
|
from langchain_openai import AzureChatOpenAI
|
|
|
|
async def run_azure_agent():
|
|
# Inizializziamo il modello Azure OpenAI tramite LangChain
|
|
# Sostituisci "il-tuo-deployment-name" con il nome esatto del deployment su Azure (es. gpt-4o)
|
|
llm = AzureChatOpenAI(
|
|
azure_deployment="gpt-4o",
|
|
openai_api_version=os.getenv("AZURE_OPENAI_API_VERSION", "2025-01-01-preview"),
|
|
azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT","https://hiis-accessibility-fonderia.cognitiveservices.azure.com"),
|
|
api_key=os.getenv("AZURE_OPENAI_API_KEY","4lwGUwrx7jsqdxESGBpN9wYYyLNsxzC2s8ZLQlZPCQUayDWuDo3NJQQJ99BKACfhMk5XJ3w3AAAAACOGs2uw")
|
|
)
|
|
|
|
# Definiamo l'agente con il modello Azure
|
|
agent = Agent(
|
|
task="Naviga su wikipedia, cerca la pagina dell'intelligenza artificiale e dimmi l'anno di nascita del termine.",
|
|
llm=llm
|
|
)
|
|
|
|
# Eseguiamo l'agente
|
|
result = await agent.run()
|
|
print("\n[Risultato Finale Azure OpenAI]:\n", result)
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(run_azure_agent())
|
|
"""
|
|
|
|
|
|
|
|
import asyncio
|
|
import os
|
|
# IMPORTANTE: Importiamo ChatAzureOpenAI direttamente da browser_use!
|
|
from browser_use import Agent, ChatAzureOpenAI
|
|
|
|
async def run_azure_agent():
|
|
# browser-use gestisce internamente la classe per evitare l'errore di Pydantic
|
|
llm = ChatAzureOpenAI(
|
|
model="gpt-4o",
|
|
azure_endpoint="https://hiis-accessibility-fonderia.cognitiveservices.azure.com/",
|
|
azure_deployment="gpt-4o",
|
|
api_version="2025-01-01-preview",
|
|
api_key="" # Sostituisci con la tua chiave Azure reale
|
|
)
|
|
|
|
# Configurazione dell'agente
|
|
agent = Agent(
|
|
#task="apri l'url https://github.com/rasbt e verifica se la pagina presenta una funzione alternativa alla mappa interattiva dei contenuti nell'anno (contribution heatmap data visualization). 'Equivalente' è da interpretare secondo la definizione WCAG Sucess Criterion 2.5.8 Target Size (Minimum): 'The function can be achieved through a different control on the same page that meets this criterion' - Rispondi SI o No e motiva la tua risposta",#"Naviga su wikipedia, cerca la pagina dell'intelligenza artificiale e dimmi l'anno di nascita del termine.",
|
|
task="Open the URL https://github.com/rasbt and check if the page offers an alternative function to the interactive map of content in the year (contribution heatmap data visualization). 'Equivalent' is to be interpreted according to the WCAG Success Criterion 2.5.8 Target Size (Minimum): 'The function can be achieved through a different control on the same page that meets this criterion' - Answer YES or NO and justify your answer.",
|
|
llm=llm
|
|
)
|
|
|
|
# Esecuzione del workflow
|
|
result = await agent.run()
|
|
print("\n[Risultato Finale Azure OpenAI]:\n", result)
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(run_azure_agent()) |