-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat_example.py
45 lines (33 loc) · 1.2 KB
/
chat_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from langchain import ConversationChain, LLMChain, PromptTemplate
from langchain.memory import ConversationBufferWindowMemory
from langchain.llms import LlamaCpp
from langchain.callbacks.manager import CallbackManager
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
callback_manager = CallbackManager([StreamingStdOutCallbackHandler()])
llm = LlamaCpp(
model_path="../models/wizardLM-7B.ggmlv3.q4_1.bin",
callback_manager=callback_manager,
verbose=True,
)
template = """You support me in identifying gratitude in my life.
You help me find gratitude. Your language is simple, clear,
and you are enthusiastic, compassionate, and caring.
Your responses are short and one or two lines.
{history}
Human: {human_input}
Assistant:"""
prompt = PromptTemplate(
input_variables=["history", "human_input"],
template=template
)
chatgpt_chain = LLMChain(
llm=llm,
prompt=prompt,
verbose=False,
memory=ConversationBufferWindowMemory(k=2),
)
print("GratitudeLLM loading...")
output = chatgpt_chain.predict(human_input="Let's get started")
while True:
human_input = input("\nHuman: ")
output = chatgpt_chain.predict(human_input=human_input)