MCPcopy Create free account
hub / github.com/TheSmallHanCat/flow2api / _normalize_gemini_request

Function _normalize_gemini_request

src/api/routes.py:457–484  ·  view source on GitHub ↗
(
    model: str,
    request: GeminiGenerateContentRequest,
)

Source from the content-addressed store, hash-verified

455
456
457async def _normalize_gemini_request(
458 model: str,
459 request: GeminiGenerateContentRequest,
460) -> NormalizedGenerationRequest:
461 prompt, images = await _extract_prompt_and_images_from_gemini_contents(request.contents)
462 resolved_model = _resolve_request_model(model, request, images=images)
463 system_instruction = _extract_text_from_gemini_content(request.systemInstruction)
464 model_config = MODEL_CONFIG.get(resolved_model)
465 media_model = bool(model_config and model_config.get("type") in {"image", "video"})
466
467 if media_model:
468 prompt = _sanitize_media_prompt(prompt)
469
470 if system_instruction:
471 if media_model and _should_ignore_media_system_instruction(system_instruction):
472 debug_logger.log_warning(
473 f"[GEMINI] 忽略媒体模型的 systemInstruction: model={resolved_model}, len={len(system_instruction)}"
474 )
475 else:
476 if media_model:
477 system_instruction = _sanitize_media_prompt(system_instruction)
478 prompt = f"{system_instruction}\n\n{prompt}".strip()
479
480 return NormalizedGenerationRequest(
481 model=resolved_model,
482 prompt=prompt,
483 images=images,
484 )
485
486
487async def _collect_non_stream_result(

Callers 3

generate_contentFunction · 0.85
stream_generate_contentFunction · 0.85

Tested by

no test coverage detected