获取create_sql_chain适用于gpt-4

我当前的代码在使用gpt-3.5-turbo-instruct时可以正常工作,但在使用gpt-4时却无法工作。我喜欢使用这个框架,因为我只想得到SQL代码,而其他代理无法做到这一点。我该如何修改代码,以便可以使用其他GPT模型?

from langchain.chains import create_sql_query_chainconnection_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 + restrictionsPROMPT = 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)

回答:

JK找到了解决方案!将OpenAI改为ChatOpenAI就解决了问题

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注