refactor: 更换图片发送方式

This commit is contained in:
hp0912 2026-04-05 15:15:27 +08:00
parent 56faf12d25
commit a4ebe79c2e
5 changed files with 52 additions and 22 deletions

View File

@ -29,3 +29,17 @@ MYSQL_PASSWORD=houhou
<wechat-robot-image-url>图片URL3</wechat-robot-image-url> <wechat-robot-image-url>图片URL3</wechat-robot-image-url>
<wechat-robot-image-url>图片URL4</wechat-robot-image-url> <wechat-robot-image-url>图片URL4</wechat-robot-image-url>
``` ```
**发送图片的时候也可以调用 Agent 接口**
```
[POST] http://127.0.0.1:{ROBOT_WECHAT_CLIENT_PORT}/api/v1//robot/message/send/image/url
请求体 Body:
{
"to_wxid": "{{ROBOT_FROM_WX_ID}}",
"image_urls": ["{{imageurl}}"]
}
```

View File

@ -94,14 +94,9 @@ argument-hint: "需要 prompt提示词和 images图片链接列表
1. 当用户发送图片并附带修改、合成、风格转换等描述时触发该技能。 1. 当用户发送图片并附带修改、合成、风格转换等描述时触发该技能。
2. 从用户输入中提取 prompt提示词不对提示词做总结或修改。提取 images图片链接列表。可选提取 model、negative_prompt、ratio、resolution 参数。 2. 从用户输入中提取 prompt提示词不对提示词做总结或修改。提取 images图片链接列表。可选提取 model、negative_prompt、ratio、resolution 参数。
3. 将参数组装为 shell 风格命令行参数,在仓库根目录下执行本地脚本,例如:`python3 image-to-image/scripts/image_to_image.py --prompt '把这张图变成油画风格' --images 'https://example.com/img1.jpg' --images 'https://example.com/img2.jpg' --model jimeng-5.0`。 3. 将参数组装为 shell 风格命令行参数,在仓库根目录下执行本地脚本,例如:`python3 image-to-image/scripts/image_to_image.py --prompt '把这张图变成油画风格' --images 'https://example.com/img1.jpg' --images 'https://example.com/img2.jpg' --model jimeng-5.0`。
4. 成功时脚本输出 4. 脚本生成图片后会自动调用客户端接口 `POST http://127.0.0.1:{ROBOT_WECHAT_CLIENT_PORT}/api/v1/robot/message/send/image/url` 将图片发送给用户,成功时输出「图片发送成功」。
```
<wechat-robot-image-url>图片URL1</wechat-robot-image-url>
<wechat-robot-image-url>图片URL2</wechat-robot-image-url>
```
## 回复要求 ## 回复要求
- 成功时,脚本输出 `<wechat-robot-image-url>图片URL1</wechat-robot-image-url><wechat-robot-image-url>图片URL2</wechat-robot-image-url>` 格式AI 智能体接收到这种格式内容会自动发送图片 - 成功时,脚本输出「图片发送成功」,表示图片已通过客户端接口直接发送,无需 AI 智能体再做额外处理。
- 失败时,返回具体的失败信息。 - 失败时,返回具体的失败信息。

View File

@ -424,11 +424,24 @@ def main() -> int:
sys.stdout.write("未生成任何图像\n") sys.stdout.write("未生成任何图像\n")
return 1 return 1
for url in image_urls: # 通过客户端接口发送图片
if url: client_port = os.environ.get("ROBOT_WECHAT_CLIENT_PORT", "").strip()
sys.stdout.write(f"<wechat-robot-image-url>{url}</wechat-robot-image-url>") if not client_port:
sys.stdout.write("环境变量 ROBOT_WECHAT_CLIENT_PORT 未配置\n")
return 1
send_url = f"http://127.0.0.1:{client_port}/api/v1/robot/message/send/image/url"
send_body = {
"to_wxid": from_wx_id,
"image_urls": [u for u in image_urls if u],
}
try:
_http_post_json(send_url, send_body, {"Content-Type": "application/json"}, timeout=60)
sys.stdout.write("图片发送成功\n")
except Exception as exc:
sys.stdout.write(f"发送图片失败: {exc}\n")
return 1
sys.stdout.write("\n")
return 0 return 0

View File

@ -89,14 +89,9 @@ argument-hint: "需要 prompt 参数(画图提示词),可选 model
1. 当用户想通过文本描述生成图像时触发该技能。 1. 当用户想通过文本描述生成图像时触发该技能。
2. 从用户输入中提取 prompt画图提示词不对提示词做总结或修改。可选提取 model、negative_prompt、ratio、resolution 参数。 2. 从用户输入中提取 prompt画图提示词不对提示词做总结或修改。可选提取 model、negative_prompt、ratio、resolution 参数。
3. 将参数组装为 shell 风格命令行参数,在仓库根目录下执行本地脚本,例如:`python3 text-to-image/scripts/text_to_image.py --prompt '一只可爱的猫咪在花园里玩耍' --model jimeng-5.0`。 3. 将参数组装为 shell 风格命令行参数,在仓库根目录下执行本地脚本,例如:`python3 text-to-image/scripts/text_to_image.py --prompt '一只可爱的猫咪在花园里玩耍' --model jimeng-5.0`。
4. 成功是脚本输出 4. 脚本生成图片后会自动调用客户端接口 `POST http://127.0.0.1:{ROBOT_WECHAT_CLIENT_PORT}/api/v1/robot/message/send/image/url` 将图片发送给用户,成功时输出「图片发送成功」。
```
<wechat-robot-image-url>图片URL1</wechat-robot-image-url>
<wechat-robot-image-url>图片URL2</wechat-robot-image-url>
```
## 回复要求 ## 回复要求
- 成功时,脚本输出 `<wechat-robot-image-url>图片URL1</wechat-robot-image-url><wechat-robot-image-url>图片URL2</wechat-robot-image-url>` 格式AI 智能体接受到这种格式内容会自动发送图片 - 成功时,脚本输出「图片发送成功」,表示图片已通过客户端接口直接发送,无需 AI 智能体再做额外处理。
- 失败时,返回具体的失败信息。 - 失败时,返回具体的失败信息。

View File

@ -423,11 +423,24 @@ def main() -> int:
sys.stdout.write("未生成任何图像\n") sys.stdout.write("未生成任何图像\n")
return 1 return 1
for url in image_urls: # 通过客户端接口发送图片
if url: client_port = os.environ.get("ROBOT_WECHAT_CLIENT_PORT", "").strip()
sys.stdout.write(f"<wechat-robot-image-url>{url}</wechat-robot-image-url>") if not client_port:
sys.stdout.write("环境变量 ROBOT_WECHAT_CLIENT_PORT 未配置\n")
return 1
send_url = f"http://127.0.0.1:{client_port}/api/v1/robot/message/send/image/url"
send_body = {
"to_wxid": from_wx_id,
"image_urls": [u for u in image_urls if u],
}
try:
_http_post_json(send_url, send_body, {"Content-Type": "application/json"}, timeout=60)
sys.stdout.write("图片发送成功\n")
except Exception as exc:
sys.stdout.write(f"发送图片失败: {exc}\n")
return 1
sys.stdout.write("\n")
return 0 return 0