
教程
Himi LiProduct Manager at EvoLink9 分钟阅读
GLM-5.4 怎么用?从首次 API 调用到截图修复
用 EvoLink 调用 GLM-5.4,把截图和 HTML、CSS 发给模型,并验证移动端结账按钮是否修好。
文章目录
EvoLink 的 Chat Completions API 已支持
glm-5.4。先用 EvoLink 密钥发一条短文本,再把截图和对应源码一起发给模型。示例里的帮助气泡在 390 CSS 像素宽的视口挡住了 Place order 按钮右侧。你会让模型给出 CSS 补丁,并在浏览器里确认两个按钮都能点到。 获取 EvoLink API 密钥发送纯文本请求
准备 EvoLink API 密钥、
curl 和 jq。第 3 步还需要 Python 3。在当前终端设置环境变量 EVOLINK_API_KEY。两个请求都发到 https://api.evolink.ai/v1/chat/completions,通过 Bearer 请求头鉴权。 管理 EvoLink 密钥curl --silent --show-error --fail-with-body \
https://api.evolink.ai/v1/chat/completions \
-H "Authorization: Bearer ${EVOLINK_API_KEY:?Set EVOLINK_API_KEY}" \
-H 'Content-Type: application/json' \
--data '{
"model": "glm-5.4",
"stream": false,
"reasoning_effort": "low",
"messages": [
{ "role": "user", "content": "Reply with just the word READY." }
]
}' \
-o text-response.json &&
jq -e '{model, answer: .choices[0].message.content, usage}
| select((.answer // "") | length > 0)' text-response.jsonAPI 成功返回且
choices[0].message.content 有正文时,说明基础请求打通。这里期望看到 READY。model 是端点在响应中报告的型号。保留 usage,稍后与截图请求比对。 EvoLink 响应示例在移动端复现按钮遮挡
将下面的代码保存为
checkout.html。在浏览器打开文件,进入响应式模式,把视口设成 390 × 540 CSS 像素。帮助按钮会叠在结账按钮右边。在 1280 × 720 下,两个按钮各自占据独立区域。<!doctype html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Checkout overlap example</title>
<style>
body { margin: 0; background: #f4f6fa; color: #182235; font: 16px system-ui, sans-serif; }
main { max-width: 26rem; margin: 48px auto; padding: 0 16px; }
h1 { margin: 0 0 24px; }
.summary { padding: 20px; border: 1px solid #dae0eb; border-radius: 12px; background: white; }
.summary p:first-child { margin-top: 0; }
.summary p:last-child { margin-bottom: 0; }
.actions { position: fixed; inset: auto 16px 24px; display: grid; max-width: 26rem; margin-inline: auto; }
button { font: inherit; font-weight: 600; cursor: pointer; }
.place-order { width: 100%; min-height: 52px; border: 0; border-radius: 10px; background: #1742bf; color: white; }
.help-bubble { position: fixed; right: 16px; bottom: 16px; z-index: 2; width: 112px; min-height: 44px; border: 0; border-radius: 24px; background: #17243d; color: white; }
</style>
<main>
<h1>Checkout</h1>
<section class="summary" aria-label="Order summary">
<p>Travel mug × 1</p>
<p><strong>Total $24.00</strong></p>
</section>
<p id="status" role="status"></p>
</main>
<div class="actions">
<button class="place-order" type="button">Place order</button>
<button class="help-bubble" type="button">Need help?</button>
</div>
<script>
const statusLine = document.querySelector("#status");
document.querySelector(".place-order").onclick = () => { statusLine.textContent = "Order button clicked"; };
document.querySelector(".help-bubble").onclick = () => { statusLine.textContent = "Help button clicked"; };
</script>
</html>将 390px 原始截图 保存为
checkout-390.png,与 checkout.html 放在同一目录。你也可以在相同视口尺寸下重新截图。示例是静态页面,两个按钮只在页面上更新被点击的控件名称。
把截图、源码和提示一起发送
截图给出重叠的控件。源码提供定位、堆叠顺序和 CSS 选择器,让模型能给出针对性的补丁。把下面的提示保存为同目录下的
repair-prompt.txt。The attached screenshot is checkout.html at a viewport of 390 × 540 CSS pixels.
The Need help button covers the right edge of Place order.
Use the screenshot and the source below to explain which CSS rules cause the overlap.
Return one minimal CSS-only unified diff for checkout.html. Keep both buttons
visible and clickable at 390 px, with no horizontal overflow. Preserve the fixed
bottom-right help position and the centered action at 1280 px. Keep both labels
and click handlers. Finish with instructions for checking the right edge of
Place order, the help button, and the desktop layout.示例把 PNG 转成 Base64 Data URL,放进
image_url 内容块。也可以传 EvoLink 能直接读取的公开图片 URL。GLM-5.4 始终启用推理,reasoning_effort 支持 low、high 和 max。示例选 high,推理和最终答案共用 8,192 Token 的输出预算。python3 - <<'PY' > screenshot-request.json
import base64
import json
from pathlib import Path
image = base64.b64encode(Path("checkout-390.png").read_bytes()).decode("ascii")
prompt = Path("repair-prompt.txt").read_text(encoding="utf-8")
source = Path("checkout.html").read_text(encoding="utf-8")
print(json.dumps({
"model": "glm-5.4",
"stream": False,
"reasoning_effort": "high",
"max_tokens": 8192,
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": f"{prompt}\n\ncheckout.html:\n{source}"},
{"type": "image_url", "image_url": {"url": f"data:image/png;base64,{image}"}},
],
}],
}))
PY
curl --silent --show-error --fail-with-body \
https://api.evolink.ai/v1/chat/completions \
-H "Authorization: Bearer ${EVOLINK_API_KEY:?Set EVOLINK_API_KEY}" \
-H 'Content-Type: application/json' \
--data-binary @screenshot-request.json \
-o screenshot-response.json &&
jq -e '{model, finish_reason: .choices[0].finish_reason,
answer: .choices[0].message.content, usage}
| select((.answer // "") | length > 0)' screenshot-response.json从
answer 读取补丁。EvoLink 将媒体转换成输入 Token,usage.prompt_tokens 包含图片、提示与源码;completion_tokens 包含输出及推理用量。若响应提供 prompt_tokens_details.cached_tokens,可以看到命中缓存的 Token 数。截图请求比纯文本请求还加了源码与指令,所以两个总数的差额包含这些变化。 查看实际 API 用量应用补丁并验证
阅读返回的 diff,再改到本地。这个例子里,窄屏下两个按钮占用同一个右下区域,帮助按钮因
z-index 更高而拦截重叠范围的点击。参考修复是在窄屏把两个按钮排成两行。把下面的 CSS 加到现有样式之后,可用它对照模型补丁。@media (max-width: 720px) {
.actions { gap: 8px; }
.help-bubble { position: static; justify-self: end; }
}| 检查 | 预期结果 |
|---|---|
| 390 × 540,点结账按钮垂直中心、离右边缘向内 12px 的位置 | 状态显示 Order button clicked。修复前,结账按钮内同一相对位置会点到帮助按钮。 |
| 390 × 540,点帮助按钮 | 显示 Help button clicked。两个控件可见、互不重叠,页面无横向滚动条。 |
| 1280 × 720,分别点击两个按钮 | 两次点击各自更新状态;结账按钮保持水平居中,帮助按钮距右边和底边各 16px。 |
参考 CSS 是作者编写的示例,点击检查已在 Chromium 验证。
这段录屏用的是 390 像素宽的结账页面。第一次点到重叠区域时触发了帮助按钮。应用参考 CSS 补丁后,点击 Place order 和 Need help? 会显示各自的状态。视频记录的是教程示例补丁在浏览器里的验收效果。
常见排错
- 文本请求报错。 查看
text-response.json中的错误对象,确认EVOLINK_API_KEY是有效的 EvoLink 密钥,请求体中的型号为glm-5.4。 - 文本成功、图片失败。 确认文件是 PNG 且 Data URL 以
data:image/png;base64,开头。使用托管地址时,确认原图无需登录或 Cookie 就能访问。 - 补丁还没写完就停止。 查看
finish_reason。如果达到长度限制,可删掉与当前问题无关的源码,或调整输出预算。补丁在choices[0].message.content,应用后按上述步骤做浏览器验证。
接下来可以把截图和对应组件替换成自己的实例。 对比 GLM-5.4 的其他入口与计费方式


