PraneshJs commited on
Commit
200801a
·
verified ·
1 Parent(s): 2360be8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -267,12 +267,12 @@ def crawl_and_index(url: str):
267
  FILENAMES = filenames
268
  DOCS = [crawled]
269
  build_faiss_index(EMBEDDINGS)
270
- return f"Crawled and loaded embeddings from cache for {url}", crawled[:2000]
271
  DOCS, FILENAMES = [crawled], [url]
272
  EMBEDDINGS = embedder.encode(DOCS, convert_to_numpy=True, show_progress_bar=False).astype("float32")
273
  cache_save_embeddings(key_hash, EMBEDDINGS, FILENAMES)
274
  build_faiss_index(EMBEDDINGS)
275
- return f"Crawled and indexed {url}", crawled[:2000]
276
 
277
  def ask_question(question: str):
278
  if not question:
@@ -282,7 +282,7 @@ def ask_question(question: str):
282
  results = search_top_k(question, k=3)
283
  if not results:
284
  return "No relevant documents found."
285
- context = "\n".join(f"Source: {r['source']}\n\n{r['text'][:1800]}\n---\n" for r in results)
286
  user_prompt = f"Use the following context to answer the question.\n\nContext:\n{context}\nQuestion: {question}\nAnswer:"
287
  return openrouter_chat_system_user(user_prompt)
288
 
 
267
  FILENAMES = filenames
268
  DOCS = [crawled]
269
  build_faiss_index(EMBEDDINGS)
270
+ return f"Crawled and loaded embeddings from cache for {url}", crawled[:20000]
271
  DOCS, FILENAMES = [crawled], [url]
272
  EMBEDDINGS = embedder.encode(DOCS, convert_to_numpy=True, show_progress_bar=False).astype("float32")
273
  cache_save_embeddings(key_hash, EMBEDDINGS, FILENAMES)
274
  build_faiss_index(EMBEDDINGS)
275
+ return f"Crawled and indexed {url}", crawled[:20000]
276
 
277
  def ask_question(question: str):
278
  if not question:
 
282
  results = search_top_k(question, k=3)
283
  if not results:
284
  return "No relevant documents found."
285
+ context = "\n".join(f"Source: {r['source']}\n\n{r['text'][:18000]}\n---\n" for r in results)
286
  user_prompt = f"Use the following context to answer the question.\n\nContext:\n{context}\nQuestion: {question}\nAnswer:"
287
  return openrouter_chat_system_user(user_prompt)
288