Spaces:
Sleeping
Sleeping
Update app-llama.py
Browse files- app-llama.py +11 -9
app-llama.py
CHANGED
|
@@ -60,14 +60,14 @@ from langchain.memory import ConversationBufferMemory
|
|
| 60 |
from langchain_community.llms import HuggingFaceEndpoint
|
| 61 |
from langchain_community.embeddings import HuggingFaceEmbeddings
|
| 62 |
|
| 63 |
-
|
| 64 |
# for hugging face llm
|
| 65 |
from transformers import AutoTokenizer
|
| 66 |
import transformers
|
| 67 |
import torch
|
| 68 |
import tqdm
|
| 69 |
import accelerate
|
| 70 |
-
|
| 71 |
|
| 72 |
import pymupdf
|
| 73 |
from PIL import Image
|
|
@@ -189,7 +189,9 @@ def build_qa_chain(collection_name, vector_db, file: str):
|
|
| 189 |
documents, file_name = process_file2(file)
|
| 190 |
# Load embeddings model
|
| 191 |
#embeddings = OpenAIEmbeddings(openai_api_key=self.OPENAI_API_KEY)
|
| 192 |
-
|
|
|
|
|
|
|
| 193 |
embeddings = AzureOpenAIEmbeddings(
|
| 194 |
model="text-embedding-ada-002",
|
| 195 |
# dimensions: Optional[int] = None, # Can specify dimensions with new text-embedding-3 models
|
|
@@ -198,11 +200,11 @@ def build_qa_chain(collection_name, vector_db, file: str):
|
|
| 198 |
#openai_api_version="2023-05-15", # If not provided, will read env variable AZURE_OPENAI_API_VERSION
|
| 199 |
openai_api_version="2023-05-15", # If not provided, will read env variable AZURE_OPENAI_API_VERSION
|
| 200 |
)
|
|
|
|
| 201 |
|
| 202 |
-
"""
|
| 203 |
#vincent for new LLM
|
| 204 |
embeddings = HuggingFaceEmbeddings()
|
| 205 |
-
|
| 206 |
|
| 207 |
#vincent added to handle the tenant problem
|
| 208 |
new_client = chromadb.EphemeralClient()
|
|
@@ -237,8 +239,8 @@ def build_qa_chain(collection_name, vector_db, file: str):
|
|
| 237 |
)
|
| 238 |
"""
|
| 239 |
|
| 240 |
-
#vincent added
|
| 241 |
-
|
| 242 |
chain = ConversationalRetrievalChain.from_llm(
|
| 243 |
#ChatOpenAI(temperature=0.0, openai_api_key=self.OPENAI_API_KEY),
|
| 244 |
|
|
@@ -255,7 +257,7 @@ def build_qa_chain(collection_name, vector_db, file: str):
|
|
| 255 |
|
| 256 |
"""
|
| 257 |
#vincent for new LLM
|
| 258 |
-
llm_model = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
|
| 259 |
llm_model = "meta-llama/Llama-2-7b-chat-hf"
|
| 260 |
llm = HuggingFaceEndpoint(
|
| 261 |
repo_id=llm_model,
|
|
@@ -276,7 +278,7 @@ def build_qa_chain(collection_name, vector_db, file: str):
|
|
| 276 |
#return_generated_question=False,
|
| 277 |
verbose=False,
|
| 278 |
)
|
| 279 |
-
|
| 280 |
|
| 281 |
return collection_name, vector_db, chain
|
| 282 |
|
|
|
|
| 60 |
from langchain_community.llms import HuggingFaceEndpoint
|
| 61 |
from langchain_community.embeddings import HuggingFaceEmbeddings
|
| 62 |
|
| 63 |
+
|
| 64 |
# for hugging face llm
|
| 65 |
from transformers import AutoTokenizer
|
| 66 |
import transformers
|
| 67 |
import torch
|
| 68 |
import tqdm
|
| 69 |
import accelerate
|
| 70 |
+
|
| 71 |
|
| 72 |
import pymupdf
|
| 73 |
from PIL import Image
|
|
|
|
| 189 |
documents, file_name = process_file2(file)
|
| 190 |
# Load embeddings model
|
| 191 |
#embeddings = OpenAIEmbeddings(openai_api_key=self.OPENAI_API_KEY)
|
| 192 |
+
|
| 193 |
+
#vincent for old LLM
|
| 194 |
+
"""
|
| 195 |
embeddings = AzureOpenAIEmbeddings(
|
| 196 |
model="text-embedding-ada-002",
|
| 197 |
# dimensions: Optional[int] = None, # Can specify dimensions with new text-embedding-3 models
|
|
|
|
| 200 |
#openai_api_version="2023-05-15", # If not provided, will read env variable AZURE_OPENAI_API_VERSION
|
| 201 |
openai_api_version="2023-05-15", # If not provided, will read env variable AZURE_OPENAI_API_VERSION
|
| 202 |
)
|
| 203 |
+
"""
|
| 204 |
|
|
|
|
| 205 |
#vincent for new LLM
|
| 206 |
embeddings = HuggingFaceEmbeddings()
|
| 207 |
+
|
| 208 |
|
| 209 |
#vincent added to handle the tenant problem
|
| 210 |
new_client = chromadb.EphemeralClient()
|
|
|
|
| 239 |
)
|
| 240 |
"""
|
| 241 |
|
| 242 |
+
#vincent added for old LLM
|
| 243 |
+
"""
|
| 244 |
chain = ConversationalRetrievalChain.from_llm(
|
| 245 |
#ChatOpenAI(temperature=0.0, openai_api_key=self.OPENAI_API_KEY),
|
| 246 |
|
|
|
|
| 257 |
|
| 258 |
"""
|
| 259 |
#vincent for new LLM
|
| 260 |
+
#llm_model = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
|
| 261 |
llm_model = "meta-llama/Llama-2-7b-chat-hf"
|
| 262 |
llm = HuggingFaceEndpoint(
|
| 263 |
repo_id=llm_model,
|
|
|
|
| 278 |
#return_generated_question=False,
|
| 279 |
verbose=False,
|
| 280 |
)
|
| 281 |
+
|
| 282 |
|
| 283 |
return collection_name, vector_db, chain
|
| 284 |
|