Skip to content

Commit

Permalink
✨ feat: add support xAI provider (lobehub#4627)
Browse files Browse the repository at this point in the history
* ✨ feat: add support xAI provider

* 💄 style: update model info

* 🐛 fix: fix CI error

* 👷 build: add docker env

* 💄 style: add desc for xAI
  • Loading branch information
hezhijie0327 authored Nov 11, 2024
1 parent 308d97d commit 49e1e08
Show file tree
Hide file tree
Showing 14 changed files with 345 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ ENV \
UPSTAGE_API_KEY="" UPSTAGE_MODEL_LIST="" \
# Wenxin
WENXIN_ACCESS_KEY="" WENXIN_SECRET_KEY="" WENXIN_MODEL_LIST="" \
# xAI
XAI_API_KEY="" XAI_MODEL_LIST="" \
# 01.AI
ZEROONE_API_KEY="" ZEROONE_MODEL_LIST="" \
# Zhipu
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile.database
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ ENV \
UPSTAGE_API_KEY="" UPSTAGE_MODEL_LIST="" \
# Wenxin
WENXIN_ACCESS_KEY="" WENXIN_SECRET_KEY="" WENXIN_MODEL_LIST="" \
# xAI
XAI_API_KEY="" XAI_MODEL_LIST="" \
# 01.AI
ZEROONE_API_KEY="" ZEROONE_MODEL_LIST="" \
# Zhipu
Expand Down
2 changes: 2 additions & 0 deletions src/app/(main)/settings/llm/ProviderList/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
TaichuProviderCard,
TogetherAIProviderCard,
UpstageProviderCard,
XAIProviderCard,
ZeroOneProviderCard,
ZhiPuProviderCard,
} from '@/config/modelProviders';
Expand Down Expand Up @@ -70,6 +71,7 @@ export const useProviderList = (): ProviderItem[] => {
MistralProviderCard,
Ai21ProviderCard,
UpstageProviderCard,
XAIProviderCard,
QwenProviderCard,
WenxinProvider,
HunyuanProviderCard,
Expand Down
8 changes: 8 additions & 0 deletions src/config/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ export const getLLMConfig = () => {
SENSENOVA_ACCESS_KEY_ID: z.string().optional(),
SENSENOVA_ACCESS_KEY_SECRET: z.string().optional(),
SENSENOVA_MODEL_LIST: z.string().optional(),

ENABLED_XAI: z.boolean(),
XAI_API_KEY: z.string().optional(),
XAI_MODEL_LIST: z.string().optional(),
},
runtimeEnv: {
API_KEY_SELECT_MODE: process.env.API_KEY_SELECT_MODE,
Expand Down Expand Up @@ -304,6 +308,10 @@ export const getLLMConfig = () => {
SENSENOVA_ACCESS_KEY_ID: process.env.SENSENOVA_ACCESS_KEY_ID,
SENSENOVA_ACCESS_KEY_SECRET: process.env.SENSENOVA_ACCESS_KEY_SECRET,
SENSENOVA_MODEL_LIST: process.env.SENSENOVA_MODEL_LIST,

ENABLED_XAI: !!process.env.XAI_API_KEY,
XAI_API_KEY: process.env.XAI_API_KEY,
XAI_MODEL_LIST: process.env.XAI_MODEL_LIST,
},
});
};
Expand Down
4 changes: 4 additions & 0 deletions src/config/modelProviders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import TaichuProvider from './taichu';
import TogetherAIProvider from './togetherai';
import UpstageProvider from './upstage';
import WenxinProvider from './wenxin';
import XAIProvider from './xai';
import ZeroOneProvider from './zeroone';
import ZhiPuProvider from './zhipu';

