mirror of
https://git.openapi.site/https://github.com/desirecore/config-center.git
synced 2026-12-05 09:29:59 +08:00
fix(vision): 按内容块提取 Anthropic 视觉文本并更新预设至 v137 (#130)
Co-authored-by: Corona <corona@CoronadeMac-Mini-2.local>
This commit is contained in:
1 parent
6eef9c1fb7
commit
c87e5521a4
5 files changed
+72
-10
No files matched your search
@@ -0,0 +1,39 @@
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { loadSchemas } from '../scripts/validate.mjs'
|
||||
|
||||
const read = path => JSON.parse(readFileSync(new URL(`../${path}`, import.meta.url), 'utf8'))
|
||||
const validate = loadSchemas()['api-provider']
|
||||
|
||||
test('Anthropic 视觉配置显式选择整个内容块数组,兼容首块为推理的响应', () => {
|
||||
const config = read('api-providers/image-understanding/configured-vision-anthropic.json')
|
||||
assert.deepEqual(config.response, { textPath: 'content', textFormat: 'text-blocks' })
|
||||
assert.equal(validate(config), true, JSON.stringify(validate.errors))
|
||||
})
|
||||
|
||||
test('字符串响应格式可省略,旧 OpenAI 视觉配置仍有效', () => {
|
||||
const config = read('api-providers/image-understanding/configured-vision-openai.json')
|
||||
assert.equal(Object.hasOwn(config.response, 'textFormat'), false)
|
||||
assert.equal(validate(config), true, JSON.stringify(validate.errors))
|
||||
assert.equal(Object.hasOwn(config.response, 'textFormat'), false)
|
||||
config.response.textFormat = 'string'
|
||||
assert.equal(validate(config), true, JSON.stringify(validate.errors))
|
||||
})
|
||||
|
||||
test('响应格式拒绝未知值和非字符串,避免默默接受未实现的提取策略', () => {
|
||||
for (const textFormat of ['thinking-blocks', null, true, []]) {
|
||||
const config = read('api-providers/image-understanding/configured-vision-anthropic.json')
|
||||
config.response.textFormat = textFormat
|
||||
assert.equal(validate(config), false)
|
||||
assert.ok(validate.errors.some(error => error.instancePath === '/response/textFormat'))
|
||||
}
|
||||
})
|
||||
|
||||
test('响应配置继续拒绝未知字段', () => {
|
||||
const config = read('api-providers/image-understanding/configured-vision-anthropic.json')
|
||||
config.response.includeThinking = true
|
||||
assert.equal(validate(config), false)
|
||||
assert.ok(validate.errors.some(error => error.keyword === 'additionalProperties'
|
||||
&& error.params.additionalProperty === 'includeThinking'))
|
||||
})
|
||||
@@ -27,6 +27,6 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": { "textPath": "content.0.text" },
|
||||
"response": { "textPath": "content", "textFormat": "text-blocks" },
|
||||
"timeoutMs": 30000
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
# 视觉模型(Anthropic 兼容,复用默认映射)
|
||||
|
||||
旧 docs.anthropic.com 跳转至此官方域名,正文证明 Messages 的 image/base64/media_type/data 结构;max_tokens=1024 是本仓输出预算策略,官网示例使用该值不证明它是默认或上限。认证、API 版本和 content.0.text 不因本篇已读而视作全部核验;任意网关仍需验收。
|
||||
旧 docs.anthropic.com 跳转至此官方域名,正文证明 Messages 的 image/base64/media_type/data 结构;max_tokens=1024 是本仓输出预算策略,官网示例使用该值不证明它是默认或上限。认证和 API 版本不因本篇已读而视作全部核验;任意网关仍需验收。
|
||||
|
||||
2026-11-03 重新读取官方 Vision 和 Messages API 正文。Messages 的响应 `content` 是异构内容块数组,文本块使用 `type=text` 与字符串 `text`,推理块另有独立类型;不能假定首块就是文本。因此将提取路径改为 `content`,显式使用客户端的 `text-blocks` 格式,仅顺序连接顶层文本块并忽略推理等其他块。`textFormat` 和换行连接是 DesireCore 的声明式消费契约,不是 Anthropic 请求参数。该配置依赖主仓新增的消费支持;旧 Schema 应拒绝候选并继续使用原有效快照,不允许把数组转换成字符串。本仓校验不代表新客户端已正式发布,也不代表任意兼容网关实测通过。
|
||||
|
||||
数据区中的 claims 是复核边界,pending 字段是当前配置快照,不能当官方证明。enabled/priority/timeout 是产品策略,未复制到合同中。更新合同必须重新读官方正文、记录实际证明字段;结构校验不等于账号可用。
|
||||
|
||||
@@ -9,7 +11,7 @@
|
||||
{
|
||||
"kind": "api-contract",
|
||||
"config": "api-providers/image-understanding/configured-vision-anthropic.json",
|
||||
"checkedAt": "2026-10-03",
|
||||
"checkedAt": "2026-11-03",
|
||||
"status": "partial",
|
||||
"sources": [
|
||||
{
|
||||
@@ -18,11 +20,26 @@
|
||||
"checkedAt": "2026-10-03",
|
||||
"resolvedUrl": "https://platform.claude.com/docs/en/build-with-claude/vision",
|
||||
"contentSha256": "b35b04f339283acf2d250590830e7c552575c27d78c9b694523a6417a7a58044"
|
||||
},
|
||||
{
|
||||
"url": "https://platform.claude.com/docs/en/build-with-claude/vision.md",
|
||||
"retrieval": "fetched",
|
||||
"checkedAt": "2026-11-03",
|
||||
"resolvedUrl": "https://platform.claude.com/docs/en/build-with-claude/vision.md",
|
||||
"contentSha256": "f67ae8c652f2fc05bf681e7020268d186c5f34b7c713852934b533548c9108ed"
|
||||
},
|
||||
{
|
||||
"url": "https://platform.claude.com/docs/en/api/messages/create.md",
|
||||
"retrieval": "fetched",
|
||||
"checkedAt": "2026-11-03",
|
||||
"resolvedUrl": "https://platform.claude.com/docs/en/api/messages/create.md",
|
||||
"contentSha256": "7bdae71980a2aff09491755da1744932b5cf722f459c1d4a2a8c818539f82ce3"
|
||||
}
|
||||
],
|
||||
"verifiedFields": [
|
||||
"request.bodyTemplate.messages.0.content.0.type",
|
||||
"request.bodyTemplate.messages.0.content.0.source.type"
|
||||
"request.bodyTemplate.messages.0.content.0.source.type",
|
||||
"response.textPath"
|
||||
],
|
||||
"claims": {
|
||||
"endpoint": "${baseUrl}/messages",
|
||||
@@ -61,7 +78,8 @@
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"textPath": "content.0.text"
|
||||
"textPath": "content",
|
||||
"textFormat": "text-blocks"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"presetDataVersion": 136,
|
||||
"updatedAt": "2026-11-02",
|
||||
"presetDataVersion": 137,
|
||||
"updatedAt": "2026-11-03",
|
||||
"description": "DesireCore 官方配置中心"
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"$id": "https://desirecore.net/schemas/config-center/api-provider.schema.json",
|
||||
"title": "ApiProvider",
|
||||
"description": "api-providers/<capability>/*.json:声明式外部 API 供应商(web_search / image_understanding 工具后端)。镜像 desirecore 主仓 lib/schemas/agent-service/api-provider.ts。",
|
||||
"description": "api-providers/<capability>/*.json:声明式外部 API 供应商(web_search / image_understanding 工具后端)。镜像 desirecore 主仓 packages/schemas/src/agent-service/api-provider.ts。",
|
||||
"type": "object",
|
||||
"required": ["id", "name", "capability", "enabled", "endpoint", "auth", "request", "response"],
|
||||
"additionalProperties": false,
|
||||
@@ -47,7 +47,7 @@
|
||||
},
|
||||
"response": {
|
||||
"type": "object",
|
||||
"description": "响应提取",
|
||||
"description": "响应解析。web_search 用 resultsPath + item;image_understanding 用 textPath + textFormat",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"resultsPath": { "type": "string", "description": "web_search 结果数组的点路径" },
|
||||
@@ -61,7 +61,12 @@
|
||||
"pageAgePath": { "type": "string" }
|
||||
}
|
||||
},
|
||||
"textPath": { "type": "string", "description": "image_understanding 结果文本的点路径" },
|
||||
"textPath": { "type": "string", "description": "image_understanding:响应结果的点路径。string 格式指向字符串(如 choices.0.message.content);text-blocks 格式指向内容块数组(如 content)" },
|
||||
"textFormat": {
|
||||
"type": "string",
|
||||
"enum": ["string", "text-blocks"],
|
||||
"description": "image_understanding:textPath 指向值的格式,省略时为 string,仅接受字符串;text-blocks 仅按原顺序读取顶层数组中 type=text 且 text 为字符串的内容,以换行连接,忽略推理、工具、图片及其他块,不递归提取"
|
||||
},
|
||||
"successCondition": {
|
||||
"type": "object",
|
||||
"description": "可选业务成功判定;HTTP 成功后读取 path 并与 equals 严格比较,不匹配时按 Provider 失败继续降级",
|
||||
|
||||
Reference in new issue
Block a user