记录一下,其实也很简单。
- fork lanqian528/chat2api 到自己的Github
- (可选) 在VPS上跑个 lanqian528/funcaptcha_solver:latest,火墙放行 5006 端口 (后面 ARKOSE_TOKEN_URL 用 http://vps_ip:5006), 参看这个docker.yml 文件。
- cloud run 选定一个绑好了 Billing账户的项目,开一个服务(Create Service),选 tier 1 区(tier 2区无免费额),CPU allocation and pricing 选
CPU is only allocated during request processing (CPU is always allocated选项无免费额) - Container(s), Volumes, Networking, Security 里: port 选 5005(预设8080,不改成5005的话就要改chat2api repo里 Dockerfile 和 app.py 里的port);
VARIABLES & SECRETS里 Environment variables/value:ARKOSE_TOKEN_URL/http://vps_ip:5006 (这个是可选,但不设一个ARKOSE_TOKEN_URL可能用不了 gpt-4o) - Set up with Cloud Build: 选刚才fork的github repo, 例如 username/chat2api, Build Type选Dockerfile,点击Save
- cloud run 里点击Create
等待构建完成,最后有个类似 https://chat2api-……-uc.a.run.app 的网址,大功搞成。测试:
set TOKEN=<https://chatgpt.com/api/auth/session拿的accessToken>
set base_url=https://chat2api-……-uc.a.run.app
set model=gpt-3.5-turbo
echo base_url %base_url%
echo model %model%
curl --location "%base_url%/v1/chat/completions" ^
--header "Content-Type: application/json" ^
--header "Authorization: Bearer %TOKEN%" ^
--data "{\"model\": \"%model%\", \"messages\": [{\"role\": \"user\", \"content\": \"Say this is a test!\"}], \"stream
\": false}"
输出
model gpt-3.5-turbo
{"id":"chatcmpl-UygCyQxkp98wKAHXivnCXAk1WyFJn","object":"chat.completion","created":1719297961,
"model":"gpt-3.5-turbo-0125","choices":[{"index":0,"message":{"role":"assistant",
"content":"\"This is a test!\""},
"logprobs":null,"finish_reason":"stop"}],"usage":{"prompt_tokens":13,"completion_tokens":5,"total_tokens":18},"system_fingerprint":"fp_b28b39ffa8"}