wt002 commited on
Commit
9c7a7bf
·
verified ·
1 Parent(s): 2a62957

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +12 -16
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
- url = "https://huggingface.co/spaces/wt002/Final_Assignment_Project/blob/main/questions.json"
400
- response = requests.get(url)
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
- # Extract text
414
- texts = [doc.get("text", "") for doc in docs if isinstance(doc, dict)]
 
 
 
 
 
 
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