Spaces:
Build error
Build error
Commit ·
86e4cf0
1
Parent(s): 05e153b
updated rag
Browse files- utils/rag_chain.py +7 -4
utils/rag_chain.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
|
| 2 |
from langchain.vectorstores import FAISS
|
| 3 |
from langchain.embeddings import HuggingFaceEmbeddings
|
| 4 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
|
@@ -16,12 +16,15 @@ class RAGChatbot:
|
|
| 16 |
self.llm = self._load_llm()
|
| 17 |
|
| 18 |
def _load_llm(self):
|
| 19 |
-
model_id = "meta-llama/Llama-
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
model = AutoModelForCausalLM.from_pretrained(
|
| 22 |
model_id,
|
| 23 |
device_map="auto",
|
| 24 |
-
torch_dtype=torch.float16
|
|
|
|
| 25 |
)
|
| 26 |
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer, max_new_tokens=512)
|
| 27 |
return HuggingFacePipeline(pipeline=pipe)
|
|
|
|
| 1 |
+
import os
|
| 2 |
from langchain.vectorstores import FAISS
|
| 3 |
from langchain.embeddings import HuggingFaceEmbeddings
|
| 4 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
|
|
|
| 16 |
self.llm = self._load_llm()
|
| 17 |
|
| 18 |
def _load_llm(self):
|
| 19 |
+
model_id = "meta-llama/Meta-Llama-3-8B-Instruct"
|
| 20 |
+
token = os.getenv("HF_TOKEN") # read the HF token from environment
|
| 21 |
+
|
| 22 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, token=token)
|
| 23 |
model = AutoModelForCausalLM.from_pretrained(
|
| 24 |
model_id,
|
| 25 |
device_map="auto",
|
| 26 |
+
torch_dtype=torch.float16,
|
| 27 |
+
token=token
|
| 28 |
)
|
| 29 |
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer, max_new_tokens=512)
|
| 30 |
return HuggingFacePipeline(pipeline=pipe)
|