boryasbora commited on
Commit
65b9327
·
verified ·
1 Parent(s): 1b3714a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -4,8 +4,9 @@ import pickle
4
  from langchain.prompts import ChatPromptTemplate
5
  from langchain.text_splitter import RecursiveCharacterTextSplitter
6
  from langchain_huggingface import HuggingFaceEmbeddings
7
- # from huggingface_llm import HuggingFaceLLM
8
- from langchain import HuggingFaceLLM
 
9
  from langchain.retrievers import ParentDocumentRetriever
10
  from langchain.storage import InMemoryStore
11
  from langchain_chroma import Chroma
@@ -80,12 +81,14 @@ def get_chain(temperature):
80
  retriever = load_retriever(docstore_path,chroma_path,embeddings,child_splitter,parent_splitter)
81
 
82
  # Replace the local OLMOLLM with the Hugging Face model
 
83
  model_name = "gpt2"
84
- tokenizer = AutoTokenizer.from_pretrained(model_name)
85
- model = AutoModelForCausalLM.from_pretrained(model_name)
 
 
86
 
87
  # Initialize LangChain
88
- llm = HuggingFaceLLM(model=model, tokenizer=tokenizer)
89
  # llm = HuggingFaceLLM(
90
  # model_id="EleutherAI/gpt-neo-1.3B", # or another suitable model
91
  # temperature=temperature,
 
4
  from langchain.prompts import ChatPromptTemplate
5
  from langchain.text_splitter import RecursiveCharacterTextSplitter
6
  from langchain_huggingface import HuggingFaceEmbeddings
7
+ from transformers import pipeline
8
+ from langchain import HuggingFacePipeline
9
+
10
  from langchain.retrievers import ParentDocumentRetriever
11
  from langchain.storage import InMemoryStore
12
  from langchain_chroma import Chroma
 
81
  retriever = load_retriever(docstore_path,chroma_path,embeddings,child_splitter,parent_splitter)
82
 
83
  # Replace the local OLMOLLM with the Hugging Face model
84
+
85
  model_name = "gpt2"
86
+ pipe = pipeline("text-generation", model=model_name)
87
+
88
+ # Initialize the LangChain HuggingFacePipeline
89
+ llm = HuggingFacePipeline(pipeline=pipe)
90
 
91
  # Initialize LangChain
 
92
  # llm = HuggingFaceLLM(
93
  # model_id="EleutherAI/gpt-neo-1.3B", # or another suitable model
94
  # temperature=temperature,