Azure Gpt35Turbo replies very differently from OpenAI Gpt3.5 turbo

Sora Teichman 0 Reputation points
2023-12-06T13:16:47.9+00:00

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/"))

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
4,101 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Saurabh Sharma 23,851 Reputation points Microsoft Employee Moderator
    2023-12-15T16:06:01.69+00:00

    Sora Teichman That is the good place to add any information that you want agent to know before generating a query. However, you should also be careful not to make the prefix too long or complex, as it might confuse the agent or reduce its performance. You can use the input_variables parameter to pass any variables that you want the agent to use in the prefix, such as the database name, the table names, the column names, etc. This way, you can reuse the same prefix for different databases or queries by changing the input variables. Can you please try using input_variables along with prefix ?

    Ref: https://python.langchain.com/docs/use_cases/qa_structured/sql

    Thanks

    Saurabh

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.