wt002 commited on
Commit
31f3113
·
verified ·
1 Parent(s): ee6b900

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +13 -21
agent.py CHANGED
@@ -327,35 +327,27 @@ tools = [tool_map[name] for name in enabled_tool_names]
327
  # -------------------------------
328
  # Step 2: Load the JSON file or tasks (Replace this part if you're loading tasks dynamically)
329
  # -------------------------------
330
- # Here we assume the tasks are already fetched from a URL or file.
331
-
332
-
333
- # Replace this with your actual URL
334
- json_url = "https://huggingface.co/spaces/wt002/Final_Assignment_Project/blob/main/questions.json"
335
 
336
- try:
337
- # Fetch the JSON content from the URL
338
- response = requests.get(json_url)
339
- response.raise_for_status() # Raise error if the request failed
340
 
341
- tasks = response.json() # Parse JSON content
342
- print(f"✅ Loaded {len(tasks)} tasks from URL")
 
 
343
 
344
- # Convert each task to a LangChain Document
345
  docs = []
346
- for task in tasks:
347
- question = task.get("question", "").strip()
348
- if not question:
349
- print(f"⚠️ Skipping task with empty question: {task}")
350
  continue
351
 
352
  task["id"] = str(uuid.uuid4())
353
- docs.append(Document(page_content=question, metadata=task))
354
 
355
- except requests.RequestException as e:
356
- print(f"❌ Failed to fetch JSON from URL: {e}")
357
- except ValueError as e:
358
- print(f"❌ Invalid JSON format: {e}")
359
 
360
 
361
  # -------------------------------
 
327
  # -------------------------------
328
  # Step 2: Load the JSON file or tasks (Replace this part if you're loading tasks dynamically)
329
  # -------------------------------
330
+ from fastapi import FastAPI, Request
331
+ from langchain_core.documents import Document
332
+ import uuid
 
 
333
 
334
+ app = FastAPI()
 
 
 
335
 
336
+ @app.post("/start")
337
+ async def start_questions(request: Request):
338
+ data = await request.json()
339
+ questions = data.get("questions", [])
340
 
 
341
  docs = []
342
+ for task in questions:
343
+ question_text = task.get("question", "").strip()
344
+ if not question_text:
 
345
  continue
346
 
347
  task["id"] = str(uuid.uuid4())
348
+ docs.append(Document(page_content=question_text, metadata=task))
349
 
350
+ return {"message": f"Loaded {len(docs)} questions", "docs": [doc.page_content for doc in docs]}
 
 
 
351
 
352
 
353
  # -------------------------------