API格式兼容性解决方案
针对不同AI客户端对接需求,可采用以下方法确保兼容性:
- OpenAI格式转换::
- 项目已内置/gemini-pro->/v1/chat/completions的路由映射
- 请求头需包含Authorization: Bearer [API_KEY]
- 模型名称映射:gemini-pro→gpt-3.5,gemini-flash→gpt-4
- 自定义适配方案::
- 修改src/adapter.ts文件扩展支持的模型列表
- 通过URL参数?api_type=openai|azure|gemini切换响应格式
- 使用Postman测试不同格式的请求/响应结构
- 客户端集成示例::
// ChatBox配置示例 baseURL: "https://your.deno.dev/v1" model: "gemini-2.0-pro" apikey: "sk-gemini-xxxx"
caveat:图像类请求需将Base64编码数据放入messages[].content数组中
This answer comes from the articleGemini Playground: Serverless Deployment of a Gemini Multimodal Dialog SiteThe