SQLDatabaseKit - using langchain, Class module error

316 Views Asked by At

Getting ValidationError: 1 validation error for SQLDatabaseToolkit llm value is not a valid dict (type=type_error.dict).

Please suggest what am I missing. Thank you

import torch
from transformers import pipeline, AutoTokenizer,AutoModelForSeq2SeqLM,AutoModelForCausalLM
from langchain.agents import create_sql_agent
from langchain.agents.agent_toolkits import SQLDatabaseToolkit
from langchain.sql_database import SQLDatabase

#define model and tokenizer
model_name = "databricks/dolly-v2-12b"
tokenizer = AutoTokenizer.from_pretrained(model_name)
#model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained("databricks/dolly-v2-12b", device_map="auto", torch_dtype=torch.bfloat16)

#initialize the sql database
db = SQLDatabase.from_databricks(catalog="samples", schema="nyctaxi")

#initialize the sql database with huuginface mode.
toolkit = SQLDatabaseToolkit(llm=model, db=db)

#create the SQl agent with hugging face model and toolkit
agent = create_sql_agent(llm=model, toolkit=toolkit, verbose=True)

#run the sql
query ="What is the longest trip distance and how long did it take?"
response=agent.run(query)

#print the response
print(response)

0

There are 0 best solutions below