File size: 3,866 Bytes
325b94c f0865b7 325b94c 616e78a 325b94c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | 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"])
# ------------------------------------
# === Agent 7:Training Generator ===
# ------------------------------------
@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:
# # ูุญูู Pydantic model ูู dict ุจููุณ ุงูุดูู ุงููู ุงููุงููุดู ู
ุณุชููุงูุง
# course_dict = course.dict()
# summary, raw = scrape_course(course_dict)
# return {
# "message": "Queries Searched and Scraped Well ๐",
# "summary": summary,
# "raw": raw,
# }
# return {"message": "Queries Searched and Scraped Well ๐", "summary": summary, "raw": raw}
# except Exception as e:
# # ูู ุงูุจุฑูุฏุงูุดู ุฎููู logging ู ู
ุชุทูุนุด ุงูุฑุณุงูุฉ ุงูุฎุงู
ููุนู
ูู
# raise HTTPException(status_code=500, detail=str(e))
@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):
# ูุญูู ูู dict ููุจุนุชูุง ููู service
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="ูุง ุชูุฌุฏ ุจูุงูุงุช ู
ุฑุณูุฉ")
# ุชุญููู Dictionary ุฅูู HTML
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)}")
|