#!/bin/bash # 检查图片文件是否存在 if [ ! -f "./sample_data/PictureCheckCode.jpeg" ]; then echo "错误:图片文件不存在" exit 1 fi # 将图片转换为 base64 image1_base64=$(base64 -i ./sample_data/PictureCheckCode.jpeg) # 检查 base64 转换是否成功 if [ -z "$image1_base64" ]; then echo "错误:base64 转换失败" exit 1 fi # 第一个请求:提取验证码 echo "发送第一个请求..." response=$(curl -X POST "http://localhost:11434/api/generate" \ -H "Content-Type: application/json" \ --max-time 300 \ --silent \ --data "{ \"model\": \"gemma3n\", \"prompt\": \"提取图片中的验证码,只返回数字\", \"images\": [\"${image1_base64}\"], \"stream\": false }") # 检查响应 if [ $? -eq 0 ]; then echo "响应:" echo "$response" | jq -r '.response' 2>/dev/null || echo "$response" else echo "请求失败" fi