Replies: 1 comment 3 replies
-
Answer generated by a 🤖 AnswerI found related issues that might be helpful. I did my best to summarize the solutions, but I recommend looking at the related issues yourself. Open IssuesHow to add memory to SQLDatabaseChain?The suggested solution is: For anyone coming in the future. Currently, passing memory directly in from langchain.agents.agent_toolkits import create_sql_agent,SQLDatabaseToolkit
from langchain.agents.agent_types import AgentType
from langchain.sql_database import SQLDatabase
from langchain.chat_models.openai import ChatOpenAI
from langchain.memory import ConversationBufferMemory
memory = ConversationBufferMemory(memory_key = 'history' , input_key = 'input')
llm = ChatOpenAI(model_name = GPT_MODEL_NAME , temperature = 0)
db = SQLDatabase.from_uri(CONN_STRING)
suffix = """Begin!
Relevant pieces of previous conversation:
{history}
(You do not need to use these pieces of information if not relevant)
Question: {input}
Thought: I should look at the tables in the database to see what I can query. Then I should query the schema of the most relevant tables.
{agent_scratchpad}
"""
executor = create_sql_agent(
llm = llm,
toolkit = SQLDatabaseToolkit(db=db, llm=llm),
agent_type = AgentType.ZERO_SHOT_REACT_DESCRIPTION,
input_variables = ["input", "agent_scratchpad","history"],
suffix = suffix # must have history as variable,
agent_executor_kwargs = {'memory':memory}
) This response is meant to be useful, save you time, and share context. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I would like to add memory to my chatbot. Since most of the times it picks the entire dataset for filtering and querying, can I use embeddings here?
If yes how can I incorporate them, please help me.
here is my code.
import pymysql
from langchain import SQLDatabaseChain
from langchain.sql_database import SQLDatabase
import urllib.parse
db_user = "XXX"
db_password = "XXX"
encoded_password = urllib.parse.quote_plus(db_password)
db_host = "XXX.mysql.database.azure.com"
db_name = "XX"
ssl_ca = r"XXX"
db = SQLDatabase.from_uri(database_uri=f"mysql+pymysql://{db_user}:{db_password}@{db_host}/{db_name}?ssl_ca={ssl_ca}")
)
from langchain.chat_models import ChatOpenAI, AzureChatOpenAI
llm = AzureChatOpenAI(deployment_name='gpt-35-turbo',
model_name='gpt-35-turbo',
openai_api_base='XXX',
openai_api_version='2023-05-15',
openai_api_key='XXX',
temperature=0)
db_chain = SQLDatabaseChain.from_llm(llm, db, verbose=True)
sys_msg = """some prompt
Here is the question.
Question: {question}
Answer:
"""
def get_prompt():
print("Type 'exit' to quit")
get_prompt()
Beta Was this translation helpful? Give feedback.
All reactions