Skip to content

Commit 286cd82

Browse files
committed
feat: 添加XAi支持及相关配置
Signed-off-by: tbxark <[email protected]>
1 parent 07b498d commit 286cd82

File tree

6 files changed

+52
-4
lines changed

6 files changed

+52
-4
lines changed

doc/cn/CONFIG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,17 @@ OPENAI_API_BASE,GOOGLE_COMPLETIONS_API,MISTRAL_API_BASE,COHERE_API_BASE,ANTHROPI
195195
| DEEPSEEK_API_KEY | DeepSeek API Key | `null` |
196196
| DEEPSEEK_API_BASE | DeepSeek API Base | `https://api.deepseek.com` |
197197
| DEEPSEEK_CHAT_MODEL | DeepSeek API Model | `deepseek-chat` |
198-
| DEEPSEEK_CHAT_MODELS_LIST | DeepSeek | `''` |
198+
| DEEPSEEK_CHAT_MODELS_LIST | DeepSeek 聊天模型列表 | `''` |
199+
200+
### XAi
201+
202+
| KEY | 名称 | 默认值 |
203+
|----------------------|---------------|--------------------|
204+
| XAI_API_KEY | XAi API Key | `null` |
205+
| XAI_API_BASE | XAi API Base | `https://api.x.ai` |
206+
| XAI_CHAT_MODEL | XAi API Model | `grok-2-latest` |
207+
| XAI_CHAT_MODELS_LIST | XAi 聊天模型列表 | `''` |
208+
199209

200210
## 支持命令
201211

doc/en/CONFIG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,16 @@ All `xxx_MODELS_LIST` can be a URL or a JSON array string. When it is empty, it
197197
| DEEPSEEK_CHAT_MODEL | DeepSeek API Model | `deepseek-chat` |
198198
| DEEPSEEK_CHAT_MODELS_LIST | List of DeepSeek Chat Models | `''` |
199199

200+
### XAi
201+
202+
| KEY | Name | Default |
203+
|----------------------|---------------------|--------------------|
204+
| XAI_API_KEY | XAi API Key | `null` |
205+
| XAI_API_BASE | XAi API Base | `https://api.x.ai` |
206+
| XAI_CHAT_MODEL | XAi API Model | `grok-2-latest` |
207+
| XAI_CHAT_MODELS_LIST | XAi Chat Model List | `''` |
208+
209+
200210
## Command
201211

202212
| Command | Description | Example |

packages/lib/core/src/agent/agent.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { AgentUserConfig } from '#/config';
22
import type { ChatAgent, ImageAgent } from './types';
3-
import { DeepSeek, Groq, Mistral } from '#/agent/openai_agents';
3+
import { DeepSeek, Groq, Mistral, XAi } from '#/agent/openai_agents';
44
import { Anthropic } from './anthropic';
55
import { AzureChatAI, AzureImageAI } from './azure';
66
import { Cohere } from './cohere';
@@ -18,6 +18,7 @@ export const CHAT_AGENTS: ChatAgent[] = [
1818
new Mistral(),
1919
new DeepSeek(),
2020
new Groq(),
21+
new XAi(),
2122
];
2223

2324
export function loadChatLLM(context: AgentUserConfig): ChatAgent | null {

packages/lib/core/src/agent/openai_agents.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,15 @@ export class Mistral extends OpenAICompatibilityAgent {
3535
});
3636
}
3737
}
38+
39+
export class XAi extends OpenAICompatibilityAgent {
40+
constructor() {
41+
super('xai', {
42+
base: 'XAI_API_BASE',
43+
key: 'XAI_API_KEY',
44+
model: 'XAI_CHAT_MODEL',
45+
modelsList: 'XAI_CHAT_MODELS_LIST',
46+
extraParams: 'XAI_CHAT_EXTRA_PARAMS',
47+
});
48+
}
49+
}

packages/lib/core/src/config/config.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,20 @@ export class GroqConfig {
158158
GROQ_CHAT_EXTRA_PARAMS: Record<string, any> = {};
159159
}
160160

161-
type UserConfig = AgentShareConfig & OpenAIConfig & DallEConfig & AzureConfig & WorkersConfig & GeminiConfig & MistralConfig & CohereConfig & AnthropicConfig & DeepSeekConfig & GroqConfig;
161+
export class XAIConfig {
162+
// XAI api key
163+
XAI_API_KEY: string | null = null;
164+
// XAI api base
165+
XAI_API_BASE = 'https://api.x.ai/v1';
166+
// XAI api model
167+
XAI_CHAT_MODEL = 'grok-2-latest';
168+
// XAI api chat models list
169+
XAI_CHAT_MODELS_LIST = '';
170+
// XAI Chat API Extra Params
171+
XAI_CHAT_EXTRA_PARAMS: Record<string, any> = {};
172+
}
173+
174+
type UserConfig = AgentShareConfig & OpenAIConfig & DallEConfig & AzureConfig & WorkersConfig & GeminiConfig & MistralConfig & CohereConfig & AnthropicConfig & DeepSeekConfig & GroqConfig & XAIConfig;
162175
export type AgentUserConfigKey = keyof UserConfig;
163176

164177
export class DefineKeys {

packages/lib/core/src/config/env.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { APIGuardBinding, KVNamespaceBinding, WorkerAIBinding } from './binding';
22
import type { AgentUserConfig, AgentUserConfigKey } from './config';
33
import loadI18n from '../i18n';
4-
import { AgentShareConfig, AnthropicConfig, AzureConfig, CohereConfig, DallEConfig, DeepSeekConfig, DefineKeys, EnvironmentConfig, GeminiConfig, GroqConfig, MistralConfig, OpenAIConfig, WorkersConfig } from './config';
4+
import { AgentShareConfig, AnthropicConfig, AzureConfig, CohereConfig, DallEConfig, DeepSeekConfig, DefineKeys, EnvironmentConfig, GeminiConfig, GroqConfig, MistralConfig, OpenAIConfig, WorkersConfig, XAIConfig } from './config';
55
import { ConfigMerger } from './merger';
66
import { BUILD_TIMESTAMP, BUILD_VERSION } from './version';
77

@@ -26,6 +26,7 @@ function createAgentUserConfig(): AgentUserConfig {
2626
new AnthropicConfig(),
2727
new DeepSeekConfig(),
2828
new GroqConfig(),
29+
new XAIConfig(),
2930
);
3031
}
3132

@@ -200,6 +201,7 @@ class Environment extends EnvironmentConfig {
200201
'ANTHROPIC_API_BASE',
201202
'DEEPSEEK_API_BASE',
202203
'GROQ_API_BASE',
204+
'XAI_API_BASE',
203205
];
204206
for (const key of keys) {
205207
const base = this.USER_CONFIG[key];

0 commit comments

Comments
 (0)