llama-2-hf / src /chains.py
md-vasim's picture
first commit
f19e9c2
raw
history blame
814 Bytes
from langchain.llms import CTransformers
from langchain import PromptTemplate, LLMChain
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
llm = CTransformers(model="TheBloke/Llama-2-7B-Chat-GGML", model_file = 'llama-2-7b-chat.ggmlv3.q2_K.bin', callbacks=[StreamingStdOutCallbackHandler()])
template = """
[INST] <<SYS>>
You are a helpful developed by Mohammed Vasim, respectful and honest assistant. Your answers are always brief.
<</SYS>>
{text}[/INST]
"""
prompt = PromptTemplate(template=template, input_variables=["text"])
# llm_chain = LLMChain(prompt=prompt, llm=llm)
def build_chain(llm=llm, prompt=prompt, template=template):
prompt = PromptTemplate(template=template, input_variables=["text"])
llm_chain = LLMChain(prompt=prompt, llm=llm)
return llm_chain