feat(ai-proxy): add OpenRouter provider support (#2823)

This commit is contained in:
澄潭
2025-08-28 19:26:21 +08:00
committed by GitHub
parent b2ffeff7b8
commit 44c33617fa
11 changed files with 5684 additions and 184 deletions

View File

@@ -173,6 +173,10 @@ Groq 所对应的 `type` 为 `groq`。它并无特有的配置字段。
Grok 所对应的 `type``grok`。它并无特有的配置字段。
#### OpenRouter
OpenRouter 所对应的 `type``openrouter`。它并无特有的配置字段。
#### 文心一言Baidu
文心一言所对应的 `type``baidu`。它并无特有的配置字段。
@@ -948,6 +952,63 @@ provider:
}
```
### 使用 OpenAI 协议代理 OpenRouter 服务
**配置信息**
```yaml
provider:
type: openrouter
apiTokens:
- 'YOUR_OPENROUTER_API_TOKEN'
modelMapping:
'gpt-4': 'openai/gpt-4-turbo-preview'
'gpt-3.5-turbo': 'openai/gpt-3.5-turbo'
'claude-3': 'anthropic/claude-3-opus'
'*': 'openai/gpt-3.5-turbo'
```
**请求示例**
```json
{
"model": "gpt-4",
"messages": [
{
"role": "user",
"content": "你好,你是谁?"
}
],
"temperature": 0.7
}
```
**响应示例**
```json
{
"id": "gen-1234567890abcdef",
"object": "chat.completion",
"created": 1699123456,
"model": "openai/gpt-4-turbo-preview",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "你好我是一个AI助手通过OpenRouter平台提供服务。我可以帮助回答问题、协助创作、进行对话等。有什么我可以帮助你的吗"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 46,
"total_tokens": 58
}
}
```
### 使用自动协议兼容功能
插件现在支持自动协议检测,可以同时处理 OpenAI 和 Claude 两种协议格式的请求。