from dotenv import load_dotenv
import langchain
from langchain.chat_models import ChatOpenAI
from langchain.agents import initialize_agent, AgentType
from agent.tools.ontology import ontology_tool
from agent.tools.interview import PAInterview
import os
from langchain.prompts import MessagesPlaceholder
from langchain.memory import ConversationBufferMemory

agent_kwargs = {
    "extra_prompt_messages": [MessagesPlaceholder(variable_name="memory")],
}
memory = ConversationBufferMemory(memory_key="memory", return_messages=True)
#langchain.debug = True

load_dotenv()
openai_api_key=os.environ['OPENAI_API_KEY']

# Because we are using functions, we need to use model gpt-4-0613
llm=ChatOpenAI(openai_api_key=openai_api_key,temperature=0, model="gpt-4-0613")

tools = [ontology_tool,PAInterview()]

agent = initialize_agent(tools, llm, agent=AgentType.OPENAI_FUNCTIONS, verbose=True, agent_kwargs=agent_kwargs, memory=memory)

langchain.agents.initialize_agent langchain.memory.ConversationBufferMemory langchain.prompts.MessagesPlaceholder langchain.chat_models.ChatOpenAI
[((462, 529), 'langchain.memory.ConversationBufferMemory', 'ConversationBufferMemory', ([], {'memory_key': '"""memory"""', 'return_messages': '(True)'}), "(memory_key='memory', return_messages=True)\n", (486, 529), False, 'from langchain.memory import ConversationBufferMemory\n'), ((555, 568), 'dotenv.load_dotenv', 'load_dotenv', ([], {}), '()\n', (566, 568), False, 'from dotenv import load_dotenv\n'), ((684, 760), 'langchain.chat_models.ChatOpenAI', 'ChatOpenAI', ([], {'openai_api_key': 'openai_api_key', 'temperature': '(0)', 'model': '"""gpt-4-0613"""'}), "(openai_api_key=openai_api_key, temperature=0, model='gpt-4-0613')\n", (694, 760), False, 'from langchain.chat_models import ChatOpenAI\n'), ((808, 930), 'langchain.agents.initialize_agent', 'initialize_agent', (['tools', 'llm'], {'agent': 'AgentType.OPENAI_FUNCTIONS', 'verbose': '(True)', 'agent_kwargs': 'agent_kwargs', 'memory': 'memory'}), '(tools, llm, agent=AgentType.OPENAI_FUNCTIONS, verbose=True,\n    agent_kwargs=agent_kwargs, memory=memory)\n', (824, 930), False, 'from langchain.agents import initialize_agent, AgentType\n'), ((784, 797), 'agent.tools.interview.PAInterview', 'PAInterview', ([], {}), '()\n', (795, 797), False, 'from agent.tools.interview import PAInterview\n'), ((405, 448), 'langchain.prompts.MessagesPlaceholder', 'MessagesPlaceholder', ([], {'variable_name': '"""memory"""'}), "(variable_name='memory')\n", (424, 448), False, 'from langchain.prompts import MessagesPlaceholder\n')]