Update api.py
Browse files
api.py
CHANGED
@@ -73,12 +73,18 @@ class FormattedKeyIssue(BaseModel):
|
|
73 |
class KeyIssueFormatResponse(BaseModel):
|
74 |
key_issues: List[FormattedKeyIssue]
|
75 |
|
|
|
|
|
|
|
|
|
|
|
76 |
class CreateSeveralProbDescRequest(BaseModel):
|
77 |
-
|
78 |
-
|
79 |
technical_topic: str
|
80 |
|
81 |
class CreateSeveralProbDescResponse(BaseModel):
|
|
|
82 |
problem_descriptions: List[str]
|
83 |
|
84 |
# --- Global Variables / State ---
|
@@ -493,8 +499,7 @@ async def create_several_probdesc(request: CreateSeveralProbDescRequest):
|
|
493 |
logger.error("Gemini client is not available or configured.")
|
494 |
raise HTTPException(status_code=503, detail="Service Unavailable: Gemini client not configured")
|
495 |
|
496 |
-
|
497 |
-
challenges_map = request.challenges
|
498 |
technical_topic = request.technical_topic
|
499 |
|
500 |
# Basic input validation
|
@@ -509,24 +514,25 @@ async def create_several_probdesc(request: CreateSeveralProbDescRequest):
|
|
509 |
generated_descriptions = []
|
510 |
|
511 |
# Iterate through challenges to create tasks
|
512 |
-
for
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
failed_count = 0
|
517 |
if description is None:
|
518 |
logger.warning(f"No description found for key_issue_id {key_issue_id}. Skipping its challenges.")
|
519 |
continue # Skip challenges for this ID if description is missing
|
520 |
|
521 |
if not list_of_challenges:
|
522 |
-
|
523 |
-
|
524 |
|
525 |
-
# Create a task for each challenge associated with this description
|
526 |
for ind, challenge in enumerate(list_of_challenges):
|
|
|
|
|
|
|
527 |
if not challenge: # Skip empty challenges
|
528 |
-
|
529 |
-
|
530 |
else:
|
531 |
prompt = f"""I want you to create a problem description using a key issue explained in a detailed description.
|
532 |
Here is the description of the key issue: <description>{description}</description>
|
@@ -558,9 +564,10 @@ Try to be about the same length as the examples if possible."""
|
|
558 |
failed_count += 1
|
559 |
logger.error(f"Error calling Gemini API for problem description {ind+1}: {e}", exc_info=True)
|
560 |
# Check for specific Gemini API errors if possible
|
561 |
-
raise HTTPException(status_code=502, detail=f"Failed to generate problem description using LLM: {e}")
|
562 |
|
563 |
logger.info(f"Successfully generated descriptions: {successful_count}/{len(list_of_challenges)} ")
|
|
|
564 |
|
565 |
# --- Return Result ---
|
566 |
return CreateSeveralProbDescResponse(problem_descriptions=generated_descriptions)
|
|
|
73 |
class KeyIssueFormatResponse(BaseModel):
|
74 |
key_issues: List[FormattedKeyIssue]
|
75 |
|
76 |
+
class KeyIssueInput(BaseModel):
|
77 |
+
"""Represents a single key issue with its description and challenges."""
|
78 |
+
description: str
|
79 |
+
challenges: List[str]
|
80 |
+
|
81 |
class CreateSeveralProbDescRequest(BaseModel):
|
82 |
+
"""Request body for creating multiple problem descriptions."""
|
83 |
+
keys_issues: List[KeyIssueInput] # Changed field name and type
|
84 |
technical_topic: str
|
85 |
|
86 |
class CreateSeveralProbDescResponse(BaseModel):
|
87 |
+
"""Response body containing the list of generated problem descriptions."""
|
88 |
problem_descriptions: List[str]
|
89 |
|
90 |
# --- Global Variables / State ---
|
|
|
499 |
logger.error("Gemini client is not available or configured.")
|
500 |
raise HTTPException(status_code=503, detail="Service Unavailable: Gemini client not configured")
|
501 |
|
502 |
+
key_issues_list = request.keys_issues
|
|
|
503 |
technical_topic = request.technical_topic
|
504 |
|
505 |
# Basic input validation
|
|
|
514 |
generated_descriptions = []
|
515 |
|
516 |
# Iterate through challenges to create tasks
|
517 |
+
for key_issue in key_issues_list:
|
518 |
+
description = key_issue.description
|
519 |
+
list_of_challenges = key_issue.challenges
|
520 |
+
|
|
|
521 |
if description is None:
|
522 |
logger.warning(f"No description found for key_issue_id {key_issue_id}. Skipping its challenges.")
|
523 |
continue # Skip challenges for this ID if description is missing
|
524 |
|
525 |
if not list_of_challenges:
|
526 |
+
logger.warning(f"Empty challenge list for key_issue_id {key_issue_id}. Skipping.")
|
527 |
+
continue
|
528 |
|
|
|
529 |
for ind, challenge in enumerate(list_of_challenges):
|
530 |
+
successful_count = 0
|
531 |
+
failed_count = 0
|
532 |
+
# Create a task for each challenge associated with this description
|
533 |
if not challenge: # Skip empty challenges
|
534 |
+
logger.warning(f"Skipping empty challenge string for key_issue_id {key_issue_id}.")
|
535 |
+
continue
|
536 |
else:
|
537 |
prompt = f"""I want you to create a problem description using a key issue explained in a detailed description.
|
538 |
Here is the description of the key issue: <description>{description}</description>
|
|
|
564 |
failed_count += 1
|
565 |
logger.error(f"Error calling Gemini API for problem description {ind+1}: {e}", exc_info=True)
|
566 |
# Check for specific Gemini API errors if possible
|
567 |
+
raise HTTPException(status_code=502, detail=f"Failed to generate problem description {ind+1} using LLM: {e}")
|
568 |
|
569 |
logger.info(f"Successfully generated descriptions: {successful_count}/{len(list_of_challenges)} ")
|
570 |
+
|
571 |
|
572 |
# --- Return Result ---
|
573 |
return CreateSeveralProbDescResponse(problem_descriptions=generated_descriptions)
|