Spaces:
Running
Running
Update agent.py
Browse files
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 |
-
|
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 |
-
|
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 |
-
|
342 |
-
|
|
|
|
|
343 |
|
344 |
-
# Convert each task to a LangChain Document
|
345 |
docs = []
|
346 |
-
for task in
|
347 |
-
|
348 |
-
if not
|
349 |
-
print(f"⚠️ Skipping task with empty question: {task}")
|
350 |
continue
|
351 |
|
352 |
task["id"] = str(uuid.uuid4())
|
353 |
-
docs.append(Document(page_content=
|
354 |
|
355 |
-
|
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 |
# -------------------------------
|