使用 langchain、nlp 和 llm 无法正确生成 SQL 查询

问题描述 投票:0回答:1

我创建了一个应用程序,它接受输入问题并使用 langchain、llm 和 nlp 将其转换为 SQL 查询,但有时它会创建错误的查询,特别是在开头,下面是我为该应用程序编写的代码。

def rds_answer(question):
    """
    This function collects all necessary information to execute the sql_db_chain and get an answer generated, taking
    a natural language question in and returning an answer and generated SQL query.
    :param question: The question the user passes in from the frontend
    :return: The final answer in natural langauge along with the generated SQL query.
    """

    rds_uri = get_rds_uri()
    db = SQLDatabase.from_uri(rds_uri)
    examples = load_samples()
    sql_db_chain = load_few_shot_chain(llm, db, examples)

    print("sql_db_chain: ",sql_db_chain)
    answer = sql_db_chain(question)
    return answer["intermediate_steps"][1], answer["result"]
python-3.x langchain large-language-model py-langchain langchain-agents
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.