Reputation: 51
The current code I have below works when I use gpt-3.5-turbo-instruct however when I use gpt-4 it doesn't work. I like using this framework because i care about getting only sql code back which the other agents don't do. How do I change it so that I can use other gpt models.
from langchain.chains import create_sql_query_chain
connection_string = ""
db = SQLDatabase.from_uri(connection_string)
llm = OpenAI(temperature=0, verbose=True, model='gpt-4')
seed_prompt = """
Given an input question, create a syntactically correct MySQL SQL query to run.
Question: "Question here"
SQLQuery: "SQL Query to run"
"""
restrictions = """
Never use LIMIT statement, use TOP statement instead.
Format all numeric response ###,###,###,###.
Only return relevant columns to the question.
If a table or column does not exist, return table or column could not be found.
Question: {input}
"""
prompt = seed_prompt + restrictions
PROMPT = PromptTemplate(
input_variables=["input"], template=prompt
)
database_chain = create_sql_query_chain(llm,db, prompt=PROMPT)
sql_query = database_chain.invoke({"question": x})
print(sql_query)
Upvotes: 0
Views: 478
Reputation: 51
JK found a resolution! Changed OpenAI to ChatOpenAI and it did the trick
Upvotes: 1