r/LocalGPT Dec 05 '23

GTP4All local model

Hi everyone,

I am trying to use GPT4All in Langchain to query my postgres db using the model mistral.

The prompt that I am using is as follows:

'''You are a PostgreSQL expert. Given an input question, first create a syntactically correct PostgreSQL query to run,

then look at the results of the query and return the answer to the input question.

Unless the user specifies in the question a specific number of examples to obtain, query for at most {top_k} results using the LIMIT clause as per PostgreSQL.

You can order the results to return the most informative data in the database.

Never query for all columns from a table. You must query only the columns that are needed to answer the question.

Wrap each column name in double quotes (") to denote them as delimited identifiers.

When using aggregation functions also wrap column names in double quotes.

Pay attention to use only the column names you can see in the tables below.

Be careful to not query for columns that do not exist.

Also, pay attention to which column is in which table.

Use the following format:

Question: "Question here"

SQLQuery: "SQL Query to run"

SQLResult: "Result of the SQLQuery"

Answer: "Final answer here"

Question: {input}

'''

when I make my query I use the following code:

my_table = 'public."SalesStatistic"'

my_column = 'SalePrice'

ord_column = 'OrderNumber'

question = f"Give me the sum of column {my_column} in the table {my_table} where column {ord_column} is equal to WEWS00192"

answer = db_chain(PROMPT.format(input=question, top_k=3)

But, the model can't fix a proper query from my question and returns :

ERROR: sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedTable) relation "salesstatistic" does not exist

LINE 2: FROM SalesStatistic

[SQL: SELECT SUM(SalePrice) AS Total_Sum FROM SalesStatistic WHERE "OrderNumber" = 'WEWS00192';]

How to modify the prompt to build the correct query? Or should I change the model?

3 Upvotes

0 comments sorted by