调用智谱清言的图像识别接口
github地址:https://github.com/LLM-Red-Team/glm-free-api
1.docker 来取镜像并部署
拉取镜像
docker pull vinlic/glm-free-api:latest
docker部署
docker run -it -d --init --name glm-free-api -p 8000:8000 -e TZ=Asia/Shanghai vinlic/glm-free-api:latest
查看服务实时日志
docker logs -f glm-free-api
重启服务
docker restart glm-free-api
停止服务
docker stop glm-free-api
Docker-compose部署
version: '3' services: glm-free-api: container_name: glm-free-api image: vinlic/glm-free-api:latest restart: always ports: - "8000:8000" environment: - TZ=Asia/Shanghai
2.接口调用
demo 代码(图像识别 )
import requests import json url = "http://10.101.92.218:8000/v1/chat/completions" payload = json.dumps({ "model": "65c046a531d3fcb034918abe", "messages": [ { "role": "user", "content": [ { "type": "image_url", "image_url": { "url": "http://10.101.92.218:9000/456.jpg" } }, { "type": "text", "text": "整理图片内容" } ] } ], "stream": False }) headers = { 'Authorization': 'xxxx', 'Content-Type': 'application/json' } response = requests.request("POST", url, headers=headers, data=payload) data = response.json() print(data.get("choices")[0].get("message").get("content"))
注意点:1.Authorization的值自己去浏览器找
2.图片的url--互联网可读取的图片url,可以图片传到某台服务器,然后开个 python -m http.server 9000 让接口可访问