sql_agent 在 Ajax llm 中返回解析器错误

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

我试图通过向代理提供提示来生成 SQL 查询,但是当我尝试执行代理来生成 SQL 查询时,它给了我错误, “此输出解析器仅适用于 ChatGeneration 输出”。 我正在使用 Ajax 使用 Turbo,它生成 SQL,没有给出错误。 有人可以帮我吗?

我希望它生成一些 SQL 查询。

ajax prompt large-language-model few-shot-learning
1个回答
0
投票

这是我的代码:

system_prefix = """You are an agent designed to interact with a SQL database.
Given an input question, create a syntactically correct {dialect} query to run, then look at the results of the query and return the answer.
Unless the user specifies a specific number of examples they wish to obtain, always limit your query to at most {top_k} results.
You can order the results by a relevant column to return the most interesting examples in the database.
Never query for all the columns from a specific table, only ask for the relevant columns given the question.
You have access to tools for interacting with the database.
Only use the given tools. Only use the information returned by the tools to construct your final answer.
You MUST double check your query before executing it. If you get an error while executing a query, rewrite the query and try again.

DO NOT make any DML statements (INSERT, UPDATE, DELETE, DROP etc.) to the database.

If the question does not seem related to the database, just return "I don't know" as the answer."""

few_shot_prompt = FewShotPromptTemplate(
    example_selector=example_selector,
    example_prompt=PromptTemplate.from_template(
        "User input: {input}\nSQL query: {query}"
    ),
    input_variables=["input", "dialect", "top_k"],
    prefix=system_prefix,
    suffix="",
    partial_variables={"format_instructions": new_parser.get_format_instructions()},
)



full_prompt = ChatPromptTemplate.from_messages(
    [
        SystemMessagePromptTemplate(prompt=few_shot_prompt),
        ("human", "{input}"),
        MessagesPlaceholder("agent_scratchpad"),
        
    ]
)


agent = create_sql_agent(
    llm=llm,
    db=db,
    prompt=full_prompt,
    verbose=True,
    agent_type="openai-tools",
)
© www.soinside.com 2019 - 2024. All rights reserved.