fix(protocol): Grok 生图 - 让 response_format 开关生效 (#692)
This commit is contained in:
@@ -303,7 +303,7 @@ func grokImageRequestBody(input canvasGenerationInput) (grokImageRequest, string
|
||||
Model: input.Config.Model,
|
||||
Prompt: withSystemPrompt(input.Config, input.Prompt),
|
||||
N: 1,
|
||||
ResponseFormat: "url",
|
||||
ResponseFormat: grokImageResponseFormat(input.ImageCapability),
|
||||
// Grok 图片协议用 aspect_ratio 表达画布比例;同时发送 size 会被上游按 OpenAI 枚举校验并拒绝。
|
||||
AspectRatio: normalizeGrokImageAspectRatio(input.Config.Size),
|
||||
Resolution: normalizeGrokImageResolution(input.Config.Quality),
|
||||
@@ -322,6 +322,13 @@ func grokImageRequestBody(input canvasGenerationInput) (grokImageRequest, string
|
||||
return body, "/images/edits", nil
|
||||
}
|
||||
|
||||
func grokImageResponseFormat(profile *ImageCapabilityConfig) string {
|
||||
if imageParameterSupported(profile, "response_format") {
|
||||
return "b64_json"
|
||||
}
|
||||
return "url"
|
||||
}
|
||||
|
||||
// normalizeGrokImageResolution 把画布 quality(1k/2k/high…)映射为 grok2api / xAI 的 resolution。
|
||||
func normalizeGrokImageResolution(quality string) string {
|
||||
raw := strings.ToLower(strings.TrimSpace(quality))
|
||||
|
||||
@@ -91,6 +91,14 @@ func protocolRequestFromInput(input canvasGenerationInput) protocol.GenerationRe
|
||||
}
|
||||
}
|
||||
}
|
||||
if input.Mode == "image" && input.Config.InterfaceType == string(model.ChannelInterfaceGrokImage) {
|
||||
options := make(map[string]any)
|
||||
for name, value := range request.ProviderOptions[input.Config.InterfaceType] {
|
||||
options[name] = value
|
||||
}
|
||||
options["response_format"] = grokImageResponseFormat(input.ImageCapability)
|
||||
request.ProviderOptions[input.Config.InterfaceType] = options
|
||||
}
|
||||
return request
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,8 @@ curl "{channel_base_url}/v1/images/generations" \
|
||||
|
||||
## 响应与错误
|
||||
|
||||
模型能力配置中的 `response_format` 开关控制请求的返回格式:开启发送 `b64_json`,关闭发送 `url`。声明式插件和后端 Grok 手写路径共用此映射。xAI 零数据保留团队应开启该选项;Base64 图片由已有响应解析器接收,不需要另设接收开关。
|
||||
|
||||
插件按 OpenAI Images 风格解析 `data[]` 中的 `url`、`b64_json` 或 `data`。如果 xAI 的实际响应结构发生变化或只返回异步任务,当前解析会失败而不是伪造结果。素材不可达、比例/分辨率不受模型支持、模型无权限和审核拒绝应原样暴露。
|
||||
|
||||
## 官方资料
|
||||
|
||||
Reference in New Issue
Block a user