Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -227,17 +227,17 @@ def respond(message, history, model, temperature, num_calls, use_web_search):
|
|
227 |
logging.info(f"Generated Response (first line): {first_line}")
|
228 |
yield response
|
229 |
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
if model == "@cf/meta/llama-3.1-8b-instruct":
|
231 |
# Use Cloudflare API
|
232 |
-
embed = get_embeddings()
|
233 |
-
if os.path.exists("faiss_database"):
|
234 |
-
database = FAISS.load_local("faiss_database", embed, allow_dangerous_deserialization=True)
|
235 |
-
retriever = database.as_retriever()
|
236 |
-
relevant_docs = retriever.get_relevant_documents(message)
|
237 |
-
context_str = "\n".join([doc.page_content for doc in relevant_docs])
|
238 |
-
else:
|
239 |
-
context_str = "No documents available."
|
240 |
-
|
241 |
for partial_response in get_response_from_cloudflare(prompt="", context=context_str, query=message, num_calls=num_calls, temperature=temperature, search_type="pdf"):
|
242 |
first_line = partial_response.split('\n')[0] if partial_response else ''
|
243 |
logging.info(f"Generated Response (first line): {first_line}")
|
@@ -267,9 +267,9 @@ def get_response_from_cloudflare(prompt, context, query, num_calls=3, temperatur
|
|
267 |
model = "@cf/meta/llama-3.1-8b-instruct"
|
268 |
|
269 |
if search_type == "pdf":
|
270 |
-
instruction = f"""Using the following context:
|
271 |
{context}
|
272 |
-
Write a detailed and complete
|
273 |
else: # web search
|
274 |
instruction = f"""Using the following context:
|
275 |
{context}
|
|
|
227 |
logging.info(f"Generated Response (first line): {first_line}")
|
228 |
yield response
|
229 |
else:
|
230 |
+
embed = get_embeddings()
|
231 |
+
if os.path.exists("faiss_database"):
|
232 |
+
database = FAISS.load_local("faiss_database", embed, allow_dangerous_deserialization=True)
|
233 |
+
retriever = database.as_retriever()
|
234 |
+
relevant_docs = retriever.get_relevant_documents(message)
|
235 |
+
context_str = "\n".join([doc.page_content for doc in relevant_docs])
|
236 |
+
else:
|
237 |
+
context_str = "No documents available."
|
238 |
+
|
239 |
if model == "@cf/meta/llama-3.1-8b-instruct":
|
240 |
# Use Cloudflare API
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
241 |
for partial_response in get_response_from_cloudflare(prompt="", context=context_str, query=message, num_calls=num_calls, temperature=temperature, search_type="pdf"):
|
242 |
first_line = partial_response.split('\n')[0] if partial_response else ''
|
243 |
logging.info(f"Generated Response (first line): {first_line}")
|
|
|
267 |
model = "@cf/meta/llama-3.1-8b-instruct"
|
268 |
|
269 |
if search_type == "pdf":
|
270 |
+
instruction = f"""Using the following context from the PDF documents:
|
271 |
{context}
|
272 |
+
Write a detailed and complete response that answers the following user question: '{query}'"""
|
273 |
else: # web search
|
274 |
instruction = f"""Using the following context:
|
275 |
{context}
|