@lobehub/chat 1.90.2 → 1.90.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cursor/rules/backend-architecture.mdc +12 -9
- package/.cursor/rules/cursor-ux-optimize.mdc +1 -1
- package/.cursor/rules/define-database-model.mdc +1 -1
- package/.cursor/rules/drizzle-schema-style-guide.mdc +1 -1
- package/.cursor/rules/i18n/i18n.mdc +1 -1
- package/.cursor/rules/project-introduce.mdc +2 -1
- package/.cursor/rules/system-role.mdc +42 -0
- package/.cursor/rules/zustand-action-patterns.mdc +318 -0
- package/.cursor/rules/zustand-slice-organization.mdc +300 -0
- package/CHANGELOG.md +58 -0
- package/README.md +2 -2
- package/README.zh-CN.md +2 -2
- package/changelog/v1.json +21 -0
- package/docs/self-hosting/advanced/model-list.mdx +1 -1
- package/docs/self-hosting/advanced/model-list.zh-CN.mdx +1 -1
- package/docs/self-hosting/environment-variables/model-provider.mdx +2 -2
- package/docs/self-hosting/environment-variables/model-provider.zh-CN.mdx +2 -2
- package/package.json +44 -44
- package/src/config/aiModels/qwen.ts +64 -42
- package/src/config/modelProviders/qwen.ts +2 -5
- package/src/config/modelProviders/xai.ts +1 -1
- package/src/features/PluginsUI/Render/utils/iframeOnReady.test.ts +1 -1
- package/src/features/PluginsUI/Render/utils/pluginSettings.test.ts +1 -1
- package/src/features/PluginsUI/Render/utils/pluginState.test.ts +1 -1
- package/src/libs/model-runtime/BaseAI.ts +3 -3
- package/src/libs/model-runtime/ModelRuntime.ts +2 -2
- package/src/libs/model-runtime/UniformRuntime/index.ts +2 -2
- package/src/libs/model-runtime/ai21/index.ts +2 -2
- package/src/libs/model-runtime/ai360/index.ts +2 -2
- package/src/libs/model-runtime/anthropic/index.ts +15 -11
- package/src/libs/model-runtime/azureOpenai/index.ts +2 -2
- package/src/libs/model-runtime/azureai/index.ts +4 -4
- package/src/libs/model-runtime/baichuan/index.ts +2 -2
- package/src/libs/model-runtime/bedrock/index.ts +4 -4
- package/src/libs/model-runtime/cloudflare/index.ts +2 -2
- package/src/libs/model-runtime/cohere/index.ts +2 -2
- package/src/libs/model-runtime/deepseek/index.ts +2 -2
- package/src/libs/model-runtime/fireworksai/index.ts +2 -2
- package/src/libs/model-runtime/giteeai/index.ts +2 -2
- package/src/libs/model-runtime/github/index.ts +2 -2
- package/src/libs/model-runtime/google/index.ts +7 -5
- package/src/libs/model-runtime/groq/index.ts +2 -2
- package/src/libs/model-runtime/higress/index.ts +2 -2
- package/src/libs/model-runtime/huggingface/index.ts +2 -2
- package/src/libs/model-runtime/hunyuan/index.ts +2 -2
- package/src/libs/model-runtime/index.ts +1 -1
- package/src/libs/model-runtime/infiniai/index.ts +2 -2
- package/src/libs/model-runtime/internlm/index.ts +7 -9
- package/src/libs/model-runtime/jina/index.ts +2 -2
- package/src/libs/model-runtime/lmstudio/index.ts +2 -2
- package/src/libs/model-runtime/minimax/index.ts +2 -2
- package/src/libs/model-runtime/mistral/index.ts +2 -2
- package/src/libs/model-runtime/modelscope/index.ts +2 -3
- package/src/libs/model-runtime/moonshot/index.ts +2 -2
- package/src/libs/model-runtime/novita/index.ts +2 -2
- package/src/libs/model-runtime/nvidia/index.ts +2 -2
- package/src/libs/model-runtime/ollama/index.ts +2 -2
- package/src/libs/model-runtime/openai/index.ts +3 -3
- package/src/libs/model-runtime/openrouter/index.ts +2 -2
- package/src/libs/model-runtime/perplexity/index.ts +2 -2
- package/src/libs/model-runtime/ppio/index.ts +2 -2
- package/src/libs/model-runtime/qiniu/index.ts +2 -2
- package/src/libs/model-runtime/qwen/index.ts +2 -2
- package/src/libs/model-runtime/sambanova/index.ts +2 -2
- package/src/libs/model-runtime/search1api/index.ts +2 -2
- package/src/libs/model-runtime/sensenova/index.ts +2 -2
- package/src/libs/model-runtime/siliconcloud/index.ts +2 -2
- package/src/libs/model-runtime/spark/index.ts +15 -13
- package/src/libs/model-runtime/stepfun/index.ts +2 -2
- package/src/libs/model-runtime/taichu/index.ts +2 -2
- package/src/libs/model-runtime/tencentcloud/index.ts +2 -2
- package/src/libs/model-runtime/togetherai/index.ts +2 -2
- package/src/libs/model-runtime/types/chat.ts +1 -1
- package/src/libs/model-runtime/upstage/index.ts +2 -2
- package/src/libs/model-runtime/utils/openaiCompatibleFactory/index.test.ts +7 -7
- package/src/libs/model-runtime/utils/openaiCompatibleFactory/index.ts +3 -3
- package/src/libs/model-runtime/vllm/index.ts +2 -2
- package/src/libs/model-runtime/volcengine/index.ts +2 -2
- package/src/libs/model-runtime/wenxin/index.ts +2 -2
- package/src/libs/model-runtime/xai/index.ts +6 -3
- package/src/libs/model-runtime/xinference/index.ts +2 -2
- package/src/libs/model-runtime/zeroone/index.ts +2 -2
- package/src/libs/model-runtime/zhipu/index.ts +2 -2
- package/src/middleware.ts +3 -1
- package/src/server/globalConfig/index.ts +3 -0
- package/src/server/routers/tools/search.test.ts +2 -4
- package/src/services/chat.ts +1 -0
- package/src/store/chat/slices/aiChat/actions/__tests__/generateAIChat.test.ts +4 -2
- package/src/store/chat/slices/message/action.test.ts +2 -1
- package/src/store/chat/slices/topic/action.test.ts +3 -2
- package/src/types/aiProvider.ts +1 -0
@@ -5,8 +5,8 @@ import type { ChatModelCard } from '@/types/llm';
|
|
5
5
|
import { LobeRuntimeAI } from '../BaseAI';
|
6
6
|
import { AgentRuntimeErrorType } from '../error';
|
7
7
|
import {
|
8
|
-
ChatCompetitionOptions,
|
9
8
|
type ChatCompletionErrorPayload,
|
9
|
+
ChatMethodOptions,
|
10
10
|
ChatStreamPayload,
|
11
11
|
ModelProvider,
|
12
12
|
} from '../types';
|
@@ -52,15 +52,15 @@ export class LobeAnthropicAI implements LobeRuntimeAI {
|
|
52
52
|
this.client = new Anthropic({
|
53
53
|
apiKey,
|
54
54
|
baseURL,
|
55
|
-
...(betaHeaders ? { defaultHeaders: {
|
56
|
-
...res
|
55
|
+
...(betaHeaders ? { defaultHeaders: { 'anthropic-beta': betaHeaders } } : {}),
|
56
|
+
...res,
|
57
57
|
});
|
58
58
|
this.baseURL = this.client.baseURL;
|
59
59
|
this.apiKey = apiKey;
|
60
60
|
this.id = id || ModelProvider.Anthropic;
|
61
61
|
}
|
62
62
|
|
63
|
-
async chat(payload: ChatStreamPayload, options?:
|
63
|
+
async chat(payload: ChatStreamPayload, options?: ChatMethodOptions) {
|
64
64
|
try {
|
65
65
|
const anthropicPayload = await this.buildAnthropicPayload(payload);
|
66
66
|
const inputStartAt = Date.now();
|
@@ -112,7 +112,7 @@ export class LobeAnthropicAI implements LobeRuntimeAI {
|
|
112
112
|
} = payload;
|
113
113
|
|
114
114
|
const { default: anthropicModels } = await import('@/config/aiModels/anthropic');
|
115
|
-
const modelConfig = anthropicModels.find(m => m.id === model);
|
115
|
+
const modelConfig = anthropicModels.find((m) => m.id === model);
|
116
116
|
const defaultMaxOutput = modelConfig?.maxOutput;
|
117
117
|
|
118
118
|
// 配置优先级:用户设置 > 模型配置 > 硬编码默认值
|
@@ -137,7 +137,9 @@ export class LobeAnthropicAI implements LobeRuntimeAI {
|
|
137
137
|
|
138
138
|
const postMessages = await buildAnthropicMessages(user_messages, { enabledContextCaching });
|
139
139
|
|
140
|
-
let postTools: anthropicTools[] | undefined = buildAnthropicTools(tools, {
|
140
|
+
let postTools: anthropicTools[] | undefined = buildAnthropicTools(tools, {
|
141
|
+
enabledContextCaching,
|
142
|
+
});
|
141
143
|
|
142
144
|
if (enabledSearch) {
|
143
145
|
// Limit the number of searches per request
|
@@ -146,9 +148,11 @@ export class LobeAnthropicAI implements LobeRuntimeAI {
|
|
146
148
|
const webSearchTool: Anthropic.WebSearchTool20250305 = {
|
147
149
|
name: 'web_search',
|
148
150
|
type: 'web_search_20250305',
|
149
|
-
...(maxUses &&
|
150
|
-
|
151
|
-
|
151
|
+
...(maxUses &&
|
152
|
+
Number.isInteger(Number(maxUses)) &&
|
153
|
+
Number(maxUses) > 0 && {
|
154
|
+
max_uses: Number(maxUses),
|
155
|
+
}),
|
152
156
|
};
|
153
157
|
|
154
158
|
// 如果已有工具,则添加到现有工具列表中;否则创建新的工具列表
|
@@ -171,8 +175,8 @@ export class LobeAnthropicAI implements LobeRuntimeAI {
|
|
171
175
|
system: systemPrompts,
|
172
176
|
thinking: {
|
173
177
|
...thinking,
|
174
|
-
budget_tokens: thinking?.budget_tokens
|
175
|
-
? Math.min(thinking.budget_tokens, maxTokens - 1)
|
178
|
+
budget_tokens: thinking?.budget_tokens
|
179
|
+
? Math.min(thinking.budget_tokens, maxTokens - 1) // `max_tokens` must be greater than `thinking.budget_tokens`.
|
176
180
|
: 1024,
|
177
181
|
},
|
178
182
|
tools: postTools,
|
@@ -5,7 +5,7 @@ import { systemToUserModels } from '@/const/models';
|
|
5
5
|
|
6
6
|
import { LobeRuntimeAI } from '../BaseAI';
|
7
7
|
import { AgentRuntimeErrorType } from '../error';
|
8
|
-
import {
|
8
|
+
import { ChatMethodOptions, ChatStreamPayload, ModelProvider } from '../types';
|
9
9
|
import { AgentRuntimeError } from '../utils/createError';
|
10
10
|
import { debugStream } from '../utils/debugStream';
|
11
11
|
import { transformResponseToStream } from '../utils/openaiCompatibleFactory';
|
@@ -32,7 +32,7 @@ export class LobeAzureOpenAI implements LobeRuntimeAI {
|
|
32
32
|
|
33
33
|
baseURL: string;
|
34
34
|
|
35
|
-
async chat(payload: ChatStreamPayload, options?:
|
35
|
+
async chat(payload: ChatStreamPayload, options?: ChatMethodOptions) {
|
36
36
|
const { messages, model, ...params } = payload;
|
37
37
|
// o1 series models on Azure OpenAI does not support streaming currently
|
38
38
|
const enableStreaming = model.includes('o1') ? false : (params.stream ?? true);
|
@@ -6,7 +6,7 @@ import { systemToUserModels } from '@/const/models';
|
|
6
6
|
|
7
7
|
import { LobeRuntimeAI } from '../BaseAI';
|
8
8
|
import { AgentRuntimeErrorType } from '../error';
|
9
|
-
import {
|
9
|
+
import { ChatMethodOptions, ChatStreamPayload, ModelProvider } from '../types';
|
10
10
|
import { AgentRuntimeError } from '../utils/createError';
|
11
11
|
import { debugStream } from '../utils/debugStream';
|
12
12
|
import { transformResponseToStream } from '../utils/openaiCompatibleFactory';
|
@@ -33,7 +33,7 @@ export class LobeAzureAI implements LobeRuntimeAI {
|
|
33
33
|
|
34
34
|
baseURL: string;
|
35
35
|
|
36
|
-
async chat(payload: ChatStreamPayload, options?:
|
36
|
+
async chat(payload: ChatStreamPayload, options?: ChatMethodOptions) {
|
37
37
|
const { messages, model, temperature, top_p, ...params } = payload;
|
38
38
|
// o1 series models on Azure OpenAI does not support streaming currently
|
39
39
|
const enableStreaming = model.includes('o1') ? false : (params.stream ?? true);
|
@@ -56,9 +56,9 @@ export class LobeAzureAI implements LobeRuntimeAI {
|
|
56
56
|
model,
|
57
57
|
...params,
|
58
58
|
stream: enableStreaming,
|
59
|
-
temperature:
|
59
|
+
temperature: model.includes('o3') || model.includes('o4') ? undefined : temperature,
|
60
60
|
tool_choice: params.tools ? 'auto' : undefined,
|
61
|
-
top_p:
|
61
|
+
top_p: model.includes('o3') || model.includes('o4') ? undefined : top_p,
|
62
62
|
},
|
63
63
|
});
|
64
64
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { ChatModelCard } from '@/types/llm';
|
2
2
|
|
3
3
|
import { ChatStreamPayload, ModelProvider } from '../types';
|
4
|
-
import {
|
4
|
+
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
5
5
|
|
6
6
|
export interface BaichuanModelCard {
|
7
7
|
function_call: boolean;
|
@@ -11,7 +11,7 @@ export interface BaichuanModelCard {
|
|
11
11
|
model_show_name: string;
|
12
12
|
}
|
13
13
|
|
14
|
-
export const LobeBaichuanAI =
|
14
|
+
export const LobeBaichuanAI = createOpenAICompatibleRuntime({
|
15
15
|
baseURL: 'https://api.baichuan-ai.com/v1',
|
16
16
|
chatCompletion: {
|
17
17
|
handlePayload: (payload: ChatStreamPayload) => {
|
@@ -8,7 +8,7 @@ import { experimental_buildLlama2Prompt } from 'ai/prompts';
|
|
8
8
|
import { LobeRuntimeAI } from '../BaseAI';
|
9
9
|
import { AgentRuntimeErrorType } from '../error';
|
10
10
|
import {
|
11
|
-
|
11
|
+
ChatMethodOptions,
|
12
12
|
ChatStreamPayload,
|
13
13
|
Embeddings,
|
14
14
|
EmbeddingsOptions,
|
@@ -51,7 +51,7 @@ export class LobeBedrockAI implements LobeRuntimeAI {
|
|
51
51
|
});
|
52
52
|
}
|
53
53
|
|
54
|
-
async chat(payload: ChatStreamPayload, options?:
|
54
|
+
async chat(payload: ChatStreamPayload, options?: ChatMethodOptions) {
|
55
55
|
if (payload.model.startsWith('meta')) return this.invokeLlamaModel(payload, options);
|
56
56
|
|
57
57
|
return this.invokeClaudeModel(payload, options);
|
@@ -114,7 +114,7 @@ export class LobeBedrockAI implements LobeRuntimeAI {
|
|
114
114
|
|
115
115
|
private invokeClaudeModel = async (
|
116
116
|
payload: ChatStreamPayload,
|
117
|
-
options?:
|
117
|
+
options?: ChatMethodOptions,
|
118
118
|
): Promise<Response> => {
|
119
119
|
const { max_tokens, messages, model, temperature, top_p, tools } = payload;
|
120
120
|
const system_message = messages.find((m) => m.role === 'system');
|
@@ -169,7 +169,7 @@ export class LobeBedrockAI implements LobeRuntimeAI {
|
|
169
169
|
|
170
170
|
private invokeLlamaModel = async (
|
171
171
|
payload: ChatStreamPayload,
|
172
|
-
options?:
|
172
|
+
options?: ChatMethodOptions,
|
173
173
|
): Promise<Response> => {
|
174
174
|
const { max_tokens, messages, model } = payload;
|
175
175
|
const command = new InvokeModelWithResponseStreamCommand({
|
@@ -2,7 +2,7 @@ import { ChatModelCard } from '@/types/llm';
|
|
2
2
|
|
3
3
|
import { LobeRuntimeAI } from '../BaseAI';
|
4
4
|
import { AgentRuntimeErrorType } from '../error';
|
5
|
-
import {
|
5
|
+
import { ChatMethodOptions, ChatStreamPayload, ModelProvider } from '../types';
|
6
6
|
import {
|
7
7
|
CloudflareStreamTransformer,
|
8
8
|
DEFAULT_BASE_URL_PREFIX,
|
@@ -54,7 +54,7 @@ export class LobeCloudflareAI implements LobeRuntimeAI {
|
|
54
54
|
this.apiKey = apiKey;
|
55
55
|
}
|
56
56
|
|
57
|
-
async chat(payload: ChatStreamPayload, options?:
|
57
|
+
async chat(payload: ChatStreamPayload, options?: ChatMethodOptions): Promise<Response> {
|
58
58
|
try {
|
59
59
|
const { model, tools, ...restPayload } = payload;
|
60
60
|
const functions = tools?.map((tool) => tool.function);
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { ChatModelCard } from '@/types/llm';
|
2
2
|
|
3
3
|
import { ModelProvider } from '../types';
|
4
|
-
import {
|
4
|
+
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
5
5
|
|
6
6
|
export interface CohereModelCard {
|
7
7
|
context_length: number;
|
@@ -10,7 +10,7 @@ export interface CohereModelCard {
|
|
10
10
|
supports_vision: boolean;
|
11
11
|
}
|
12
12
|
|
13
|
-
export const LobeCohereAI =
|
13
|
+
export const LobeCohereAI = createOpenAICompatibleRuntime({
|
14
14
|
baseURL: 'https://api.cohere.ai/compatibility/v1',
|
15
15
|
chatCompletion: {
|
16
16
|
// https://docs.cohere.com/v2/docs/compatibility-api#unsupported-parameters
|
@@ -1,13 +1,13 @@
|
|
1
1
|
import type { ChatModelCard } from '@/types/llm';
|
2
2
|
|
3
3
|
import { ModelProvider } from '../types';
|
4
|
-
import {
|
4
|
+
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
5
5
|
|
6
6
|
export interface DeepSeekModelCard {
|
7
7
|
id: string;
|
8
8
|
}
|
9
9
|
|
10
|
-
export const LobeDeepSeekAI =
|
10
|
+
export const LobeDeepSeekAI = createOpenAICompatibleRuntime({
|
11
11
|
baseURL: 'https://api.deepseek.com/v1',
|
12
12
|
debug: {
|
13
13
|
chatCompletion: () => process.env.DEBUG_DEEPSEEK_CHAT_COMPLETION === '1',
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { ChatModelCard } from '@/types/llm';
|
2
2
|
|
3
3
|
import { ModelProvider } from '../types';
|
4
|
-
import {
|
4
|
+
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
5
5
|
|
6
6
|
export interface FireworksAIModelCard {
|
7
7
|
context_length: number;
|
@@ -10,7 +10,7 @@ export interface FireworksAIModelCard {
|
|
10
10
|
supports_tools: boolean;
|
11
11
|
}
|
12
12
|
|
13
|
-
export const LobeFireworksAI =
|
13
|
+
export const LobeFireworksAI = createOpenAICompatibleRuntime({
|
14
14
|
baseURL: 'https://api.fireworks.ai/inference/v1',
|
15
15
|
debug: {
|
16
16
|
chatCompletion: () => process.env.DEBUG_FIREWORKSAI_CHAT_COMPLETION === '1',
|
@@ -1,13 +1,13 @@
|
|
1
1
|
import type { ChatModelCard } from '@/types/llm';
|
2
2
|
|
3
3
|
import { ModelProvider } from '../types';
|
4
|
-
import {
|
4
|
+
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
5
5
|
|
6
6
|
export interface GiteeAIModelCard {
|
7
7
|
id: string;
|
8
8
|
}
|
9
9
|
|
10
|
-
export const LobeGiteeAI =
|
10
|
+
export const LobeGiteeAI = createOpenAICompatibleRuntime({
|
11
11
|
baseURL: 'https://ai.gitee.com/v1',
|
12
12
|
debug: {
|
13
13
|
chatCompletion: () => process.env.DEBUG_GITEE_AI_CHAT_COMPLETION === '1',
|
@@ -2,7 +2,7 @@ import type { ChatModelCard } from '@/types/llm';
|
|
2
2
|
|
3
3
|
import { AgentRuntimeErrorType } from '../error';
|
4
4
|
import { ModelProvider } from '../types';
|
5
|
-
import {
|
5
|
+
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
6
6
|
import { pruneReasoningPayload } from '../utils/openaiHelpers';
|
7
7
|
|
8
8
|
export interface GithubModelCard {
|
@@ -16,7 +16,7 @@ export interface GithubModelCard {
|
|
16
16
|
|
17
17
|
/* eslint-enable typescript-sort-keys/interface */
|
18
18
|
|
19
|
-
export const LobeGithubAI =
|
19
|
+
export const LobeGithubAI = createOpenAICompatibleRuntime({
|
20
20
|
baseURL: 'https://models.github.ai/inference',
|
21
21
|
chatCompletion: {
|
22
22
|
handlePayload: (payload) => {
|
@@ -17,8 +17,8 @@ import { safeParseJSON } from '@/utils/safeParseJSON';
|
|
17
17
|
import { LobeRuntimeAI } from '../BaseAI';
|
18
18
|
import { AgentRuntimeErrorType, ILobeAgentRuntimeErrorType } from '../error';
|
19
19
|
import {
|
20
|
-
ChatCompetitionOptions,
|
21
20
|
ChatCompletionTool,
|
21
|
+
ChatMethodOptions,
|
22
22
|
ChatStreamPayload,
|
23
23
|
OpenAIChatMessage,
|
24
24
|
UserMessageContentPart,
|
@@ -111,15 +111,15 @@ export class LobeGoogleAI implements LobeRuntimeAI {
|
|
111
111
|
this.provider = id || (isVertexAi ? 'vertexai' : 'google');
|
112
112
|
}
|
113
113
|
|
114
|
-
async chat(rawPayload: ChatStreamPayload, options?:
|
114
|
+
async chat(rawPayload: ChatStreamPayload, options?: ChatMethodOptions) {
|
115
115
|
try {
|
116
116
|
const payload = this.buildPayload(rawPayload);
|
117
117
|
const { model, thinking } = payload;
|
118
118
|
|
119
119
|
const thinkingConfig: GoogleAIThinkingConfig = {
|
120
120
|
includeThoughts:
|
121
|
-
|
122
|
-
(!thinking && model && (model.includes('-2.5-') || model.includes('thinking')))
|
121
|
+
thinking?.type === 'enabled' ||
|
122
|
+
(!thinking && model && (model.includes('-2.5-') || model.includes('thinking')))
|
123
123
|
? true
|
124
124
|
: undefined,
|
125
125
|
thinkingBudget:
|
@@ -142,7 +142,9 @@ export class LobeGoogleAI implements LobeRuntimeAI {
|
|
142
142
|
response_modalities: modelsWithModalities.has(model) ? ['Text', 'Image'] : undefined,
|
143
143
|
temperature: payload.temperature,
|
144
144
|
topP: payload.top_p,
|
145
|
-
...(modelsDisableInstuction.has(model) || model.toLowerCase().includes('learnlm')
|
145
|
+
...(modelsDisableInstuction.has(model) || model.toLowerCase().includes('learnlm')
|
146
|
+
? {}
|
147
|
+
: { thinkingConfig }),
|
146
148
|
},
|
147
149
|
model,
|
148
150
|
// avoid wide sensitive words
|
@@ -2,14 +2,14 @@ import type { ChatModelCard } from '@/types/llm';
|
|
2
2
|
|
3
3
|
import { AgentRuntimeErrorType } from '../error';
|
4
4
|
import { ModelProvider } from '../types';
|
5
|
-
import {
|
5
|
+
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
6
6
|
|
7
7
|
export interface GroqModelCard {
|
8
8
|
context_window: number;
|
9
9
|
id: string;
|
10
10
|
}
|
11
11
|
|
12
|
-
export const LobeGroq =
|
12
|
+
export const LobeGroq = createOpenAICompatibleRuntime({
|
13
13
|
baseURL: 'https://api.groq.com/openai/v1',
|
14
14
|
chatCompletion: {
|
15
15
|
handleError: (error) => {
|
@@ -3,7 +3,7 @@ import { uniqueId } from 'lodash-es';
|
|
3
3
|
import type { ChatModelCard } from '@/types/llm';
|
4
4
|
|
5
5
|
import { ModelProvider } from '../types';
|
6
|
-
import {
|
6
|
+
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
7
7
|
|
8
8
|
export interface HigressModelCard {
|
9
9
|
context_length: number;
|
@@ -15,7 +15,7 @@ export interface HigressModelCard {
|
|
15
15
|
};
|
16
16
|
}
|
17
17
|
|
18
|
-
export const LobeHigressAI =
|
18
|
+
export const LobeHigressAI = createOpenAICompatibleRuntime({
|
19
19
|
constructorOptions: {
|
20
20
|
defaultHeaders: {
|
21
21
|
'HTTP-Referer': 'https://chat-preview.lobehub.com',
|
@@ -5,7 +5,7 @@ import type { ChatModelCard } from '@/types/llm';
|
|
5
5
|
|
6
6
|
import { AgentRuntimeErrorType } from '../error';
|
7
7
|
import { ModelProvider } from '../types';
|
8
|
-
import {
|
8
|
+
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
9
9
|
import { convertIterableToStream } from '../utils/streams';
|
10
10
|
|
11
11
|
export interface HuggingFaceModelCard {
|
@@ -13,7 +13,7 @@ export interface HuggingFaceModelCard {
|
|
13
13
|
tags: string[];
|
14
14
|
}
|
15
15
|
|
16
|
-
export const LobeHuggingFaceAI =
|
16
|
+
export const LobeHuggingFaceAI = createOpenAICompatibleRuntime({
|
17
17
|
chatCompletion: {
|
18
18
|
handleStreamBizErrorType: (error) => {
|
19
19
|
// e.g.: Server meta-llama/Meta-Llama-3.1-8B-Instruct does not seem to support chat completion. Error: Model requires a Pro subscription; check out hf.co/pricing to learn more. Make sure to include your HF token in your query.
|
@@ -1,13 +1,13 @@
|
|
1
1
|
import type { ChatModelCard } from '@/types/llm';
|
2
2
|
|
3
3
|
import { ModelProvider } from '../types';
|
4
|
-
import {
|
4
|
+
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
5
5
|
|
6
6
|
export interface HunyuanModelCard {
|
7
7
|
id: string;
|
8
8
|
}
|
9
9
|
|
10
|
-
export const LobeHunyuanAI =
|
10
|
+
export const LobeHunyuanAI = createOpenAICompatibleRuntime({
|
11
11
|
baseURL: 'https://api.hunyuan.cloud.tencent.com/v1',
|
12
12
|
chatCompletion: {
|
13
13
|
handlePayload: (payload) => {
|
@@ -20,7 +20,7 @@ export { LobeQwenAI } from './qwen';
|
|
20
20
|
export { LobeTogetherAI } from './togetherai';
|
21
21
|
export * from './types';
|
22
22
|
export { AgentRuntimeError } from './utils/createError';
|
23
|
-
export {
|
23
|
+
export { createOpenAICompatibleRuntime } from './utils/openaiCompatibleFactory';
|
24
24
|
export { pruneReasoningPayload } from './utils/openaiHelpers';
|
25
25
|
export { LobeVolcengineAI } from './volcengine';
|
26
26
|
export { LobeZeroOneAI } from './zeroone';
|
@@ -2,13 +2,13 @@ import type { ChatModelCard } from '@/types/llm';
|
|
2
2
|
|
3
3
|
import { AgentRuntimeErrorType } from '../error';
|
4
4
|
import { ChatCompletionErrorPayload, ModelProvider } from '../types';
|
5
|
-
import {
|
5
|
+
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
6
6
|
|
7
7
|
export interface InfiniAIModelCard {
|
8
8
|
id: string;
|
9
9
|
}
|
10
10
|
|
11
|
-
export const LobeInfiniAI =
|
11
|
+
export const LobeInfiniAI = createOpenAICompatibleRuntime({
|
12
12
|
baseURL: 'https://cloud.infini-ai.com/maas/v1',
|
13
13
|
chatCompletion: {
|
14
14
|
handleError(error): Omit<ChatCompletionErrorPayload, 'provider'> | undefined {
|
@@ -1,13 +1,13 @@
|
|
1
1
|
import type { ChatModelCard } from '@/types/llm';
|
2
2
|
|
3
3
|
import { ModelProvider } from '../types';
|
4
|
-
import {
|
4
|
+
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
5
5
|
|
6
6
|
export interface InternLMModelCard {
|
7
7
|
id: string;
|
8
8
|
}
|
9
9
|
|
10
|
-
export const LobeInternLMAI =
|
10
|
+
export const LobeInternLMAI = createOpenAICompatibleRuntime({
|
11
11
|
baseURL: 'https://internlm-chat.intern-ai.org.cn/puyu/api/v1',
|
12
12
|
chatCompletion: {
|
13
13
|
handlePayload: (payload) => {
|
@@ -23,9 +23,9 @@ export const LobeInternLMAI = LobeOpenAICompatibleFactory({
|
|
23
23
|
models: async ({ client }) => {
|
24
24
|
const { LOBE_DEFAULT_MODEL_LIST } = await import('@/config/aiModels');
|
25
25
|
|
26
|
-
const functionCallKeywords = ['internlm']
|
26
|
+
const functionCallKeywords = ['internlm'];
|
27
27
|
|
28
|
-
const visionKeywords = ['internvl']
|
28
|
+
const visionKeywords = ['internvl'];
|
29
29
|
|
30
30
|
const modelsPage = (await client.models.list()) as any;
|
31
31
|
const modelList: InternLMModelCard[] = modelsPage.data;
|
@@ -41,15 +41,13 @@ export const LobeInternLMAI = LobeOpenAICompatibleFactory({
|
|
41
41
|
displayName: knownModel?.displayName ?? undefined,
|
42
42
|
enabled: knownModel?.enabled || false,
|
43
43
|
functionCall:
|
44
|
-
functionCallKeywords.some(keyword => model.id.toLowerCase().includes(keyword)) ||
|
44
|
+
functionCallKeywords.some((keyword) => model.id.toLowerCase().includes(keyword)) ||
|
45
45
|
knownModel?.abilities?.functionCall ||
|
46
46
|
false,
|
47
47
|
id: model.id,
|
48
|
-
reasoning:
|
49
|
-
knownModel?.abilities?.reasoning ||
|
50
|
-
false,
|
48
|
+
reasoning: knownModel?.abilities?.reasoning || false,
|
51
49
|
vision:
|
52
|
-
visionKeywords.some(keyword => model.id.toLowerCase().includes(keyword)) ||
|
50
|
+
visionKeywords.some((keyword) => model.id.toLowerCase().includes(keyword)) ||
|
53
51
|
knownModel?.abilities?.vision ||
|
54
52
|
false,
|
55
53
|
};
|
@@ -1,13 +1,13 @@
|
|
1
1
|
import type { ChatModelCard } from '@/types/llm';
|
2
2
|
|
3
3
|
import { ModelProvider } from '../types';
|
4
|
-
import {
|
4
|
+
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
5
5
|
|
6
6
|
export interface JinaModelCard {
|
7
7
|
id: string;
|
8
8
|
}
|
9
9
|
|
10
|
-
export const LobeJinaAI =
|
10
|
+
export const LobeJinaAI = createOpenAICompatibleRuntime({
|
11
11
|
baseURL: 'https://deepsearch.jina.ai/v1',
|
12
12
|
debug: {
|
13
13
|
chatCompletion: () => process.env.DEBUG_JINA_CHAT_COMPLETION === '1',
|
@@ -1,13 +1,13 @@
|
|
1
1
|
import type { ChatModelCard } from '@/types/llm';
|
2
2
|
|
3
3
|
import { ModelProvider } from '../types';
|
4
|
-
import {
|
4
|
+
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
5
5
|
|
6
6
|
export interface LMStudioModelCard {
|
7
7
|
id: string;
|
8
8
|
}
|
9
9
|
|
10
|
-
export const LobeLMStudioAI =
|
10
|
+
export const LobeLMStudioAI = createOpenAICompatibleRuntime({
|
11
11
|
apiKey: 'placeholder-to-avoid-error',
|
12
12
|
baseURL: 'http://127.0.0.1:1234/v1',
|
13
13
|
debug: {
|
@@ -1,14 +1,14 @@
|
|
1
1
|
import minimaxChatModels from '@/config/aiModels/minimax';
|
2
2
|
|
3
3
|
import { ModelProvider } from '../types';
|
4
|
-
import {
|
4
|
+
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
5
5
|
|
6
6
|
export const getMinimaxMaxOutputs = (modelId: string): number | undefined => {
|
7
7
|
const model = minimaxChatModels.find((model) => model.id === modelId);
|
8
8
|
return model ? model.maxOutput : undefined;
|
9
9
|
};
|
10
10
|
|
11
|
-
export const LobeMinimaxAI =
|
11
|
+
export const LobeMinimaxAI = createOpenAICompatibleRuntime({
|
12
12
|
baseURL: 'https://api.minimax.chat/v1',
|
13
13
|
chatCompletion: {
|
14
14
|
handlePayload: (payload) => {
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { ChatModelCard } from '@/types/llm';
|
2
2
|
|
3
3
|
import { ModelProvider } from '../types';
|
4
|
-
import {
|
4
|
+
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
5
5
|
|
6
6
|
export interface MistralModelCard {
|
7
7
|
capabilities: {
|
@@ -13,7 +13,7 @@ export interface MistralModelCard {
|
|
13
13
|
max_context_length: number;
|
14
14
|
}
|
15
15
|
|
16
|
-
export const LobeMistralAI =
|
16
|
+
export const LobeMistralAI = createOpenAICompatibleRuntime({
|
17
17
|
baseURL: 'https://api.mistral.ai/v1',
|
18
18
|
chatCompletion: {
|
19
19
|
// Mistral API does not support stream_options: { include_usage: true }
|
@@ -1,8 +1,7 @@
|
|
1
|
-
|
2
1
|
import type { ChatModelCard } from '@/types/llm';
|
3
2
|
|
4
3
|
import { ModelProvider } from '../types';
|
5
|
-
import {
|
4
|
+
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
6
5
|
|
7
6
|
export interface ModelScopeModelCard {
|
8
7
|
created: number;
|
@@ -11,7 +10,7 @@ export interface ModelScopeModelCard {
|
|
11
10
|
owned_by: string;
|
12
11
|
}
|
13
12
|
|
14
|
-
export const LobeModelScopeAI =
|
13
|
+
export const LobeModelScopeAI = createOpenAICompatibleRuntime({
|
15
14
|
baseURL: 'https://api-inference.modelscope.cn/v1',
|
16
15
|
debug: {
|
17
16
|
chatCompletion: () => process.env.DEBUG_MODELSCOPE_CHAT_COMPLETION === '1',
|
@@ -1,13 +1,13 @@
|
|
1
1
|
import type { ChatModelCard } from '@/types/llm';
|
2
2
|
|
3
3
|
import { ChatStreamPayload, ModelProvider } from '../types';
|
4
|
-
import {
|
4
|
+
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
5
5
|
|
6
6
|
export interface MoonshotModelCard {
|
7
7
|
id: string;
|
8
8
|
}
|
9
9
|
|
10
|
-
export const LobeMoonshotAI =
|
10
|
+
export const LobeMoonshotAI = createOpenAICompatibleRuntime({
|
11
11
|
baseURL: 'https://api.moonshot.cn/v1',
|
12
12
|
chatCompletion: {
|
13
13
|
handlePayload: (payload: ChatStreamPayload) => {
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import type { ChatModelCard } from '@/types/llm';
|
2
2
|
|
3
3
|
import { ModelProvider } from '../types';
|
4
|
-
import {
|
4
|
+
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
5
5
|
import { NovitaModelCard } from './type';
|
6
6
|
|
7
|
-
export const LobeNovitaAI =
|
7
|
+
export const LobeNovitaAI = createOpenAICompatibleRuntime({
|
8
8
|
baseURL: 'https://api.novita.ai/v3/openai',
|
9
9
|
constructorOptions: {
|
10
10
|
defaultHeaders: {
|
@@ -1,13 +1,13 @@
|
|
1
1
|
import type { ChatModelCard } from '@/types/llm';
|
2
2
|
|
3
3
|
import { ModelProvider } from '../types';
|
4
|
-
import {
|
4
|
+
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
|
5
5
|
|
6
6
|
export interface NvidiaModelCard {
|
7
7
|
id: string;
|
8
8
|
}
|
9
9
|
|
10
|
-
export const LobeNvidiaAI =
|
10
|
+
export const LobeNvidiaAI = createOpenAICompatibleRuntime({
|
11
11
|
baseURL: 'https://integrate.api.nvidia.com/v1',
|
12
12
|
debug: {
|
13
13
|
chatCompletion: () => process.env.DEBUG_NVIDIA_CHAT_COMPLETION === '1',
|
@@ -8,7 +8,7 @@ import { createErrorResponse } from '@/utils/errorResponse';
|
|
8
8
|
import { LobeRuntimeAI } from '../BaseAI';
|
9
9
|
import { AgentRuntimeErrorType } from '../error';
|
10
10
|
import {
|
11
|
-
|
11
|
+
ChatMethodOptions,
|
12
12
|
ChatStreamPayload,
|
13
13
|
Embeddings,
|
14
14
|
EmbeddingsPayload,
|
@@ -43,7 +43,7 @@ export class LobeOllamaAI implements LobeRuntimeAI {
|
|
43
43
|
if (baseURL) this.baseURL = baseURL;
|
44
44
|
}
|
45
45
|
|
46
|
-
async chat(payload: ChatStreamPayload, options?:
|
46
|
+
async chat(payload: ChatStreamPayload, options?: ChatMethodOptions) {
|
47
47
|
try {
|
48
48
|
const abort = () => {
|
49
49
|
this.client.abort();
|