buildOpenAiImageBody function

Map<String, dynamic> buildOpenAiImageBody(
  1. ImageGenerationRequest request, {
  2. bool b64ResponseFormat = false,
  3. bool sendSize = true,
  4. bool sendAspectRatio = false,
})

OpenAI 形式の画像生成リクエストのボディ。

b64ResponseFormat は response_format: b64_json を送るか(DALL·E と xAI は既定が URL のため。gpt-image は常に base64 で、この指定を拒否する)。 sendSize / sendAspectRatio で、プロバイダーが受け付けるものだけを送る。

Implementation

Map<String, dynamic> buildOpenAiImageBody(
  ImageGenerationRequest request, {
  bool b64ResponseFormat = false,
  bool sendSize = true,
  bool sendAspectRatio = false,
}) {
  final size = request.size;
  final aspectRatio = request.aspectRatio;
  return {
    'model': request.model,
    'prompt': request.prompt,
    if (request.n != 1) 'n': request.n,
    if (sendSize && size != null) 'size': size,
    if (sendAspectRatio && aspectRatio != null) 'aspect_ratio': aspectRatio,
    if (b64ResponseFormat) 'response_format': 'b64_json',
  };
}