本项目已成功集成了 OpenRouter API,支持多个免费的大语言模型。OpenRouter 是一个统一的 API 接口,可以访问多个不同的 AI 模型提供商。
以下模型已添加到 OpenRouter 配置中:
- deepseek/deepseek-r1-0528:free - DeepSeek R1 模型(免费版)
- deepseek/deepseek-chat-v3-0324:free - DeepSeek Chat V3 模型(免费版)
- openai/gpt-oss-20b:free - OpenAI GPT-OSS 20B 模型(免费版)
- z-ai/glm-4.5-air:free - GLM-4.5 Air 模型(免费版)
- moonshotai/kimi-k2:free - Kimi K2 模型(免费版)
- qwen/qwen3-235b-a22b:free - Qwen3 235B 模型(免费版)
- meta-llama/llama-3.3-70b-instruct:free - Llama 3.3 70B 模型(免费版)
- 访问 OpenRouter 官网
- 注册账户并登录
- 在 API Keys 页面创建新的 API 密钥
- 复制生成的 API 密钥
- 启动游戏
- 按 ESC 键打开设置界面
- 在 API 设置选项卡中:
- 选择 "OpenRouter (免费模型)" 作为 API 类型
- 选择你想要的免费模型
- 输入你的 OpenRouter API 密钥
- 点击保存
每个角色都可以有独立的 AI 设置:
- 在角色设置中选择 "OpenRouter (免费模型)"
- 为角色选择特定的模型
- 输入 API 密钥(如果与全局设置不同)
script/ai/APIConfig.gd: 添加了 OpenRouter 配置- 在 API 类型枚举中添加了
OPENROUTER - 添加了 OpenRouter 提供商配置,包括所有免费模型
# OpenRouter配置
_providers["OpenRouter"] = APIProvider.new(
"OpenRouter",
"OpenRouter (免费模型)",
"https://openrouter.ai/api/v1/chat/completions",
[
"deepseek/deepseek-r1-0528:free",
"deepseek/deepseek-chat-v3-0324:free",
"openai/gpt-oss-20b:free",
"z-ai/glm-4.5-air:free",
"moonshotai/kimi-k2:free",
"qwen/qwen3-235b-a22b:free",
"meta-llama/llama-3.3-70b-instruct:free"
],
true, # 需要API密钥
{
"Content-Type": "application/json",
"Authorization": "Bearer {api_key}",
"HTTP-Referer": "https://github.com/your-repo",
"X-Title": "Microverse Game"
},
"openai", # 使用OpenAI格式的请求
"openai" # 使用OpenAI格式的响应解析
)OpenRouter 使用与 OpenAI 兼容的 API 格式:
{
"model": "deepseek/deepseek-r1-0528:free",
"messages": [
{
"role": "user",
"content": "你的提示内容"
}
]
}OpenRouter 返回标准的 OpenAI 格式响应:
{
"choices": [
{
"message": {
"content": "AI的回复内容"
}
}
]
}- API 密钥安全: 请妥善保管你的 OpenRouter API 密钥,不要分享给他人
- 使用限制: 免费模型可能有使用频率和数量限制
- 模型可用性: 免费模型的可用性可能会变化,建议定期检查
- 网络连接: 需要稳定的网络连接来访问 OpenRouter API
- API 密钥无效: 检查密钥是否正确复制,确保没有多余的空格
- 模型不可用: 尝试选择其他免费模型
- 网络错误: 检查网络连接,确保可以访问 openrouter.ai
- 请求超时: 某些模型可能需要更长的响应时间
游戏会在控制台输出详细的调试信息,包括:
- API 请求 URL
- 请求头信息
- 请求数据
- 响应状态
- v1.0: 初始 OpenRouter 集成
- 添加了 7 个免费模型支持
- 实现了完整的 API 配置
- 支持角色独立 AI 设置