from dotenv import load_dotenv
from langchain_core.prompts import PromptTemplate

load_dotenv()
from langchain import hub
from langchain.agents import create_react_agent, AgentExecutor
from langchain_core.tools import Tool
from langchain_openai import ChatOpenAI

from tools.tools import get_profile_url


def lookup(name: str) -> str:
    llm = ChatOpenAI(temperature=0, model_name="gpt-3.5-turbo")
    template = """
       given the name {name_of_person} I want you to find a link to their Twitter profile page, and extract from it their username
       In Your Final answer only the person's username"""
    tools_for_agent_twitter = [
        Tool(
            name="Crawl Google 4 Twitter profile page",
            func=get_profile_url,
            description="useful for when you need get the Twitter Page URL",
        ),
    ]

    # agent = initialize_agent(
    #     tools_for_agent_twitter,
    #     llm,
    #     agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
    #     verbose=True,
    # )

    prompt_template = PromptTemplate(
        input_variables=["name_of_person"], template=template
    )

    react_prompt = hub.pull("hwchase17/react")
    agent = create_react_agent(
        llm=llm, tools=tools_for_agent_twitter, prompt=react_prompt
    )
    agent_executor = AgentExecutor(
        agent=agent, tools=tools_for_agent_twitter, verbose=True
    )

    result = agent_executor.invoke(
        input={"input": prompt_template.format_prompt(name_of_person=name)}
    )

    twitter_username = result["output"]

    return twitter_username

langchain_openai.ChatOpenAI langchain.agents.AgentExecutor langchain.agents.create_react_agent langchain_core.tools.Tool langchain_core.prompts.PromptTemplate langchain.hub.pull
[((82, 95), 'dotenv.load_dotenv', 'load_dotenv', ([], {}), '()\n', (93, 95), False, 'from dotenv import load_dotenv\n'), ((346, 399), 'langchain_openai.ChatOpenAI', 'ChatOpenAI', ([], {'temperature': '(0)', 'model_name': '"""gpt-3.5-turbo"""'}), "(temperature=0, model_name='gpt-3.5-turbo')\n", (356, 399), False, 'from langchain_openai import ChatOpenAI\n'), ((1031, 1100), 'langchain_core.prompts.PromptTemplate', 'PromptTemplate', ([], {'input_variables': "['name_of_person']", 'template': 'template'}), "(input_variables=['name_of_person'], template=template)\n", (1045, 1100), False, 'from langchain_core.prompts import PromptTemplate\n'), ((1135, 1162), 'langchain.hub.pull', 'hub.pull', (['"""hwchase17/react"""'], {}), "('hwchase17/react')\n", (1143, 1162), False, 'from langchain import hub\n'), ((1175, 1254), 'langchain.agents.create_react_agent', 'create_react_agent', ([], {'llm': 'llm', 'tools': 'tools_for_agent_twitter', 'prompt': 'react_prompt'}), '(llm=llm, tools=tools_for_agent_twitter, prompt=react_prompt)\n', (1193, 1254), False, 'from langchain.agents import create_react_agent, AgentExecutor\n'), ((1290, 1361), 'langchain.agents.AgentExecutor', 'AgentExecutor', ([], {'agent': 'agent', 'tools': 'tools_for_agent_twitter', 'verbose': '(True)'}), '(agent=agent, tools=tools_for_agent_twitter, verbose=True)\n', (1303, 1361), False, 'from langchain.agents import create_react_agent, AgentExecutor\n'), ((648, 787), 'langchain_core.tools.Tool', 'Tool', ([], {'name': '"""Crawl Google 4 Twitter profile page"""', 'func': 'get_profile_url', 'description': '"""useful for when you need get the Twitter Page URL"""'}), "(name='Crawl Google 4 Twitter profile page', func=get_profile_url,\n    description='useful for when you need get the Twitter Page URL')\n", (652, 787), False, 'from langchain_core.tools import Tool\n')]