Skip to content

Commit

Permalink
✨ feat: Add Spark model provider (lobehub#3098)
Browse files Browse the repository at this point in the history
* ✨ feat: Add Spark model provider

* 🔨 chore: split Spark API Key & Spark Secret

* 💄 style: update Spark icon

* 💄 style: update Spark icon size

* 💄 style: update Spark icon in ProviderAvatar

* 🔨 chore: update Spark models

* 🔨 chore: update Spark models

* 💄 style: fixed Spark 4.0 Ultra model icon display

* 🔨 chore: update Spark models info

* 🔨 chore: update Spark models tokens info

* 🔨 chore: update Spark models info

* 🐛 fix: fixed "'$.header.uid' length must be less or equal than 32" with Spark Lite

* 💄 style: fix model tag icon missing

* 🐛 fix: fix typo in ModelIcon

* 🔨 chore: add unit test for noUserId

* 🔨 chore: disable stream mode

* Revert "🔨 chore: disable stream mode" (lobehub#25)

This reverts commit 302e01d.

* 💄 style: add Spark Pro-128K new model

* ✨ feat: Add Spark ENV

* 🐛 fix: fixed Pro-128k model id, wrong id from official document

![image](https://github.com/user-attachments/assets/7fc3fc73-b460-448c-ad78-4a56d3cae34e)

* 💄style: improve APIKeyForm for Spark

* 💄 style: improve custom Spark API missing form

* 🔨 chore: cleanup code

* 🐛 fix: fix CI issue after merge

* 👷 build: add ENV

* ♻️ refactor: support latest Spark HTTP SDK

* ♻️ refactor: cleanup

* 🔨 chore: fix rebase conflicts

---------

Co-authored-by: Arvin Xu <[email protected]>
  • Loading branch information
hezhijie0327 and arvinxx authored Sep 10, 2024
1 parent 656a1f8 commit fc85c20
Show file tree
Hide file tree
Showing 14 changed files with 368 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ ENV \
QWEN_API_KEY="" QWEN_MODEL_LIST="" \
# SiliconCloud
SILICONCLOUD_API_KEY="" SILICONCLOUD_MODEL_LIST="" SILICONCLOUD_PROXY_URL="" \
# Spark
SPARK_API_KEY="" \
# Stepfun
STEPFUN_API_KEY="" \
# Taichu
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile.database
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ ENV \
QWEN_API_KEY="" QWEN_MODEL_LIST="" \
# SiliconCloud
SILICONCLOUD_API_KEY="" SILICONCLOUD_MODEL_LIST="" SILICONCLOUD_PROXY_URL="" \
# Spark
SPARK_API_KEY="" \
# Stepfun
STEPFUN_API_KEY="" \
# Taichu
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 @@ -15,6 +15,7 @@ import {
PerplexityProviderCard,
QwenProviderCard,
SiliconCloudProviderCard,
SparkProviderCard,
StepfunProviderCard,
TaichuProviderCard,
TogetherAIProviderCard,
Expand Down Expand Up @@ -61,6 +62,7 @@ export const useProviderList = (): ProviderItem[] => {
Ai360ProviderCard,
SiliconCloudProviderCard,
UpstageProviderCard,
SparkProviderCard,
],
[AzureProvider, OllamaProvider, OpenAIProvider, 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 @@ -213,6 +213,13 @@ const getLlmOptionsFromPayload = (provider: string, payload: JWTPayload) => {

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

return { apiKey };
}
case ModelProvider.Spark: {
const { SPARK_API_KEY } = getLLMConfig();

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

return { apiKey };
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/config/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ export const getLLMConfig = () => {

ENABLED_UPSTAGE: z.boolean(),
UPSTAGE_API_KEY: z.string().optional(),

ENABLED_SPARK: z.boolean(),
SPARK_API_KEY: z.string().optional(),
},
runtimeEnv: {
API_KEY_SELECT_MODE: process.env.API_KEY_SELECT_MODE,
Expand Down Expand Up @@ -199,6 +202,9 @@ export const getLLMConfig = () => {

ENABLED_UPSTAGE: !!process.env.UPSTAGE_API_KEY,
UPSTAGE_API_KEY: process.env.UPSTAGE_API_KEY,

ENABLED_SPARK: !!process.env.SPARK_API_KEY,
SPARK_API_KEY: process.env.SPARK_API_KEY,
},
});
};
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 @@ -18,6 +18,7 @@ import OpenRouterProvider from './openrouter';
import PerplexityProvider from './perplexity';
import QwenProvider from './qwen';
import SiliconCloudProvider from './siliconcloud';
import SparkProvider from './spark';
import StepfunProvider from './stepfun';
import TaichuProvider from './taichu';
import TogetherAIProvider from './togetherai';
Expand Down Expand Up @@ -49,6 +50,7 @@ export const LOBE_DEFAULT_MODEL_LIST: ChatModelCard[] = [
Ai360Provider.chatModels,
SiliconCloudProvider.chatModels,
UpstageProvider.chatModels,
SparkProvider.chatModels,
].flat();

export const DEFAULT_MODEL_PROVIDER_LIST = [
Expand Down Expand Up @@ -76,6 +78,7 @@ export const DEFAULT_MODEL_PROVIDER_LIST = [
Ai360Provider,
SiliconCloudProvider,
UpstageProvider,
SparkProvider,
];

export const filterEnabledModels = (provider: ModelProviderCard) => {
Expand Down Expand Up @@ -105,6 +108,7 @@ export { default as OpenRouterProviderCard } from './openrouter';
export { default as PerplexityProviderCard } from './perplexity';
export { default as QwenProviderCard } from './qwen';
export { default as SiliconCloudProviderCard } from './siliconcloud';
export { default as SparkProviderCard } from './spark';
export { default as StepfunProviderCard } from './stepfun';
export { default as TaichuProviderCard } from './taichu';
export { default as TogetherAIProviderCard } from './togetherai';
Expand Down
59 changes: 59 additions & 0 deletions src/config/modelProviders/spark.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { ModelProviderCard } from '@/types/llm';

// ref https://www.xfyun.cn/doc/spark/HTTP%E8%B0%83%E7%94%A8%E6%96%87%E6%A1%A3.html#_3-%E8%AF%B7%E6%B1%82%E8%AF%B4%E6%98%8E
// ref https://www.xfyun.cn/doc/spark/Web.html#_1-%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E
const Spark: ModelProviderCard = {
chatModels: [
{
description: '轻量级大语言模型,低延迟,全免费 支持在线联网搜索功能 响应快速、便捷,全面免费开放 适用于低算力推理与模型精调等定制化场景',
displayName: 'Spark Lite',
enabled: true,
functionCall: false,
id: 'general',
maxOutput: 4096,
tokens: 8192,
},
{
description: '专业级大语言模型,兼顾模型效果与性能 数学、代码、医疗、教育等场景专项优化 支持联网搜索、天气、日期等多个内置插件 覆盖大部分知识问答、语言理解、文本创作等多个场景',
displayName: 'Spark Pro',
enabled: true,
functionCall: false,
id: 'generalv3',
maxOutput: 8192,
tokens: 8192,
},
{
description: '支持最长上下文的星火大模型,长文无忧 128K星火大模型强势来袭 通读全文,旁征博引 沟通无界,逻辑连贯',
displayName: 'Spark Pro-128K',
enabled: true,
functionCall: false,
id: 'Pro-128k',
maxOutput: 4096,
tokens: 128_000,
},
{
description: '最全面的星火大模型版本,功能丰富 支持联网搜索、天气、日期等多个内置插件 核心能力全面升级,各场景应用效果普遍提升 支持System角色人设与FunctionCall函数调用',
displayName: 'Spark3.5 Max',
enabled: true,
functionCall: false,
id: 'generalv3.5',
maxOutput: 8192,
tokens: 8192,
},
{
description: '最强大的星火大模型版本,效果极佳 全方位提升效果,引领智能巅峰 优化联网搜索链路,提供精准回答 强化文本总结能力,提升办公生产力',
displayName: 'Spark4.0 Ultra',
enabled: true,
functionCall: false,
id: '4.0Ultra',
maxOutput: 8192,
tokens: 8192,
},
],
checkModel: 'generalv3',
id: 'spark',
modelList: { showModelFetcher: true },
name: 'Spark',
};

export default Spark;
5 changes: 5 additions & 0 deletions src/const/settings/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
PerplexityProviderCard,
QwenProviderCard,
SiliconCloudProviderCard,
SparkProviderCard,
StepfunProviderCard,
TaichuProviderCard,
TogetherAIProviderCard,
Expand Down Expand Up @@ -100,6 +101,10 @@ export const DEFAULT_LLM_CONFIG: UserModelProviderConfig = {
enabled: false,
enabledModels: filterEnabledModels(SiliconCloudProviderCard),
},
spark: {
enabled: false,
enabledModels: filterEnabledModels(SparkProviderCard),
},
stepfun: {
enabled: false,
enabledModels: filterEnabledModels(StepfunProviderCard),
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 @@ -21,6 +21,7 @@ import { LobeOpenRouterAI } from './openrouter';
import { LobePerplexityAI } from './perplexity';
import { LobeQwenAI } from './qwen';
import { LobeSiliconCloudAI } from './siliconcloud';
import { LobeSparkAI } from './spark';
import { LobeStepfunAI } from './stepfun';
import { LobeTaichuAI } from './taichu';
import { LobeTogetherAI } from './togetherai';
Expand Down Expand Up @@ -132,6 +133,7 @@ class AgentRuntime {
perplexity: Partial<ClientOptions>;
qwen: Partial<ClientOptions>;
siliconcloud: Partial<ClientOptions>;
spark: Partial<ClientOptions>;
stepfun: Partial<ClientOptions>;
taichu: Partial<ClientOptions>;
togetherai: Partial<ClientOptions>;
Expand Down Expand Up @@ -268,6 +270,11 @@ class AgentRuntime {
runtimeModel = new LobeUpstageAI(params.upstage);
break
}

case ModelProvider.Spark: {
runtimeModel = new LobeSparkAI(params.spark);
break
}
}

return new AgentRuntime(runtimeModel);
Expand Down
Loading

0 comments on commit fc85c20

Please sign in to comment.