Spaces:
Running
Running
clementsan commited on
Commit ·
ecf1633
1
Parent(s): 5db4902
Use HuggingFaceEndpoint
Browse files8 unmodified lines910111213141585 unmodified lines1011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311328 unmodified linesfrom langchain_community.llms import HuggingFacePipelinefrom langchain.chains import ConversationChainfrom langchain.memory import ConversationBufferMemoryfrom langchain.llms import HuggingFaceHubfrom pathlib import Pathimport chromadb85 unmodified lines# Warning: langchain issue# URL: https://github.com/langchain-ai/langchain/issues/6080if llm_model == "mistralai/Mixtral-8x7B-Instruct-v0.1":llm = HuggingFaceHub(repo_id=llm_model,model_kwargs={"temperature": temperature, "max_new_tokens": max_tokens, "top_k": top_k, "load_in_8bit": True})elif llm_model == "microsoft/phi-2":raise gr.Error("phi-2 model requires 'trust_remote_code=True', currently not supported by langchain HuggingFaceHub...")llm = HuggingFaceHub(repo_id=llm_model,model_kwargs={"temperature": temperature, "max_new_tokens": max_tokens, "top_k": top_k, "trust_remote_code": True, "torch_dtype": "auto"})elif llm_model == "TinyLlama/TinyLlama-1.1B-Chat-v1.0":llm = HuggingFaceHub(repo_id=llm_model,model_kwargs={"temperature": temperature, "max_new_tokens": 250, "top_k": top_k})elif llm_model == "meta-llama/Llama-2-7b-chat-hf":raise gr.Error("Llama-2-7b-chat-hf model requires a Pro subscription...")llm = HuggingFaceHub(repo_id=llm_model,model_kwargs={"temperature": temperature, "max_new_tokens": max_tokens, "top_k": top_k})else:llm = HuggingFaceHub(repo_id=llm_model,# model_kwargs={"temperature": temperature, "max_new_tokens": max_tokens, "top_k": top_k, "trust_remote_code": True, "torch_dtype": "auto"}model_kwargs={"temperature": temperature, "max_new_tokens": max_tokens, "top_k": top_k})progress(0.75, desc="Defining buffer memory...")8 unmodified lines910111213141585 unmodified lines1011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491508 unmodified linesfrom langchain_community.llms import HuggingFacePipelinefrom langchain.chains import ConversationChainfrom langchain.memory import ConversationBufferMemoryfrom langchain_community.llms import HuggingFaceEndpointfrom pathlib import Pathimport chromadb85 unmodified lines# Warning: langchain issue# URL: https://github.com/langchain-ai/langchain/issues/6080if llm_model == "mistralai/Mixtral-8x7B-Instruct-v0.1":llm = HuggingFaceEndpoint(repo_id=llm_model,# model_kwargs={"temperature": temperature, "max_new_tokens": max_tokens, "top_k": top_k, "load_in_8bit": True}temperature = temperature,max_new_tokens = max_tokens,top_k = top_k,load_in_8bit = True,)elif llm_model == "microsoft/phi-2":raise gr.Error("phi-2 model requires 'trust_remote_code=True', currently not supported by langchain HuggingFaceHub...")llm = HuggingFaceEndpoint(repo_id=llm_model,# model_kwargs={"temperature": temperature, "max_new_tokens": max_tokens, "top_k": top_k, "trust_remote_code": True, "torch_dtype": "auto"}temperature = temperature,max_new_tokens = max_tokens,top_k = top_k,trust_remote_code = True,torch_dtype = "auto",)elif llm_model == "TinyLlama/TinyLlama-1.1B-Chat-v1.0":llm = HuggingFaceEndpoint(repo_id=llm_model,# model_kwargs={"temperature": temperature, "max_new_tokens": 250, "top_k": top_k}temperature = temperature,max_new_tokens = 250,top_k = top_k,)elif llm_model == "meta-llama/Llama-2-7b-chat-hf":raise gr.Error("Llama-2-7b-chat-hf model requires a Pro subscription...")llm = HuggingFaceEndpoint(repo_id=llm_model,# model_kwargs={"temperature": temperature, "max_new_tokens": max_tokens, "top_k": top_k}temperature = temperature,max_new_tokens = max_tokens,top_k = top_k,)else:llm = HuggingFaceEndpoint(repo_id=llm_model,# model_kwargs={"temperature": temperature, "max_new_tokens": max_tokens, "top_k": top_k, "trust_remote_code": True, "torch_dtype": "auto"}# model_kwargs={"temperature": temperature, "max_new_tokens": max_tokens, "top_k": top_k}temperature = temperature,max_new_tokens = max_tokens,top_k = top_k,)progress(0.75, desc="Defining buffer memory...")
app.py+29-11