Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat: Add 360AI model provider #3130

Merged
merged 11 commits into from
Jul 12, 2024
7 changes: 7 additions & 0 deletions src/app/(main)/settings/llm/ProviderList/providers.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
Ai360,
AiMass,
Anthropic,
Baichuan,
Expand All @@ -25,6 +26,7 @@ import { Flexbox } from 'react-layout-kit';
import urlJoin from 'url-join';

import {
Ai360ProviderCard,
AnthropicProviderCard,
BaichuanProviderCard,
DeepSeekProviderCard,
Expand Down Expand Up @@ -184,6 +186,11 @@ export const useProviderList = (): ProviderItem[] => {
docUrl: urlJoin(BASE_DOC_URL, 'taichu'),
title: <AiMass.Combine size={ 28 } type={ 'color' } />,
},
{
...Ai360ProviderCard,
docUrl: urlJoin(BASE_DOC_URL, 'ai360'),
title: <Ai360.Combine size={ 20 } type={ 'color' } />,
},
],
[azureProvider, ollamaProvider, ollamaProvider, bedrockProvider],
);
Expand Down
7 changes: 7 additions & 0 deletions src/app/api/chat/agentRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ const getLlmOptionsFromPayload = (provider: string, payload: JWTPayload) => {

const apiKey = apiKeyManager.pick(payload?.apiKey || TAICHU_API_KEY);

return { apiKey };
}
case ModelProvider.Ai360: {
const { AI360_API_KEY } = getLLMConfig();

const apiKey = apiKeyManager.pick(payload?.apiKey || AI360_API_KEY);

return { apiKey };
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/components/ModelIcon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
AiMass,
Adobe,
Ai21,
Ai360,
Aws,
Azure,
Baichuan,
Expand Down Expand Up @@ -68,6 +69,7 @@ const ModelIcon = memo<ModelProviderIconProps>(({ model: originModel, size = 12
if (model.includes('dbrx')) return <Dbrx.Avatar size={size} />;
if (model.includes('step')) return <Stepfun.Avatar size={size} />;
if (model.includes('taichu')) return <AiMass.Avatar size={size} />;
if (model.includes('360gpt')) return <Ai360.Avatar size={size} />;

// below: To be supported in providers, move up if supported
if (model.includes('baichuan'))
Expand Down
5 changes: 5 additions & 0 deletions src/components/ModelProviderIcon/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
Ai360,
AiMass,
Anthropic,
Azure,
Expand Down Expand Up @@ -124,6 +125,10 @@ const ModelProviderIcon = memo<ModelProviderIconProps>(({ provider }) => {
return <AiMass size={20} />;
}

case ModelProvider.Ai360: {
return <Ai360 size={20} />;
}

default: {
return null;
}
Expand Down
2 changes: 2 additions & 0 deletions src/components/ModelTag/ModelIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
AdobeFirefly,
Ai21,
Ai360,
AiMass,
Aws,
Azure,
Expand Down Expand Up @@ -63,6 +64,7 @@ const ModelIcon = memo<ModelIconProps>(({ model, size = 12 }) => {
if (model.includes('command')) return <Cohere size={size} />;
if (model.includes('dbrx')) return <Dbrx size={size} />;
if (model.includes('taichu')) return <AiMass size={size} />;
if (model.includes('360gpt')) return <Ai360 size={size} />;

// below: To be supported in providers, move up if supported
if (model.includes('baichuan')) return <Baichuan size={size} />;
Expand Down
6 changes: 6 additions & 0 deletions src/config/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ export const getLLMConfig = () => {

ENABLED_TAICHU: z.boolean(),
TAICHU_API_KEY: z.string().optional(),

ENABLED_AI360: z.boolean(),
AI360_API_KEY: z.string().optional(),
},
runtimeEnv: {
API_KEY_SELECT_MODE: process.env.API_KEY_SELECT_MODE,
Expand Down Expand Up @@ -167,6 +170,9 @@ export const getLLMConfig = () => {

ENABLED_TAICHU: !!process.env.TAICHU_API_KEY,
TAICHU_API_KEY: process.env.TAICHU_API_KEY,

ENABLED_AI360: !!process.env.AI360_API_KEY,
AI360_API_KEY: process.env.AI360_API_KEY,
},
});
};
Expand Down
38 changes: 38 additions & 0 deletions src/config/modelProviders/ai360.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { ModelProviderCard } from '@/types/llm';

// ref https://ai.360.cn/platform/docs/overview
const Ai360: ModelProviderCard = {
chatModels: [
{
displayName: '360GPT Pro',
enabled: true,
functionCall: false,
id: '360gpt-pro',
maxOutput: 7000,
tokens: 8192,
},
{
displayName: '360GPT Turbo',
enabled: true,
functionCall: false,
id: '360gpt-turbo',
maxOutput: 8192,
tokens: 8192,
},
{
displayName: '360GPT Turbo Responsibility 8K',
enabled: true,
functionCall: false,
id: '360gpt-turbo-responsibility-8k',
maxOutput: 2048,
tokens: 8192,
},
],
checkModel: '360gpt-turbo',
disableBrowserRequest: true,
id: 'ai360',
modelList: { showModelFetcher: true },
name: '360智脑',
};

export default Ai360;
4 changes: 4 additions & 0 deletions src/config/modelProviders/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ChatModelCard, ModelProviderCard } from '@/types/llm';

import Ai360Provider from './ai360';
import AnthropicProvider from './anthropic';
import AzureProvider from './azure';
import BaichuanProvider from './baichuan';
Expand Down Expand Up @@ -41,6 +42,7 @@ export const LOBE_DEFAULT_MODEL_LIST: ChatModelCard[] = [
StepfunProvider.chatModels,
BaichuanProvider.chatModels,
TaichuProvider.chatModels,
Ai360Provider.chatModels,
].flat();

export const DEFAULT_MODEL_PROVIDER_LIST = [
Expand All @@ -64,6 +66,7 @@ export const DEFAULT_MODEL_PROVIDER_LIST = [
StepfunProvider,
BaichuanProvider,
TaichuProvider,
Ai360Provider,
];

export const filterEnabledModels = (provider: ModelProviderCard) => {
Expand All @@ -75,6 +78,7 @@ export const isProviderDisableBroswerRequest = (id: string) => {
return !!provider;
};

export { default as Ai360ProviderCard } from './ai360';
export { default as AnthropicProviderCard } from './anthropic';
export { default as AzureProviderCard } from './azure';
export { default as BaichuanProviderCard } from './baichuan';
Expand Down
5 changes: 5 additions & 0 deletions src/const/settings/llm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
Ai360ProviderCard,
AnthropicProviderCard,
BaichuanProviderCard,
BedrockProviderCard,
Expand All @@ -24,6 +25,10 @@ import { ModelProvider } from '@/libs/agent-runtime';
import { UserModelProviderConfig } from '@/types/user/settings';

export const DEFAULT_LLM_CONFIG: UserModelProviderConfig = {
ai360: {
enabled: false,
enabledModels: filterEnabledModels(Ai360ProviderCard),
},
anthropic: {
enabled: false,
enabledModels: filterEnabledModels(AnthropicProviderCard),
Expand Down
5 changes: 5 additions & 0 deletions src/features/Conversation/Error/APIKeyForm/ProviderAvatar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
Ai360,
AiMass,
Anthropic,
Baichuan,
Expand Down Expand Up @@ -94,6 +95,10 @@ const ProviderAvatar = memo<ProviderAvatarProps>(({ provider }) => {
return <ZeroOne color={ZeroOne.colorPrimary} size={56} />;
}

case ModelProvider.Ai360: {
return <Ai360 color={Ai360.colorPrimary} size={56} />;
}

default:
case ModelProvider.OpenAI: {
return <OpenAI color={theme.colorText} size={64} />;
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 @@ -3,6 +3,7 @@ import { ClientOptions } from 'openai';
import type { TracePayload } from '@/const/trace';

import { LobeRuntimeAI } from './BaseAI';
import { LobeAi360AI } from './ai360';
import { LobeAnthropicAI } from './anthropic';
import { LobeAzureOpenAI } from './azureOpenai';
import { LobeBaichuanAI } from './baichuan';
Expand Down Expand Up @@ -103,6 +104,7 @@ class AgentRuntime {
static async initializeWithProviderOptions(
provider: string,
params: Partial<{
ai360: Partial<ClientOptions>;
anthropic: Partial<ClientOptions>;
azure: { apiVersion?: string; apikey?: string; endpoint?: string };
baichuan: Partial<ClientOptions>;
Expand Down Expand Up @@ -233,6 +235,11 @@ class AgentRuntime {
runtimeModel = new LobeTaichuAI(params.taichu);
break;
}

case ModelProvider.Ai360: {
runtimeModel = new LobeAi360AI(params.ai360 ?? {});
break
}
}

return new AgentRuntime(runtimeModel);
Expand Down
Loading
Loading