Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
@@ -369,27 +369,36 @@ class MyVectorStore:
|
|
369 |
import json
|
370 |
from langchain.schema import Document
|
371 |
|
372 |
-
def
|
373 |
-
"""
|
374 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
375 |
|
376 |
with open("questions.json", "r", encoding="utf-8") as f:
|
377 |
data = json.load(f)
|
378 |
|
379 |
docs = [
|
380 |
Document(
|
381 |
-
page_content=
|
382 |
metadata={
|
383 |
"task_id": item["task_id"],
|
384 |
-
"level": item.get("Level", "
|
385 |
"file_name": item.get("file_name", "")
|
386 |
}
|
387 |
)
|
388 |
for item in data
|
389 |
-
if "question" in item and item["question"] # Skip missing/empty
|
390 |
]
|
391 |
|
392 |
-
texts = [doc.page_content for doc in docs]
|
393 |
|
394 |
# Initialize the embedding model
|
395 |
embedding_model = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
|
|
|
369 |
import json
|
370 |
from langchain.schema import Document
|
371 |
|
372 |
+
def get_question(raw_question) -> str:
|
373 |
+
"""Convert list to string and fix reversed text"""
|
374 |
+
# Handle lists (join with spaces)
|
375 |
+
if isinstance(raw_question, list):
|
376 |
+
text = " ".join(raw_question)
|
377 |
+
else:
|
378 |
+
text = str(raw_question)
|
379 |
+
|
380 |
+
# Fix reversed text like ".rewsna..."
|
381 |
+
if text.startswith(('.', ',')):
|
382 |
+
return text[::-1].replace("\\", "").strip()
|
383 |
+
return text
|
384 |
|
385 |
with open("questions.json", "r", encoding="utf-8") as f:
|
386 |
data = json.load(f)
|
387 |
|
388 |
docs = [
|
389 |
Document(
|
390 |
+
page_content=get_question(item["question"]),
|
391 |
metadata={
|
392 |
"task_id": item["task_id"],
|
393 |
+
"level": item.get("Level", "unknown"),
|
394 |
"file_name": item.get("file_name", "")
|
395 |
}
|
396 |
)
|
397 |
for item in data
|
398 |
+
if "question" in item and item["question"] # Skip missing/empty
|
399 |
]
|
400 |
|
401 |
+
texts = [doc.page_content for doc in docs]
|
402 |
|
403 |
# Initialize the embedding model
|
404 |
embedding_model = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
|