Kryko7
commited on
Commit
•
144690a
1
Parent(s):
81d98d1
updated requirements
Browse files- app.py +34 -3
- requirements.txt +4 -4
app.py
CHANGED
@@ -6,6 +6,8 @@ from langchain.document_loaders import GutenbergLoader
|
|
6 |
|
7 |
|
8 |
import langchain
|
|
|
|
|
9 |
|
10 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
11 |
|
@@ -35,6 +37,21 @@ llm = Replicate(
|
|
35 |
)
|
36 |
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
# Function to search for a book by name and return the best match URL
|
40 |
def search_book_by_name(book_name):
|
@@ -100,8 +117,7 @@ def create_book_embeddings(book_content):
|
|
100 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size = Configuration.split_chunk_size,
|
101 |
chunk_overlap = Configuration.split_overlap)
|
102 |
texts = text_splitter.split_documents(book_content)
|
103 |
-
|
104 |
-
model_kwargs = {"device": "cuda"})
|
105 |
|
106 |
vectordb = None
|
107 |
try:
|
@@ -173,4 +189,19 @@ def generate_answer_from_embeddings(query, book_embeddings):
|
|
173 |
llm_response = qa_chain(query)
|
174 |
ans = process_llm_response(llm_response)
|
175 |
|
176 |
-
return ans
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
|
8 |
import langchain
|
9 |
+
from fastapi import FastAPI
|
10 |
+
|
11 |
|
12 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
13 |
|
|
|
37 |
)
|
38 |
|
39 |
|
40 |
+
class Configuration:
|
41 |
+
model_name = 'llama2-13b'
|
42 |
+
temperature = 0.5
|
43 |
+
top_p = 0.95
|
44 |
+
repetition_penalty = 1.15
|
45 |
+
|
46 |
+
split_chunk_size = 1000
|
47 |
+
split_overlap = 100
|
48 |
+
|
49 |
+
embeddings_model_repo = 'hkunlp/instructor-large'
|
50 |
+
|
51 |
+
k = 3
|
52 |
+
|
53 |
+
Embeddings_path = '/book-vectordb-chroma'
|
54 |
+
Persist_directory = './book-vectordb-chroma'
|
55 |
|
56 |
# Function to search for a book by name and return the best match URL
|
57 |
def search_book_by_name(book_name):
|
|
|
117 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size = Configuration.split_chunk_size,
|
118 |
chunk_overlap = Configuration.split_overlap)
|
119 |
texts = text_splitter.split_documents(book_content)
|
120 |
+
|
|
|
121 |
|
122 |
vectordb = None
|
123 |
try:
|
|
|
189 |
llm_response = qa_chain(query)
|
190 |
ans = process_llm_response(llm_response)
|
191 |
|
192 |
+
return ans
|
193 |
+
|
194 |
+
|
195 |
+
|
196 |
+
|
197 |
+
|
198 |
+
app = FastAPI()
|
199 |
+
llm = Replicate(
|
200 |
+
model= "replicate/llama-2-70b-chat:2796ee9483c3fd7aa2e171d38f4ca12251a30609463dcfd4cd76703f22e96cdf",
|
201 |
+
input={"temperature": 0.75, "max_length": 500, "top_p": 1},
|
202 |
+
)
|
203 |
+
|
204 |
+
|
205 |
+
|
206 |
+
instructor_embeddings = HuggingFaceInstructEmbeddings(model_name = Configuration.embeddings_model_repo,
|
207 |
+
model_kwargs = {"device": "cpu"})
|
requirements.txt
CHANGED
@@ -11,9 +11,9 @@ xformers
|
|
11 |
einops
|
12 |
replicate
|
13 |
beautifulsoup4
|
14 |
-
fastapi
|
15 |
-
requests
|
16 |
-
uvicorn
|
17 |
sentencepiece
|
18 |
-
torch
|
19 |
|
|
|
11 |
einops
|
12 |
replicate
|
13 |
beautifulsoup4
|
14 |
+
fastapi
|
15 |
+
requests
|
16 |
+
uvicorn
|
17 |
sentencepiece
|
18 |
+
torch
|
19 |
|