Update api.py
Browse files
api.py
CHANGED
@@ -53,6 +53,13 @@ class SpecificityEvaluationResponse(BaseModel):
|
|
53 |
problematic: str
|
54 |
specificity: SpecificityScore
|
55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
# --- Global Variables / State ---
|
57 |
# Keep the graph instance global for efficiency if desired,
|
58 |
# but consider potential concurrency issues if graph/LLMs have state.
|
@@ -114,8 +121,8 @@ async def lifespan(app: FastAPI):
|
|
114 |
|
115 |
# --- FastAPI Application ---
|
116 |
app = FastAPI(
|
117 |
-
title="Key Issue Generator Specificity API",
|
118 |
-
description="API to generate Key Issues
|
119 |
version="1.1.0",
|
120 |
lifespan=lifespan # Use the lifespan context manager
|
121 |
)
|
@@ -323,10 +330,69 @@ async def evaluation(request: SpecificityEvaluationRequest):
|
|
323 |
problematic=problematic_result,
|
324 |
specificity=specificity_score
|
325 |
)
|
326 |
-
|
327 |
return final_response
|
328 |
|
329 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
330 |
# --- How to Run ---
|
331 |
if __name__ == "__main__":
|
332 |
# Make sure to set environment variables for config (NEO4J_URI, NEO4J_PASSWORD, GEMINI_API_KEY, etc.)
|
|
|
53 |
problematic: str
|
54 |
specificity: SpecificityScore
|
55 |
|
56 |
+
class ProblemDescriptionRequest(BaseModel):
|
57 |
+
description: str
|
58 |
+
technical_topic: str
|
59 |
+
|
60 |
+
class ProblemDescriptionResponse(BaseModel):
|
61 |
+
problem_description: str
|
62 |
+
|
63 |
# --- Global Variables / State ---
|
64 |
# Keep the graph instance global for efficiency if desired,
|
65 |
# but consider potential concurrency issues if graph/LLMs have state.
|
|
|
121 |
|
122 |
# --- FastAPI Application ---
|
123 |
app = FastAPI(
|
124 |
+
title="Key Issue Generator, Specificity, and Description API",
|
125 |
+
description="API to generate Key Issues, evaluate problematic specificity, and generate problem descriptions.",
|
126 |
version="1.1.0",
|
127 |
lifespan=lifespan # Use the lifespan context manager
|
128 |
)
|
|
|
330 |
problematic=problematic_result,
|
331 |
specificity=specificity_score
|
332 |
)
|
|
|
333 |
return final_response
|
334 |
|
335 |
|
336 |
+
@app.post("/create-problem-description", response_model=ProblemDescriptionResponse)
|
337 |
+
async def gen_problem_description(request: ProblemDescriptionRequest):
|
338 |
+
"""
|
339 |
+
Generates a problem description using Gemini based on a detailed description
|
340 |
+
and technical topic.
|
341 |
+
"""
|
342 |
+
description = request.description
|
343 |
+
technical_topic = request.technical_topic
|
344 |
+
|
345 |
+
if not description or not technical_topic:
|
346 |
+
raise HTTPException(status_code=400, detail="Missing required fields: description or technical_topic.")
|
347 |
+
|
348 |
+
logger.info("Received request for problem description generation.")
|
349 |
+
logger.debug(f"Topic: {technical_topic}") # Avoid logging full description unless necessary
|
350 |
+
|
351 |
+
# --- Construct Prompt ---
|
352 |
+
prompt = f"""I want you to create a problem description using a key issue explained in a detailed description.
|
353 |
+
|
354 |
+
Here is the description of the key issue: <description>{description}</description>
|
355 |
+
|
356 |
+
This key issue is part of the following technical topic: <technical_topic>{technical_topic}</technical_topic>
|
357 |
+
|
358 |
+
As the output, I only want you to provide the problem description found, nothing else.
|
359 |
+
|
360 |
+
Here are examples of problem descriptions that you could create, it shows the level of specificity that you should aim for:
|
361 |
+
|
362 |
+
Example 1: 'I am working on enhancing security in 4G and 5G telecommunications networks, specifically in the area of network slicing. My goal is to address vulnerabilities in the isolation of slices and improve the integrity of data transmission across different network slices, ensuring they are properly protected against unauthorized access and attacks.'
|
363 |
+
Example 2: 'I am working on improving user authentication in the context of 3GPP (3rd Generation Partnership Project) networks. Specifically, I need to solve issues related to the security and efficiency of the authentication process in the 5G network architecture, focusing on the use of cryptographic keys and identity management.'
|
364 |
+
|
365 |
+
As far as possible, avoid using acronyms in the problem description.
|
366 |
+
Try to be about the same length as the examples if possible."""
|
367 |
+
|
368 |
+
try:
|
369 |
+
logger.info("Calling Gemini API to generate problem description...")
|
370 |
+
# Use the specified model and configuration
|
371 |
+
model_name = "gemini-2.5-flash-preview-04-17"
|
372 |
+
model = genai.GenerativeModel(model_name)
|
373 |
+
|
374 |
+
response = model.generate_content(prompt)
|
375 |
+
# Extract the result
|
376 |
+
result_text = response.text.strip()
|
377 |
+
logger.info("Successfully generated problem description from Gemini.")
|
378 |
+
logger.debug(f"Generated description: {result_text[:200]}...") # Log snippet
|
379 |
+
|
380 |
+
except Exception as e:
|
381 |
+
logger.error(f"Error calling Gemini API for problem description: {e}", exc_info=True)
|
382 |
+
# Check for specific Gemini API errors if possible
|
383 |
+
raise HTTPException(status_code=502, detail=f"Failed to generate problem description using LLM: {e}")
|
384 |
+
|
385 |
+
if not result_text:
|
386 |
+
logger.error("Gemini API returned an empty result for problem description.")
|
387 |
+
raise HTTPException(status_code=502, detail="LLM returned an empty problem description.")
|
388 |
+
|
389 |
+
# --- Return Result ---
|
390 |
+
# Return as JSON using the Pydantic model
|
391 |
+
return ProblemDescriptionResponse(problem_description=result_text)
|
392 |
+
|
393 |
+
# Alternative: Return as plain text
|
394 |
+
# return PlainTextResponse(content=result_text)
|
395 |
+
|
396 |
# --- How to Run ---
|
397 |
if __name__ == "__main__":
|
398 |
# Make sure to set environment variables for config (NEO4J_URI, NEO4J_PASSWORD, GEMINI_API_KEY, etc.)
|