curl_ollama.sh 942 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/bash
  2. # 检查图片文件是否存在
  3. if [ ! -f "./sample_data/PictureCheckCode.jpeg" ]; then
  4. echo "错误:图片文件不存在"
  5. exit 1
  6. fi
  7. # 将图片转换为 base64
  8. image1_base64=$(base64 -i ./sample_data/PictureCheckCode.jpeg)
  9. # 检查 base64 转换是否成功
  10. if [ -z "$image1_base64" ]; then
  11. echo "错误:base64 转换失败"
  12. exit 1
  13. fi
  14. # 第一个请求:提取验证码
  15. echo "发送第一个请求..."
  16. response=$(curl -X POST "http://localhost:11434/api/generate" \
  17. -H "Content-Type: application/json" \
  18. --max-time 300 \
  19. --silent \
  20. --data "{
  21. \"model\": \"gemma3n\",
  22. \"prompt\": \"提取图片中的验证码,只返回数字\",
  23. \"images\": [\"${image1_base64}\"],
  24. \"stream\": false
  25. }")
  26. # 检查响应
  27. if [ $? -eq 0 ]; then
  28. echo "响应:"
  29. echo "$response" | jq -r '.response' 2>/dev/null || echo "$response"
  30. else
  31. echo "请求失败"
  32. fi