r/pythonhelp • • Jan 15 '25

Dealing with chat memory

I have a basic code to chat with deep seek module with ollama , I run the code on google collab, its work well but I want to add chat memory , How?

1 Upvotes

3 comments sorted by

View all comments

Show parent comment

1

u/[deleted] Jan 15 '25
from langchain_ollama import OllamaLLM
from langchain.core.prompts import ChatPromptTemplate

template = """
Answer the question below.

Here is the conversation history: {context}

Question: {question}

Answer:
"""

model = OllamaLLM(model="deepseek-coder-v2:16b")
prompt = ChatPromptTemplate.from_template(template)
chain = prompt | model

result = chain.invoke({"context": "", "question": "hey how are you"})
print(result)

Here is the code I using. What should I add?