Cannot add memory langchain

207 Views Asked by At

I am using python with langchain. And i have problem with using memory in SQLDatabaseSequentialChain.

template = """... {chat_history} ... {table_info} ... {input}"""

prompt = PromptTemplate(template=template, input_variables=["chat_history", "table_info", "input"])

llm = ChatOpenAI(temperature=0, model="gpt-4", verbose=True,
                          openai_api_key=openai_api_key)

db_use = SQLDatabase.from_uri(
        connection_str,
        schema="public",
        sample_rows_in_table_info=1,
        custom_table_info=custom_table_info,
        ignore_tables=ignore_tables
    )

memory = ConversationBufferWindowMemory(k=6, memory_key="chat_history")

db_chain = SQLDatabaseSequentialChain.from_llm(
        llm=llm,
        db=db_use,
        verbose=True,
        query_prompt=prompt,
        memory=memory,
        use_query_checker=True,
    )

And how i run my db_chain

db_chain({
        "input": question,
        "table_info": table_info,
        "chat_history": history,
        "query": question,
    })

My table_info is schema string of db

history is string from array

And my problem, when i run this code i get error

ValueError: One input key expected got ['table_names_to_use', 'query']

I made it how it shows in examples but i don't understand why i get this error

And also when i remove from parameters query i got error:

Missing some input keys: {'query'}

Any advice can help me

0

There are 0 best solutions below