本地部署 gemini-openai-proxy,使用Google Gemini 实现 Openai API
- 0. 背景
- 1. 申请 Google Gemini API key
- 2. (Optional)Google Gemini 模型说明
- 3. gemini-openai-proxy Github 地址
- 4. 本地部署 gemini-openai-proxy
- 5. 测试
0. 背景
使用 Google Gemini 实现 Openai 的兼容 API,可以节省真正的 Openai API Key 的花销。
1. 申请 Google Gemini API key
访问https://ai.google.dev/ 申请。
2. (Optional)Google Gemini 模型说明
3. gemini-openai-proxy Github 地址
https://github.com/zhu327/gemini-openai-proxy
4. 本地部署 gemini-openai-proxy
docker run --restart=always -it -d -p 8080:8080 --name gemini zhu327/gemini-openai-proxy:latest
5. 测试
curl http://localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $YOUR_GOOGLE_AI_STUDIO_API_KEY" \
-d '{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "Say this is a test!"}],
"temperature": 0.7
}'
示例输出,
{
"id": "chatcmpl-bc77a209753242bf94a5f83cc7b59c98",
"object": "chat.completion",
"created": 1704624098,
"model": "gemini-pro",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "This is a test!"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0
},
"system_fingerprint": ""
}
完结!