项目地址:
https://github.com/tech-shrimp/gemini-playground
爬爬虾把上次三个项目整合成一起了,添加了Deno的部署,解决国内使用cloudflare worker 有时候可能出现400: User location is not supported for the API use的问题。
项目简介
Demo: https://play.210718.xyz
只需准备一个Gemini API Key,10秒即可部署一个Gemini多模态对话的网站。
不限地区/网络环境,打开即用。
使用Deno/Cloudflare Worker无服务器免费部署。
对Gemini Chat API 进行了格式转换,中转为更通用的OpenAI格式,国内直连可用。
可对接AI编程,接入ChatBox等AI客户端。
Deno部署(推荐)
- fork本项目
- 登录/注册 https://dash.deno.com/
- 创建项目 Deno Deploy
- 选择此项目,填写项目名字(请仔细填写项目名字,关系到自动分配的域名)
- Entrypoint 填写
src/deno_index.ts
其他字段留空 - 点击 Deploy Project
- 部署成功后获得域名,点开即用。域名同样可以作为Chat API的代理使用。
Cloudflare Worker 部署
- 点击部署按钮
- 登录Cloudflare账号
- 填入Account ID,与API Token
- Fork本项目,开启Github Action功能
- 部署,打开dash.cloudflare.com,查看部署后的worker
- 国内使用需要绑定一个自定义域名
国内使用cloudflare有时候可能出现400: User location is not supported for the API use. 可能是粤港地区Cloudflare路由到了香港的CDN节点代理导致的。建议换成Deno部署。
本地调试
Windows 安装Deno:
irm https://deno.land/install.ps1 | iex
Mac/Linux 安装Deno:
curl -fsSL https://deno.land/install.sh | sh
启动项目:
cd 项目目录
deno run --allow-net --allow-read src/deno_index.ts
使用方法
多模态对话
填入API Key, 点击Connect按钮即可对话。
API 代理
API已经被代理为OpenAI格式,可以直接使用OpenAI格式的API。
注意替换域名与Gemini API Key。
可用模型列表:
curl --location 'http://your.domain.com/v1/models' \
--header 'Authorization: Bearer YOUR-GEMINI-API-KEY'
对话:
curl --location 'https://your.domain.com/v1/chat/completions' \
--header 'Authorization: Bearer YOUR-GEMINI-API-KEY' \
--header 'Content-Type: application/json' \
--data '{
"messages": [
{
"role": "system",
"content": "You are a test assistant."
},
{
"role": "user",
"content": "Testing. Just say hi and nothing else."
}
],
"model": "gemini-2.0-flash-exp"
}'