import sys

from dotenv import load_dotenv

from langchain.agents import load_tools
from langchain.agents import initialize_agent
from langchain.llms import OpenAI

from commands import chrome_click_on_link, chrome_get_the_links_on_the_page, chrome_open_url, chrome_read_the_page, computer_applescript_action, say_text


# load environment variables
load_dotenv()

def main(command):
    llm = OpenAI(temperature=0)

    tools = [
        computer_applescript_action,
        chrome_open_url,
        chrome_get_the_links_on_the_page,
        chrome_click_on_link,
        chrome_read_the_page
    ]

    agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True)

    result = agent.run(command)

    if result:
        say_text(f'The result is {result}')
    else:
        say_text(f'Finished doing {command}')

if __name__ == "__main__":
    command = sys.argv[1]
    if not command:
        print("Please provide a command to execute e.g. python main.py 'Open the calculator app'")
        exit(1)

    main(command)

langchain.agents.initialize_agent langchain.llms.OpenAI
[((350, 363), 'dotenv.load_dotenv', 'load_dotenv', ([], {}), '()\n', (361, 363), False, 'from dotenv import load_dotenv\n'), ((394, 415), 'langchain.llms.OpenAI', 'OpenAI', ([], {'temperature': '(0)'}), '(temperature=0)\n', (400, 415), False, 'from langchain.llms import OpenAI\n'), ((613, 692), 'langchain.agents.initialize_agent', 'initialize_agent', (['tools', 'llm'], {'agent': '"""zero-shot-react-description"""', 'verbose': '(True)'}), "(tools, llm, agent='zero-shot-react-description', verbose=True)\n", (629, 692), False, 'from langchain.agents import initialize_agent\n'), ((750, 785), 'commands.say_text', 'say_text', (['f"""The result is {result}"""'], {}), "(f'The result is {result}')\n", (758, 785), False, 'from commands import chrome_click_on_link, chrome_get_the_links_on_the_page, chrome_open_url, chrome_read_the_page, computer_applescript_action, say_text\n'), ((804, 841), 'commands.say_text', 'say_text', (['f"""Finished doing {command}"""'], {}), "(f'Finished doing {command}')\n", (812, 841), False, 'from commands import chrome_click_on_link, chrome_get_the_links_on_the_page, chrome_open_url, chrome_read_the_page, computer_applescript_action, say_text\n')]