tools = [ Tool( name="GPT Index", func=lambda q: str(index.as_query_engine().query(q)), description="useful for when you want to answer questions about the author. The input to this tool should be a complete english sentence.", return_direct=True, ), ] memory = ConversationBufferMemory(memory_key="chat_history") llm = ChatOpenAI(temperature=0) agent_chain = initialize_agent(tools, llm, agent="conversational-react-description", memory=memory)
def query_with_sources(query_str, query_engine=None): response = query_engine.query(query_str) print(response.source_nodes) return str(response) ... func=lambda q: query_with_sources(q, query_engine=index.query_engine), ...