Spaces:
Running
Running
Update agent.py
Browse files
agent.py
CHANGED
@@ -393,25 +393,21 @@ class MyVectorStore:
|
|
393 |
# -----------------------------
|
394 |
# Define the URL where the JSON file is hosted
|
395 |
|
396 |
-
import requests
|
397 |
import json
|
|
|
398 |
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
# Check status
|
403 |
-
if response.status_code != 200:
|
404 |
-
raise ValueError(f"Failed to fetch data: {response.status_code}")
|
405 |
-
|
406 |
-
# Parse JSON content
|
407 |
-
try:
|
408 |
-
docs = response.json() # or json.loads(response.text)
|
409 |
-
except json.JSONDecodeError as e:
|
410 |
-
print("Response was:", response.text)
|
411 |
-
raise e
|
412 |
|
413 |
-
#
|
414 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
415 |
|
416 |
|
417 |
# Initialize the embedding model
|
|
|
393 |
# -----------------------------
|
394 |
# Define the URL where the JSON file is hosted
|
395 |
|
|
|
396 |
import json
|
397 |
+
from langchain.schema import Document
|
398 |
|
399 |
+
# Load the JSON file
|
400 |
+
with open("questions.json", "r", encoding="utf-8") as f:
|
401 |
+
data = json.load(f)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
402 |
|
403 |
+
# Convert each question into a Document
|
404 |
+
docs = [
|
405 |
+
Document(
|
406 |
+
page_content=item["question"],
|
407 |
+
metadata={"task_id": item["task_id"], "level": item["Level"]}
|
408 |
+
)
|
409 |
+
for item in data if "question" in item
|
410 |
+
]
|
411 |
|
412 |
|
413 |
# Initialize the embedding model
|