from langchain_community.utilities.dataherald import DataheraldAPIWrapperfrom langchain_community.tools.dataherald.tool import DataheraldTextToSQLfrom langchain_openai import ChatOpenAIfrom langchain import hubfrom langchain.agents import AgentExecutor, create_react_agent, load_toolsapi_wrapper = DataheraldAPIWrapper(db_connection_id="<db_connection_id>")tool = DataheraldTextToSQL(api_wrapper=api_wrapper)llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)prompt = hub.pull("hwchase17/react")agent = create_react_agent(llm, tools, prompt)agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True, handle_parsing_errors=True)agent_executor.invoke({"input":"Return the sql for this question: How many employees are in the company?"})
Output
Copy
Ask AI
> Entering new AgentExecutor chain...I need to use a tool that can convert this question into SQL.Action: dataheraldAction Input: How many employees are in the company?Answer: SELECT COUNT(*) FROM employeesI now know the final answerFinal Answer: SELECT COUNT(*)FROM employees> Finished chain.{'input': 'Return the sql for this question: How many employees are in the company?', 'output': "SELECT \n COUNT(*)\nFROM \n employees"}