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] <> You are a helpful developed by Mohammed Vasim, respectful and honest assistant. Your answers are always brief. <> {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