feat(provider): add support for Grok provider in AI proxy (#2713)

Co-authored-by: 韩贤涛 <601803023@qq.com>
This commit is contained in:
aias00
2025-08-07 17:22:47 +08:00
committed by GitHub
parent b69e3a8f30
commit a1bf1ff009
6 changed files with 354 additions and 39 deletions

View File

@@ -158,6 +158,10 @@ DeepSeek 所对应的 `type` 为 `deepseek`。它并无特有的配置字段。
Groq 所对应的 `type``groq`。它并无特有的配置字段。
#### Grok
Grok 所对应的 `type``grok`。它并无特有的配置字段。
#### 文心一言Baidu
文心一言所对应的 `type``baidu`。它并无特有的配置字段。
@@ -863,6 +867,76 @@ provider:
}
```
### 使用 OpenAI 协议代理 Grok 服务
**配置信息**
```yaml
provider:
type: grok
apiTokens:
- 'YOUR_GROK_API_TOKEN'
```
**请求示例**
```json
{
"messages": [
{
"role": "system",
"content": "You are a helpful assistant that can answer questions and help with tasks."
},
{
"role": "user",
"content": "What is 101*3?"
}
],
"model": "grok-4"
}
```
**响应示例**
```json
{
"id": "a3d1008e-4544-40d4-d075-11527e794e4a",
"object": "chat.completion",
"created": 1752854522,
"model": "grok-4",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "101 multiplied by 3 is 303.",
"refusal": null
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 32,
"completion_tokens": 9,
"total_tokens": 135,
"prompt_tokens_details": {
"text_tokens": 32,
"audio_tokens": 0,
"image_tokens": 0,
"cached_tokens": 6
},
"completion_tokens_details": {
"reasoning_tokens": 94,
"audio_tokens": 0,
"accepted_prediction_tokens": 0,
"rejected_prediction_tokens": 0
},
"num_sources_used": 0
},
"system_fingerprint": "fp_3a7881249c"
}
```
### 使用 OpenAI 协议代理 Claude 服务
**配置信息**