docs(discovery): 用实测数据替换注释里的猜测

composeImageEndpoint 原注释写着「两种形式都 404,无法区分」,那是我写代码时
的推测,不是观测。后来真实打了一次上游就分清了:

  /v1/images/generations    → 200(图像生成本身要几分钟,是上游耗时)
  /v1/v1/images/generations → 404
  /images/generations      → 404

注释里的假话比没有注释更糟——下一个人会拿它当「已知的模糊地带」而不敢
收紧判据。
This commit is contained in:
root
2026-10-06 08:05:37 +08:00
committed by JianFeeeee
parent ae9f56ddb3
commit 7ce0378e8b

View File

@ -285,18 +285,22 @@ func composeEndpoint(modelsPath, persistedBase, typedBase string) string {
// //
// base "https://h" + "/v1/images/generations" → correct // base "https://h" + "/v1/images/generations" → correct
// base "https://h/v1" + "/v1/images/generations" → "/v1/v1/…" 404 // base "https://h/v1" + "/v1/images/generations" → "/v1/v1/…" 404
// base "https://h/v1" + "/images/generations" → "/v1/images/generations" correct
// //
// Emitting "" when the base already ends in a version is wrong for a different // The second row is not a theoretical guess. Measured against the real
// reason: the vendor's catalog path is not proof that its image path carries // amr-link endpoint with base_url "https://amr-link.open-design.ai/v1":
// the same prefix. Some gateways serve the catalog at "/v1/models" but the //
// image endpoint at "/images/generations" (observed: 404 on both forms, but a // …/v1/images/generations → 200 (the image is then generated; that call
// 404 from the doubled form is indistinguishable from a 404 from the wrong // takes minutes, which is the upstream's own
// host). Rather than guess, the value written here is derived from the base so // latency and not a routing problem)
// it composes, and the caller can still override image_endpoint by hand. // …/v1/v1/images/generations → 404
// …/images/generations → 404
//
// Leaving the default in place when the base already ends in a version is
// therefore always wrong for such an upstream, and the version-relative form
// is the one that composes.
func composeImageEndpoint(persistedBase string) string { func composeImageEndpoint(persistedBase string) string {
if b := trimVersionSuffix(persistedBase); b != persistedBase { if b := trimVersionSuffix(persistedBase); b != persistedBase {
// The base ends in a version segment, so the default absolute path
// would double it. Use the version-relative form instead.
return "/images/generations" return "/images/generations"
} }
return "" return ""