refactor: 更换图片发送方式
This commit is contained in:
parent
56faf12d25
commit
a4ebe79c2e
14
README.md
14
README.md
@ -29,3 +29,17 @@ MYSQL_PASSWORD=houhou
|
||||
<wechat-robot-image-url>图片URL3</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}}"]
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
@ -94,14 +94,9 @@ argument-hint: "需要 prompt(提示词)和 images(图片链接列表)
|
||||
1. 当用户发送图片并附带修改、合成、风格转换等描述时触发该技能。
|
||||
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`。
|
||||
4. 成功时脚本输出
|
||||
|
||||
```
|
||||
<wechat-robot-image-url>图片URL1</wechat-robot-image-url>
|
||||
<wechat-robot-image-url>图片URL2</wechat-robot-image-url>
|
||||
```
|
||||
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>` 格式,AI 智能体接收到这种格式内容会自动发送图片。
|
||||
- 成功时,脚本输出「图片发送成功」,表示图片已通过客户端接口直接发送,无需 AI 智能体再做额外处理。
|
||||
- 失败时,返回具体的失败信息。
|
||||
|
||||
@ -424,11 +424,24 @@ def main() -> int:
|
||||
sys.stdout.write("未生成任何图像\n")
|
||||
return 1
|
||||
|
||||
for url in image_urls:
|
||||
if url:
|
||||
sys.stdout.write(f"<wechat-robot-image-url>{url}</wechat-robot-image-url>")
|
||||
# 通过客户端接口发送图片
|
||||
client_port = os.environ.get("ROBOT_WECHAT_CLIENT_PORT", "").strip()
|
||||
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
|
||||
|
||||
|
||||
|
||||
@ -89,14 +89,9 @@ argument-hint: "需要 prompt 参数(画图提示词),可选 model(模
|
||||
1. 当用户想通过文本描述生成图像时触发该技能。
|
||||
2. 从用户输入中提取 prompt(画图提示词),不对提示词做总结或修改。可选提取 model、negative_prompt、ratio、resolution 参数。
|
||||
3. 将参数组装为 shell 风格命令行参数,在仓库根目录下执行本地脚本,例如:`python3 text-to-image/scripts/text_to_image.py --prompt '一只可爱的猫咪在花园里玩耍' --model jimeng-5.0`。
|
||||
4. 成功是脚本输出
|
||||
|
||||
```
|
||||
<wechat-robot-image-url>图片URL1</wechat-robot-image-url>
|
||||
<wechat-robot-image-url>图片URL2</wechat-robot-image-url>
|
||||
```
|
||||
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>` 格式,AI 智能体接受到这种格式内容会自动发送图片。
|
||||
- 成功时,脚本输出「图片发送成功」,表示图片已通过客户端接口直接发送,无需 AI 智能体再做额外处理。
|
||||
- 失败时,返回具体的失败信息。
|
||||
|
||||
@ -423,11 +423,24 @@ def main() -> int:
|
||||
sys.stdout.write("未生成任何图像\n")
|
||||
return 1
|
||||
|
||||
for url in image_urls:
|
||||
if url:
|
||||
sys.stdout.write(f"<wechat-robot-image-url>{url}</wechat-robot-image-url>")
|
||||
# 通过客户端接口发送图片
|
||||
client_port = os.environ.get("ROBOT_WECHAT_CLIENT_PORT", "").strip()
|
||||
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
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user