-
Notifications
You must be signed in to change notification settings - Fork 15.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to execute related query functions using CassandraDatabaseToolkit. #28878
Comments
@BACMiao It is very difficult to help you without you providing the output. Can you please provide the output? But please note one thing, the model used in tutorial is |
@keenborder786 Thank you very much. Based on your suggestion, I updated the model to The codes: # Import necessary libraries
import os
import cassio
from langchain import hub
from langchain.agents import AgentExecutor, create_openai_tools_agent
from langchain_community.agent_toolkits.cassandra_database.toolkit import (
CassandraDatabaseToolkit,
)
from langchain_community.tools.cassandra_database.prompt import QUERY_PATH_PROMPT
from langchain_community.utilities.cassandra_database import CassandraDatabase
from langchain_community.chat_models.openai import ChatOpenAI
from dotenv import load_dotenv
def init_cassandra():
load_dotenv(override=True)
cassio.init(auto=True)
session = cassio.config.resolve_session()
if not session:
raise Exception(
"Check environment configuration or manually configure cassio connection parameters"
)
session.execute("""DROP KEYSPACE IF EXISTS langchain_agent_test; """)
session.execute(
"""
CREATE KEYSPACE if not exists langchain_agent_test
WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
"""
)
session.execute(
"""
CREATE TABLE IF NOT EXISTS langchain_agent_test.user_credentials (
user_email text PRIMARY KEY,
user_id UUID,
password TEXT
);
"""
)
session.execute(
"""
CREATE TABLE IF NOT EXISTS langchain_agent_test.users (
id UUID PRIMARY KEY,
name TEXT,
email TEXT
);"""
)
session.execute(
"""
CREATE TABLE IF NOT EXISTS langchain_agent_test.user_videos (
user_id UUID,
video_id UUID,
title TEXT,
description TEXT,
PRIMARY KEY (user_id, video_id)
);
"""
)
user_id = "522b1fe2-2e36-4cef-a667-cd4237d08b89"
video_id = "27066014-bad7-9f58-5a30-f63fe03718f6"
session.execute(
f"""
INSERT INTO langchain_agent_test.user_credentials (user_id, user_email)
VALUES ({user_id}, '[email protected]');
"""
)
session.execute(
f"""
INSERT INTO langchain_agent_test.users (id, name, email)
VALUES ({user_id}, 'Patrick McFadin', '[email protected]');
"""
)
session.execute(
f"""
INSERT INTO langchain_agent_test.user_videos (user_id, video_id, title)
VALUES ({user_id}, {video_id}, 'Use Langflow to Build a LangChain LLM Application in 5 Minutes');
"""
)
session.set_keyspace("langchain_agent_test")
def test_sql_agent(prompt):
load_dotenv(override=True)
cassio.init(auto=True)
session = cassio.config.resolve_session()
if not session:
raise Exception(
"Check environment configuration or manually configure cassio connection parameters"
)
db = CassandraDatabase(session=session)
llm = ChatOpenAI(temperature=0, model="gpt-4-1106-preview")
toolkit = CassandraDatabaseToolkit(db=db)
tools = toolkit.get_tools()
print("Available tools:")
for tool in tools:
print(tool.name + "\t- " + tool.description)
agent = create_openai_tools_agent(llm, tools, hub.pull("hwchase17/openai-tools-agent"))
input = (
QUERY_PATH_PROMPT
+ "\n\n" + prompt
)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
response = agent_executor.invoke({"input": input})
print(response["output"])
if __name__ == "__main__":
# init_cassandra()
prompt = f"Forget all our previous conversations. Here is your task: In the langchain_agent_test keyspace Find all the videos that the user with the email address '[email protected]' has uploaded to the langchain_agent_test keyspace and tell me the result"
test_sql_agent(prompt) |
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
No response
Description
I want to use CassandraDatabaseToolkit to process data. I referred to the tutorial at https://python.langchain.com/v0.2/docs/integrations/tools/cassandra_database/, but unfortunately, my output is completely different from what is shown in the documentation. Through debugging, we found that it directly returned ActionFinish without executing the tools. Further analysis revealed that tool_calls is empty. Could you please explain why this is happening?
System Info
openai==1.14.0
langchain-community==0.3.18
The text was updated successfully, but these errors were encountered: