rairo commited on
Commit
99e8be4
·
verified ·
1 Parent(s): ba74ad7

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +14 -5
main.py CHANGED
@@ -79,9 +79,10 @@ except Exception as e:
79
  # → gemini-3.1-flash-lite (Gemini 3.1 Flash-Lite,
80
  # Google's most cost-efficient model as of May 2026)
81
  #
82
- # GENERATION_MODEL : multimodal image+text generation
83
- # gemini-3.1-flash-image-preview (Nano Banana 2,
84
- # launched Feb 26 2026 as Gemini 3.1 Flash Image)
 
85
  #
86
  # SUMMARY_MODEL : lightweight text analysis for call briefings
87
  # → gemini-2.5-flash-lite (replaces 2.0-flash-lite
@@ -317,7 +318,11 @@ def generate_tts_audio_and_upload(text_to_speak, uid, project_id, step_num):
317
 
318
 
319
  def send_text_request(model_name, prompt, image):
320
- """Helper to send requests that expect only a text response."""
 
 
 
 
321
  try:
322
  chat = client.chats.create(model=model_name)
323
  response = chat.send_message([prompt, image])
@@ -1375,7 +1380,11 @@ def create_project():
1375
  INITIAL PLAN:
1376
  [Your plan or 3 options]
1377
  """
1378
- plan_response = send_text_request(GENERATION_MODEL, plan_prompt, pil_image)
 
 
 
 
1379
  if not plan_response:
1380
  return jsonify({'error': 'Failed to generate project plan from AI.'}), 500
1381
 
 
79
  # → gemini-3.1-flash-lite (Gemini 3.1 Flash-Lite,
80
  # Google's most cost-efficient model as of May 2026)
81
  #
82
+ # GENERATION_MODEL : IMAGE OUTPUT ONLY (Nano Banana 2). It must always be
83
+ # called with response_modalities=['Text', 'Image'] — a
84
+ # text-only request against this model returns 400
85
+ # INVALID_ARGUMENT. Never route text prompts here.
86
  #
87
  # SUMMARY_MODEL : lightweight text analysis for call briefings
88
  # → gemini-2.5-flash-lite (replaces 2.0-flash-lite
 
318
 
319
 
320
  def send_text_request(model_name, prompt, image):
321
+ """Helper to send requests that expect only a text response.
322
+
323
+ Only pass text-capable models here (CATEGORY_MODEL, PLAN_TEXT_MODEL,
324
+ SUMMARY_MODEL). Image-output models reject text-only requests with 400.
325
+ """
326
  try:
327
  chat = client.chats.create(model=model_name)
328
  response = chat.send_message([prompt, image])
 
1380
  INITIAL PLAN:
1381
  [Your plan or 3 options]
1382
  """
1383
+ # FIX (400 INVALID_ARGUMENT): this is a text-only response, so it must go
1384
+ # to a text model. GENERATION_MODEL (gemini-3.1-flash-image-preview) is an
1385
+ # image-output model that requires response_modalities=['Text','Image'];
1386
+ # sending it a plain text chat rejects with 400 before generation begins.
1387
+ plan_response = send_text_request(PLAN_TEXT_MODEL, plan_prompt, pil_image)
1388
  if not plan_response:
1389
  return jsonify({'error': 'Failed to generate project plan from AI.'}), 500
1390