Spaces:
Sleeping

axeronis commited on
Commit
060e28e
·
1 Parent(s): 84b7891

fix: SDK mismatch in generate_11_point_summary - use google.genai consistently

Browse files
Files changed (1) hide show
  1. backend/app/services/gemini_client.py +13 -18
backend/app/services/gemini_client.py CHANGED
@@ -439,29 +439,24 @@ Respond with ONLY a number from 0 to 100."""
439
  """
440
 
441
  try:
442
- # Convert Pydantic model to JSON schema for Gemini
443
- from google.generativeai.types import GenerationConfig
444
-
445
- # Create model with structured output (response_schema)
446
- model_with_schema = genai.GenerativeModel(
447
- settings.GEMINI_MODEL,
448
- generation_config=GenerationConfig(
449
- temperature=0.1, # Low temperature for consistent analysis
450
- response_mime_type="application/json",
451
- response_schema=AISummary # Gemini will enforce this schema
452
- )
453
  )
454
 
455
- # FIX: Use synchronous generate_content in async context properly
456
- import nest_asyncio
457
- nest_asyncio.apply() # Allow nested event loops
458
-
459
  # Run in executor to avoid blocking
460
  loop = asyncio.get_event_loop()
461
  response = await loop.run_in_executor(
462
- None, # Use default executor
463
- model_with_schema.generate_content,
464
- prompt
 
 
 
465
  )
466
 
467
  import json
 
439
  """
440
 
441
  try:
442
+ # Use new google.genai SDK with JSON response schema
443
+ # Create config with response_schema for guaranteed JSON output
444
+ summary_config = types.GenerateContentConfig(
445
+ temperature=0.1, # Low temperature for consistent analysis
446
+ max_output_tokens=4096,
447
+ response_mime_type="application/json",
448
+ response_schema=AISummary.model_json_schema() # Pydantic v2 JSON schema
 
 
 
 
449
  )
450
 
 
 
 
 
451
  # Run in executor to avoid blocking
452
  loop = asyncio.get_event_loop()
453
  response = await loop.run_in_executor(
454
+ None,
455
+ lambda: self.client.models.generate_content(
456
+ model=self.model_name,
457
+ contents=prompt,
458
+ config=summary_config
459
+ )
460
  )
461
 
462
  import json