提问人:ML Ops 提问时间:9/27/2023 最后编辑:ML Ops 更新时间:10/26/2023 访问量:136
langchain sqlagent 回复错误结果
langchain sqlagent reply with wrong result
问:
我有一个简单的SQLagent,它查询表上带有ID和电子邮件地址的数据库。 我想检查是否有匹配的电子邮件并用 id 回复。 如果没有匹配,则回复 none。
如果存在匹配项,则工作正常,但是如果没有匹配项,但有更接近匹配的电子邮件,则返回 ID 列中的随机值。例如,如果 myFirstName.Last[email protected] 匹配,它可以工作,但是如果我传入 myFirstName.LastnamA@mydomain.com 它将返回一个随机 ID。 关于如何解决这个问题的任何想法?
``*dburi = "sqlite:///data/users.db"
db = SQLDatabase.from_uri(dburi)
toolkit = SQLDatabaseToolkit(db=db, llm=OpenAI(temperature=0))
agent_executor = create_sql_agent(
llm=OpenAI(temperature=0),
toolkit=toolkit,
verbose=True,
agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
)
agent_executor.run("What is the id for email is exactly [email protected]. I want 100% match ignoring the case. If you can not find it reply with NONE")*`
`
如果存在匹配项,则工作正常,但是如果没有匹配项,但有更接近匹配的电子邮件,则返回 ID 列中的随机值。例如,如果 myFirstName.Last[email protected] 匹配,它可以工作,但是如果我传入 myFirstName.LastnamA@mydomain.com 它将返回一个随机 ID。
答:
1赞
ML Ops
9/27/2023
#1
我设法更改了查询并解决了这个问题。 我的新查询是:
agent_executor.run("Do you have a record with email is [email protected]. I want 100% match ignoring the case. If you have a match reply with the ID. If you can not find it reply with NONE")
0赞
ZKS
9/28/2023
#2
您可以根据需要使用以下代码,并稍作调整
dburi = "sqlite:///data/users.db"
db = SQLDatabase.from_uri(dburi)
toolkit = SQLDatabaseToolkit(db=db, llm=OpenAI(temperature=0))
custom_suffix = """
Filter the records based on exact match, ignore similar search or close matched records
"""
agent_executor = create_sql_agent(
llm=OpenAI(temperature=0),
toolkit=toolkit,
verbose=True,
agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
suffix=custom_suffix
)
agent_executor.run("What is the id for email [email protected]")
评论