removed some comments
Browse files- app/main.py +6 -6
app/main.py
CHANGED
@@ -42,9 +42,9 @@ class PromptRequest(BaseModel):
|
|
42 |
|
43 |
class ContentRequest(BaseModel):
|
44 |
grade: int
|
45 |
-
subject: str
|
46 |
topic: str
|
47 |
-
style: str = "normal"
|
48 |
|
49 |
TOPIC_KEYWORDS = {
|
50 |
# Grade 3 Science
|
@@ -208,13 +208,13 @@ def retrieve_documents(query, index, embedding_model, documents, top_k=5):
|
|
208 |
|
209 |
# Simple direct keyword matching since we only have one keyword per topic
|
210 |
for filename, keywords in TOPIC_KEYWORDS.items():
|
211 |
-
if keywords[0] == query_lower:
|
212 |
target_topic = filename
|
213 |
break
|
214 |
|
215 |
# Get embeddings and search
|
216 |
query_embedding = embedding_model.encode([query])
|
217 |
-
distances, indices = index.search(query_embedding, top_k * 3)
|
218 |
|
219 |
# Filter and organize retrieved documents
|
220 |
topic_docs = []
|
@@ -393,7 +393,7 @@ async def load_or_create_index():
|
|
393 |
files_found = True
|
394 |
chunks = split_text_into_chunks(text, filename)
|
395 |
documents.extend(chunks)
|
396 |
-
await asyncio.sleep(0)
|
397 |
|
398 |
if not files_found:
|
399 |
raise Exception(f"No valid text or PDF files found in the specified paths")
|
@@ -497,7 +497,7 @@ async def generate_content(request: ContentRequest):
|
|
497 |
}
|
498 |
|
499 |
response = generate_response_with_rag(
|
500 |
-
request.topic,
|
501 |
app.state.faiss_index,
|
502 |
app.state.embedding_model,
|
503 |
app.state.documents,
|
|
|
42 |
|
43 |
class ContentRequest(BaseModel):
|
44 |
grade: int
|
45 |
+
subject: str
|
46 |
topic: str
|
47 |
+
style: str = "normal"
|
48 |
|
49 |
TOPIC_KEYWORDS = {
|
50 |
# Grade 3 Science
|
|
|
208 |
|
209 |
# Simple direct keyword matching since we only have one keyword per topic
|
210 |
for filename, keywords in TOPIC_KEYWORDS.items():
|
211 |
+
if keywords[0] == query_lower:
|
212 |
target_topic = filename
|
213 |
break
|
214 |
|
215 |
# Get embeddings and search
|
216 |
query_embedding = embedding_model.encode([query])
|
217 |
+
distances, indices = index.search(query_embedding, top_k * 3)
|
218 |
|
219 |
# Filter and organize retrieved documents
|
220 |
topic_docs = []
|
|
|
393 |
files_found = True
|
394 |
chunks = split_text_into_chunks(text, filename)
|
395 |
documents.extend(chunks)
|
396 |
+
await asyncio.sleep(0)
|
397 |
|
398 |
if not files_found:
|
399 |
raise Exception(f"No valid text or PDF files found in the specified paths")
|
|
|
497 |
}
|
498 |
|
499 |
response = generate_response_with_rag(
|
500 |
+
request.topic,
|
501 |
app.state.faiss_index,
|
502 |
app.state.embedding_model,
|
503 |
app.state.documents,
|