{ “10”:{ “数量”:“10”, …… } }
使用 `{'query' 调用:sql_db_query_checker: "SELECT JSON_UNQUOTE(JSON_EXTRACT(point_of_sales, '$.*.quantity')) AS 数量 FROM 库存 WHERE store = 'STORE_NAME'
下面是实际执行的查询结果 [(None,)]
调用:sql_db_query with `{'query': "SELECT JSON_UNQUOTE(JSON_EXTRACT(point_of_sales, '$.[*].quantity')) AS 数量 FROM stock WHERE store = 'STORE_NAME'
实际执行的查询('$..' vs '$.[].)生成不同的原因是什么?请帮我解决。
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=""
)
full_prompt = ChatPromptTemplate.from_messages(
[
SystemMessagePromptTemplate(prompt=few_shot_prompt),
("human", "{input}"),
MessagesPlaceholder("agent_scratchpad"),
]
)
agent_with_few_shots = create_sql_agent(
llm=llm,
db=db,
prompt=full_prompt,
verbose=True,
agent_type="tool-calling",
stream_runnable = False,
max_iterations=5,
agent_executor_kwargs = {"return_intermediate_steps": True},
top_k = 2
)
agent_with_few_shots.invoke({
"input": "list all the quantities in point of sale data of the STOCK of STORE_NAME"})`enter code here`
从响应中捕获日志并为您的工具解析它。然后使用该 SQL 来执行
response = agent_with_few_shots.invoke(...)
queries = []
for (log, output) in response["intermediate_steps"]:
if log.tool == 'sql_db_query_checker':
queries.append(log.tool_input)