Hi,
We are using AzureOpenAI with langchain to generate SQL queries and run them against our database to answer user queries. I noticed that when I use the AzureChatOpenAI llm, it often returns far inferior responses than the OpenAI llm. Here's an example: I ran the same query: How many sales orders were placed in November 2023?
OpenAI was able to formulate the correct sql and returned the correct response.
...
Thought: I should query the SalesOrders table to get the number of sales orders created in November 2023.
Action: sql_db_query
Action Input: SELECT COUNT(*) FROM SalesOrders WHERE CreatedOn BETWEEN '2023-11-01' AND '2023-11-30'
Observation: [(17,)]
Thought: I now know the final answer.
Final Answer: 17 sales orders were created in November 2023.
However when I use AzureChatOpenAI, it puts backticks before and after any query that it formats into more than one line, causing syntax errors when it tries to run it in sql. It does not listen to my custom instructions to leave out backticks.
I've tried it with different API versions (2023-05-01) but it does not help.
See the 2 versions of the code here:
toolkit = SQLDatabaseToolkit(db=db, llm=OpenAI(temperature=0, openai_api_key="sk-xxx"))
toolkit = SQLDatabaseToolkit(db=db, llm=AzureChatOpenAI(temperature=0, deployment_name="xx", openai_api_version="2023-09-01-preview", openai_api_type="azure", openai_api_base="https://xxx.openai.azure.com/"))