Langchain sqlagent - 错误:在数据库中找不到表名 {'inventory Observ'}

thtygnil  于 2个月前  发布在  其他
关注(0)|答案(2)|浏览(30)

检查其他资源

  • 为这个问题添加了一个非常描述性的标题。
  • 使用集成搜索在LangChain文档中搜索。
  • 使用GitHub搜索查找类似的问题,但没有找到。
  • 我确信这是LangChain中的一个bug,而不是我的代码。
  • 通过更新到LangChain的最新稳定版本(或特定集成包)无法解决此错误。

示例代码

from langchain_nvidia_ai_endpoints import ChatNVIDIA
from langchain_community.utilities.sql_database import SQLDatabase
from langchain_community.agent_toolkits.sql.base import create_sql_agent
from langchain_community.agent_toolkits.sql.toolkit import SQLDatabaseToolkit
from langchain.agents.agent_types import AgentType
import os
import logging

client = ChatNVIDIA(
    model="meta/llama-3.1-405b-instruct",
    api_key="api_key",
    temperature=0.2,
    top_p=0.7,
    max_tokens=1024,
)
inventory_db_path = os.path.expanduser('~/database.db')
db = SQLDatabase.from_uri(f"sqlite:///{inventory_db_path}")
toolkit = SQLDatabaseToolkit(db=db, llm=client)
agent_executor = create_sql_agent(
    llm=client,
    toolkit=toolkit,
    verbose=True,
)

def handle_conversation(context, user_input):
    try:
        result = agent_executor.run(user_input)
        return result
    except Exception as e:
        logging.error(f"Exception in handle_conversation: {e}")
        return "Error: Exception occurred while processing the request."

错误信息和堆栈跟踪(如果适用)

动作:sql_db_schema
动作输入:inventory, inband_ping
ObserDEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): integrate.api.nvidia.com:443
DEBUG:urllib3.connectionpool: https://integrate.api.nvidia.com:443 "POST /v1/chat/completions HTTP/11" 200 None
错误:table_names {'inband_ping\nObserv'} not found in databaseIt looks like you're having trouble getting the schema of the 'inventory' table. Let me try a different approach.

描述

当前运行langchain==0.2.11,使用llama3.1针对sqlite数据库查询表中的数据,但遇到了一个问题,即LLM在使用nObserv在数据库中搜索表时。我尝试使用不同的LLM模型(llama、mistra),并遇到了相同的问题。

dced5bon

dced5bon1#

请有人能帮我解决这个问题吗?这样我就可以利用LLM执行SQL查询并相应地提供输出了。我被困在错误中:table_names {'psu_status
Observ'} not found in database

jyztefdp

jyztefdp2#

表名似乎不正确,例如'psu_status
Observ'。这些名称与任何数据库都不兼容。请问您能否手动验证这些表是否存在?另外,将intermediate_steps设置为True有助于查看代理所采取的步骤。

相关问题