|
import os |
|
from langchain import PromptTemplate, HuggingFaceHub, LLMChain |
|
from langchain.memory import ConversationBufferMemory |
|
from langchain.chains import ConversationChain |
|
import langchain.globals |
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
|
|
def get_Model(hugging_face_key): |
|
tokenizer = AutoTokenizer.from_pretrained("KvrParaskevi/Hotel-Assistant-Attempt4-Llama-2-7b",use_auth_token=hugging_face_key) |
|
model = AutoModelForCausalLM.from_pretrained("KvrParaskevi/Hotel-Assistant-Attempt4-Llama-2-7b",use_auth_token=hugging_face_key).eval() |
|
return model |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def demo_miny_memory(model): |
|
|
|
memory = ConversationBufferMemory(llm = model,max_token_limit = 512) |
|
return memory |
|
|
|
def demo_chain(input_text, memory,model): |
|
|
|
llm_conversation = ConversationChain(llm=model,memory=memory,verbose=langchain.globals.get_verbose()) |
|
|
|
chat_reply = llm_conversation.predict(input=input_text) |
|
return chat_reply |