| import os |
| from crewai import Crew, Process |
| import json |
| from typing import Dict, Any |
| from fastapi import APIRouter, HTTPException, Depends |
| from fastapi.responses import HTMLResponse |
| from agents.content_phase import ( |
| query_agent, |
| query_task, |
| course_writer_agent, |
| course_writer_task, |
| ) |
| import app |
| from core import generate_course_content |
| from core.content_converter_service import convert_dict_to_html |
|
|
| from modules import ( |
| llm, |
| inputs, |
| ) |
| from tools import scrape_course, SerperExhaustedError,CURRENT_SERPER_INDEX |
| from schemas import ( |
| CourseWithQueries, |
| CourseContent, |
| ) |
|
|
|
|
| router = APIRouter(prefix="/content", tags=["Content Generation"]) |
|
|
| |
| |
| |
|
|
|
|
| @router.post("/keyword_generation") |
| def run_keywords(outlines: CourseContent): |
| agent = query_agent() |
| task = query_task(agent) |
| keywords_crew = Crew( |
| agents=[agent], |
| tasks=[task], |
| process=Process.sequential, |
| ) |
|
|
| result = keywords_crew.kickoff(inputs={"course": outlines.dict()}) |
| print(result.json_dict) |
|
|
| return {"message": "Keywords Generated Well ๐", "result": result} |
|
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
|
|
|
|
| @router.post("/scrape") |
| def scrape_endpoint(course: CourseWithQueries): |
| try: |
| course_dict = course.dict() |
| summary, raw = scrape_course(course_dict) |
|
|
| return { |
| "message": "Queries Searched and Scraped Well ๐", |
| "serper_api_used_index": CURRENT_SERPER_INDEX, |
| "summary": summary, |
| "raw": raw, |
| } |
|
|
| except SerperExhaustedError as e: |
| raise HTTPException(status_code=500, detail=f"{str(e)}") |
|
|
|
|
| except Exception as e: |
| raise HTTPException(status_code=500, detail=f"Unexpected error: {str(e)}") |
|
|
|
|
|
|
| @router.post("/content_generation") |
| def run_content_generation(course_data: Dict): |
| |
| course_dict = course_data |
| result = generate_course_content(course_dict) |
|
|
| return {"message": "Content Generated Well ๐", "result": result} |
|
|
|
|
| @router.post("/convert_course", response_class=HTMLResponse) |
| def convert_to_html(course_data: Dict[str, Any]): |
| """ |
| ุชุญููู ุจูุงูุงุช ุงูู
ูุฑุฑ ุงูุฏุฑุงุณู ู
ู Dictionary ุฅูู HTML |
| |
| Args: |
| course_data: Dictionary ูุญุชูู ุนูู ุจูุงูุงุช ุงูู
ูุฑุฑ ุงูุฏุฑุงุณู |
| - course_name: ุงุณู
ุงูู
ูุฑุฑ |
| - course_audience: ุงูุฌู
ููุฑ ุงูู
ุณุชูุฏู |
| - results: ูุงุฆู
ุฉ ุงููุญุฏุงุช |
| |
| Returns: |
| HTML string ูุงู
ู ุฌุงูุฒ ููุนุฑุถ |
| """ |
| try: |
| |
| if not course_data: |
| raise HTTPException(status_code=400, detail="ูุง ุชูุฌุฏ ุจูุงูุงุช ู
ุฑุณูุฉ") |
|
|
| |
| html_content = convert_dict_to_html(course_data) |
|
|
| return HTMLResponse(content=html_content) |
|
|
| except Exception as e: |
| raise HTTPException(status_code=500, detail=f"ุฎุทุฃ ูู ุงูุชุญููู: {str(e)}") |
|
|