Expand All @@ -53,6 +54,7 @@ export const LOBE_DEFAULT_MODEL_LIST: ChatModelCard[] = [
PerplexityProvider.chatModels,
AnthropicProvider.chatModels,
HuggingFaceProvider.chatModels,
XAIProvider.chatModels,
ZeroOneProvider.chatModels,
StepfunProvider.chatModels,
NovitaProvider.chatModels,
Expand Down Expand Up @@ -88,6 +90,7 @@ export const DEFAULT_MODEL_PROVIDER_LIST = [
MistralProvider,
Ai21Provider,
UpstageProvider,
XAIProvider,
QwenProvider,
WenxinProvider,
HunyuanProvider,
Expand Down Expand Up @@ -145,5 +148,6 @@ export { default as TaichuProviderCard } from './taichu';
export { default as TogetherAIProviderCard } from './togetherai';
export { default as UpstageProviderCard } from './upstage';
export { default as WenxinProviderCard } from './wenxin';
export { default as XAIProviderCard } from './xai';
export { default as ZeroOneProviderCard } from './zeroone';
export { default as ZhiPuProviderCard } from './zhipu';
29 changes: 29 additions & 0 deletions src/config/modelProviders/xai.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ModelProviderCard } from '@/types/llm';

// ref: https://x.ai/about
const XAI: ModelProviderCard = {
chatModels: [
{
description: '拥有与 Grok 2 相当的性能,但具有更高的效率、速度和功能。',
displayName: 'Grok Beta',
enabled: true,
functionCall: true,
id: 'grok-beta',
pricing: {
input: 5,
output: 15,
},
tokens: 131_072,
},
],
checkModel: 'grok-beta',
description:
'xAI 是一家致力于构建人工智能以加速人类科学发现的公司。我们的使命是推动我们对宇宙的共同理解。',
id: 'xai',
modelList: { showModelFetcher: true },
modelsUrl: 'https://docs.x.ai/docs#models',
name: 'xAI',
url: 'https://console.x.ai',
};

export default XAI;
5 changes: 5 additions & 0 deletions src/const/settings/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
TogetherAIProviderCard,
UpstageProviderCard,
WenxinProviderCard,
XAIProviderCard,
ZeroOneProviderCard,
ZhiPuProviderCard,
filterEnabledModels,
Expand Down Expand Up @@ -161,6 +162,10 @@ export const DEFAULT_LLM_CONFIG: UserModelProviderConfig = {
enabled: false,
enabledModels: filterEnabledModels(WenxinProviderCard),
},
xai: {
enabled: false,
enabledModels: filterEnabledModels(XAIProviderCard),
},
zeroone: {
enabled: false,
enabledModels: filterEnabledModels(ZeroOneProviderCard),
Expand Down
7 changes: 7 additions & 0 deletions src/libs/agent-runtime/AgentRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
TextToSpeechPayload,
} from './types';
import { LobeUpstageAI } from './upstage';
import { LobeXAI } from './xai';
import { LobeZeroOneAI } from './zeroone';
import { LobeZhipuAI } from './zhipu';

Expand Down Expand Up @@ -156,6 +157,7 @@ class AgentRuntime {
taichu: Partial<ClientOptions>;
togetherai: Partial<ClientOptions>;
upstage: Partial<ClientOptions>;
xai: Partial<ClientOptions>;
zeroone: Partial<ClientOptions>;
zhipu: Partial<ClientOptions>;
}>,
Expand Down Expand Up @@ -324,6 +326,11 @@ class AgentRuntime {
break;
}

case ModelProvider.XAI: {
runtimeModel = new LobeXAI(params.xai);
break;
}

case ModelProvider.Cloudflare: {
runtimeModel = new LobeCloudflareAI(params.cloudflare ?? {});
break;
Expand Down
1 change: 1 addition & 0 deletions src/libs/agent-runtime/types/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export enum ModelProvider {
TogetherAI = 'togetherai',
Upstage = 'upstage',
Wenxin = 'wenxin',
XAI = 'xai',
ZeroOne = 'zeroone',
ZhiPu = 'zhipu',
}
Expand Down
Loading

0 comments on commit 49e1e08

Please sign in to comment.