class ScopeObjective(BaseModel): scope: str = Field(description="Define the core functionalities of the system") objectives: List[str] = Field(description="List at least three objectives focusing on user needs and system capabilities") class ArchitectureObjectives(BaseModel): component: str = Field(description="architecture component for the project") objectives: str = Field(description="project objectives, each associated with a key architecture component") class ComponenetDesign(BaseModel): component: str = Field(description="core component for the project") purpose: str = Field(description="purpose of the core component") interactions: str = Field(description="interactions between the core components") specifications: str = Field(description="specifications for the core components") class TeamRolesSkillsRequirements(BaseModel): role: str = Field(description="role for the team member") skills: str = Field(description="skills required for this particular job") class CostEstimatesOptimization(BaseModel): estimated_costs: str = Field(description="estimated cost for the project") optimization_strategies: List[str] = Field(description="Optimized Strategy for the project, it will always be a list of strings") class Tasks(BaseModel): name: str = Field(description="Name of the task") subtasks: List[str] = Field(description="sub tasks relevant for the task") class Phases(BaseModel): name: str = Field(description="name of the phase") tasks: List[Tasks] = Field(description="Tasks for this phase") class ProjectTasksMileStones(BaseModel): phases: List[Phases] = Field(description="Phases for the project") class PlanOutput(BaseModel): executive_summary: str = Field(description="concise overview of the project objectives, highlighting key features, targeted users, and platform (e.g., AWS)") scope_objectives: ScopeObjective = Field(description="Scope and Objective for the project") architecture_overview: str = Field(description="Overview of the system architecture, detailing the primary components and how they interact") architecture_objectives: List[ArchitectureObjectives] = Field(description="List at least three objectives, each associated with a key architecture component, such as compute, storage, or network.") component_design: List[ComponenetDesign] = Field(description="Detail at least two core components, including their purpose, interactions, and specifications") security_and_compliance: List[str] = Field(description="List at least three security and compliance measures as strings, it should always be list of strings") deployment_testing_monitoring: List[str] = Field(description="List of different points of deployment, testing, and monitoring, describing CI/CD, testing types, and monitoring approaches. it should always be list of strings") team_roles_skills_requirements: List[TeamRolesSkillsRequirements] = Field(description="Define the roles needed for the project and their respective skill sets") cost_estimates_optimization: CostEstimatesOptimization = Field(description="Cost Estimates for the project and strategies to optimize resources: don't include the cost just the explanation for the cost") project_tasks_milestones: ProjectTasksMileStones = Field(description="Major project tasks and milestones, structured by phases") async def generate_rough_plan(data, token): prompt = ( f"Requirements: {data.requirements}\n" f"Backend: {data.backend}\n" f"Frontend: {data.frontend}\n" f"Database: {data.database}\n" f"Features: {data.features} \n" f"Additional Features: {data.additional_feature} \n" + "\n".join([ f"{qa.question}\n{qa.answer}" for qa in data.question_answers ]) + "\n\n" "Based on the provided details, please generate a comprehensive project description with the following sections:\n" "1. Executive Summary\n" f" Provide a concise overview of the project objectives, highlighting key features, targeted users, and platform (e.g., AWS) it should be atleast 4, 5 lines long also add 3 key outcomes. it should also focus of platform {data.platform}\n" "2. Project Scope and Objectives\n" f" - Scope: Define the core functionalities of the system 3 scopes and 3 objectives. focusing of platform {data.platform}\n" f" - Objectives: List at least three objectives focusing on user needs and system capabilities focusing on platofrm {data.platform}.\n" "3. Architecture Overview\n" f" - Provide an overview of the system architecture, detailing the primary components and how they interact.focusing mostly on {data.platform}\n" "4. Architecture Objectives\n" f" - List at least three objectives, each associated with a key architecture component, such as frontend, backend, database, media storage, Authentication, compute, storage, or network. include all 6, 7 points focusing mostly on platofrm {data.platform}\n" "5. Component Design\n" f" - Detail at least two core components, including their purpose, interactions, and specifications. focus mostly on {data.platform}\n" "6. Security and Compliance\n" f" - List at least three security and compliance measures, such as data encryption, authentication, and compliance standards. focus mostly on {data.platform}\n" "7. Deployment, Testing, and Monitoring\n" f" - Include at least three aspects of deployment, testing, and monitoring, describing CI/CD, testing types, and monitoring approaches. focus mostly on {data.platform}\n" "8. Team Roles and Skills Requirements\n" f" - Define the roles needed for the project and their respective skill sets.focus mostly on {data.platform}\n" "9. Cost Estimates and Optimization\n" f" - Provide explanation for the cost (not including any digits or estimate just the explanation) and strategies to optimize resources {data.platform} (e.g., autoscaling, storage management).\n" "10. Project Tasks and Milestones\n" f" - Outline major project tasks and milestones, structured by phases (e.g., architecture design, development, testing, deployment). {data.platform}\n\n" "11. Architecture Design Phase \n" " - Define Architecture Design Phase for the project with main task and subtasks (Include exactly 3 tasks and 3 subtasks for each tasks) \n" "12. Development Phase \n" " - Define Development Phase for the project with main task that can be represented on the kanman, (Include exactly 4 tasks and 3 subtasks for each tasks) \n" "13. Testing Phase \n" " - Define Testing Phase for the project with main task that can be represented on the kanman, (Include exactly 2 tasks and 3 subtasks for each tasks)" "14. Deployment Phase \n" " - Define Deployment Phase for the project with main task that can be represented with the kanman (Include exactly 3 tasks and 2 subtasks for each tasks)" "Output format:\n" "The output should be a valid JSON structure with each section represented as a JSON object. For example:\n\n" f"Note: the description or content for each section should foces on platform and include data sepcific to that platoform{data.platform}" f"{json_output_format}" ) output = "" user = await get_user_from_token(token=token) async for chunk in ask_question(question= prompt, history=[], use_context=False): output += chunk project_title = data.project_title json_response = parse_and_return_json(output) if (data.project_title == "" or data.project_title == None): generated_project_title = await generate_project_title(requirements=data.requirements) project_title = generated_project_title.split(":")[0].strip('"') try: print(f"Json Response before generate_plan_html: {json_response}") plan_html = generate_plan_html(data=json.loads(json_response)) print(f"Json Response before generate_plan_html:") project_id = await save_final_plan(project_title=project_title, user=user, data=data, json_response=json_response, plan_html=plan_html) print(f"Project ID: {project_id}") return { "project_title": project_title, "project_id": project_id, "plan_html": plan_html, "data": json.loads(json_response) } except Exception as e: raise Exception(str(e)) async def generate_final_plan(data, token): print(f"Step 1111111") user = await get_user_from_token(token= token) output = "" # async for chunk in ask_question(question=prompt, history=[], use_context=False): # output += chunk # json_response = parse_and_return_json(output) # json_response = json.loads(json_response) json_response = await extract_data_from_html(data.rough_plan_html) print(f"JSON RESPONSE after extract_data_from_html.......") json_response = json.loads(json_response) project_title = data.project_title if (data.project_title == "" or data.project_title == None): generated_project_title = await generate_project_title(requirements=data.requirements) project_title = generated_project_title.split(":")[0].strip('"') project_name = project_title # tasks_applications = "".join([phase['name'] for phase in json_response['project_tasks_milestones']['phases']]) tasks_applications = generate_task_appplication(json_response['project_tasks_milestones']) business_objectives = ", ".join([obj for obj in json_response['scope_objectives']['objectives']]) existing_infrastructure = 'AWS', scalability_performance = ", ".join([item['objective'] for item in json_response['architecture_objectives']]) other_requirements = "".join([feature for feature in data.features]) user_id = "e16575cd-e9d3-47d5-b3ba-d3ef612f5683" request_body = { "project_name": project_name, "tasks_applications": tasks_applications, "business_objectives": business_objectives, "existing_infrastructure": "AWS", "scalability_performance":scalability_performance, "security_compliance": scalability_performance, "other_requirements": other_requirements, "user_id": "e16575cd-e9d3-47d5-b3ba-d3ef612f5683", } async with httpx.AsyncClient(timeout=60.0) as client: try: external_response = await client.post( "https://auto-board-workspace.vercel.app/api/plan/generate", json=request_body, timeout=60.0 ) except Exception as e: raise Exception(f"Error generating auto-board:::::::::{e}") if external_response.status_code != 200: raise Exception("Error generating auto-board....") else: response_data = external_response.json() print(f"Response Data: {response_data}") print(f"Response Data: {response_data['data']}") print(f"Response Data: {response_data['data']['id']}") print(f"First API called.............") gantt_request_body = { "projectId": str(response_data['data']['id']), "userId": "e16575cd-e9d3-47d5-b3ba-d3ef612f5683" } print(f"gantt request body: {gantt_request_body}") try: kamban = await client.post( "https://auto-board-workspace.vercel.app/api/kanbans/generate", json=gantt_request_body, timeout=60.0 ) external_response = await client.post( "https://auto-board-workspace.vercel.app/api/gantt/generate", json=gantt_request_body, timeout=60.0 ) except Exception as e: raise Exception(f"Error generating gantt: {e}") print(f"Second and Third API called.............") kamban_response = kamban.json() async with httpx.AsyncClient() as client: if external_response.status_code == 200: response_json = external_response.json() db_instance = ProjectModel(requirements=data.requirements, features=data.features, solution_stack = data.solution_stack, rough_plan = data.rough_plan, final_plan = json_response, user_id = user.id, project_title = project_title, gantt_project_id = str(response_data['data']['id']), user_uuid ="e16575cd-e9d3-47d5-b3ba-d3ef612f5683", ganttDataID=str(response_json['data']['id']), boardId=str(kamban_response['board']['id']), rough_plan_html=data.rough_plan_html, final_plan_html=data.rough_plan_html ) await db_instance.save() print(f"DB Instance: {db_instance.id}") # str_data = "" # if isinstance(json_response, dict): # str_data = json.dumps(json_response) # else: # str_data = json.loads(json_response) # await generate_embeddings(data=str_data, project_id=db_instance.id) print(f"Finalizing............") return { "project_title": project_title, "project_id": int(db_instance.id), "data": json_response, "final_plan": data.rough_plan_html } else: print(f"Gantt Chart Task: External API responded with status code {external_response.status_code}: {external_response.text}") return { "success": False, "status_code": external_response.status_code, "message": external_response.text } async def update_final_plan_fun(project_id, data, token): try: project , json_response = await asyncio.gather( ProjectModel.get(id=project_id), extract_data_from_html(data.final_plan_html) ) project.final_plan_html = data.final_plan_html print(f"saving html content.........") project.final_plan = json.loads(json_response) await project.save() return { "success": True, "message": "Final plan HTML updated successfully.", "project_id": project.id, "final_plan_html": project.final_plan_html } except Exception as e: raise Exception(f"Error updating final plan HTML: {str(e)}")