Kryko7
commited on
Commit
•
10f304d
1
Parent(s):
31c9c03
updated app.py
Browse files- __pycache__/app.cpython-311.pyc +0 -0
- app.py +11 -11
__pycache__/app.cpython-311.pyc
CHANGED
Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ
|
|
app.py
CHANGED
@@ -120,15 +120,15 @@ def create_book_embeddings(book_content):
|
|
120 |
|
121 |
|
122 |
print("Creating book embeddings...")
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
|
133 |
book_embeddings.add_documents(documents=texts, embedding=instructor_embeddings)
|
134 |
book_embeddings.persist()
|
@@ -164,7 +164,7 @@ PROMPT = PromptTemplate(
|
|
164 |
)
|
165 |
|
166 |
|
167 |
-
def generate_answer_from_embeddings(query
|
168 |
"""
|
169 |
Retrieve documents from the vector database and then pass them to the language model to generate an answer.
|
170 |
|
@@ -215,4 +215,4 @@ def get_book(book_name: str):
|
|
215 |
|
216 |
@app.get("/answer")
|
217 |
def get_answer(query: str):
|
218 |
-
return generate_answer_from_embeddings(query
|
|
|
120 |
|
121 |
|
122 |
print("Creating book embeddings...")
|
123 |
+
try:
|
124 |
+
book_embeddings = Chroma.load(persist_directory = '.',
|
125 |
+
collection_name = 'book')
|
126 |
+
except:
|
127 |
+
book_embeddings = Chroma.from_documents(documents = texts,
|
128 |
+
embedding = instructor_embeddings,
|
129 |
+
persist_directory = '.',
|
130 |
+
collection_name = 'book')
|
131 |
+
print("Book embeddings created.")
|
132 |
|
133 |
book_embeddings.add_documents(documents=texts, embedding=instructor_embeddings)
|
134 |
book_embeddings.persist()
|
|
|
164 |
)
|
165 |
|
166 |
|
167 |
+
def generate_answer_from_embeddings(query):
|
168 |
"""
|
169 |
Retrieve documents from the vector database and then pass them to the language model to generate an answer.
|
170 |
|
|
|
215 |
|
216 |
@app.get("/answer")
|
217 |
def get_answer(query: str):
|
218 |
+
return generate_answer_from_embeddings(query)
|