@lobehub/chat 1.114.0 → 1.114.2
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/.eslintignore +17 -0
- package/.github/workflows/auto-i18n.yml +1 -1
- package/.github/workflows/claude.yml +1 -1
- package/.github/workflows/desktop-pr-build.yml +4 -4
- package/.github/workflows/docker-database.yml +3 -3
- package/.github/workflows/docker-pglite.yml +3 -3
- package/.github/workflows/docker.yml +3 -3
- package/.github/workflows/lighthouse.yml +2 -2
- package/.github/workflows/release-desktop-beta.yml +3 -3
- package/.github/workflows/release.yml +2 -2
- package/.github/workflows/sync-database-schema.yml +1 -1
- package/.github/workflows/sync.yml +1 -1
- package/.github/workflows/test.yml +76 -14
- package/.stylelintignore +39 -0
- package/CHANGELOG.md +50 -0
- package/changelog/v1.json +18 -0
- package/package.json +1 -1
- package/packages/const/src/index.ts +2 -0
- package/packages/electron-server-ipc/package.json +2 -1
- package/packages/electron-server-ipc/vitest.config.ts +10 -0
- package/packages/file-loaders/package.json +2 -1
- package/packages/model-runtime/package.json +4 -0
- package/packages/model-runtime/src/baichuan/index.test.ts +1 -1
- package/packages/model-runtime/src/mistral/index.test.ts +1 -1
- package/packages/model-runtime/src/utils/anthropicHelpers.test.ts +1 -1
- package/packages/model-runtime/src/utils/modelParse.ts +1 -2
- package/packages/model-runtime/vitest.config.ts +16 -0
- package/packages/prompts/package.json +5 -0
- package/{src → packages/prompts/src}/chains/__tests__/langDetect.test.ts +1 -2
- package/{src → packages/prompts/src}/chains/__tests__/pickEmoji.test.ts +1 -2
- package/{src → packages/prompts/src}/chains/__tests__/summaryAgentName.test.ts +2 -15
- package/{src → packages/prompts/src}/chains/__tests__/summaryDescription.test.ts +4 -16
- package/{src → packages/prompts/src}/chains/__tests__/summaryHistory.test.ts +1 -5
- package/{src → packages/prompts/src}/chains/__tests__/summaryTags.test.ts +1 -14
- package/{src → packages/prompts/src}/chains/__tests__/summaryTitle.test.ts +3 -22
- package/{src → packages/prompts/src}/chains/abstractChunk.ts +2 -2
- package/{src → packages/prompts/src}/chains/answerWithContext.ts +1 -1
- package/packages/prompts/src/chains/index.ts +12 -0
- package/{src → packages/prompts/src}/chains/langDetect.ts +1 -1
- package/{src → packages/prompts/src}/chains/pickEmoji.ts +1 -1
- package/{src → packages/prompts/src}/chains/rewriteQuery.ts +2 -2
- package/{src → packages/prompts/src}/chains/summaryAgentName.ts +6 -5
- package/{src → packages/prompts/src}/chains/summaryDescription.ts +7 -5
- package/{src → packages/prompts/src}/chains/summaryGenerationTitle.ts +3 -5
- package/{src → packages/prompts/src}/chains/summaryHistory.ts +2 -3
- package/{src → packages/prompts/src}/chains/summaryTags.ts +3 -4
- package/{src → packages/prompts/src}/chains/summaryTitle.ts +5 -5
- package/{src → packages/prompts/src}/chains/translate.ts +1 -1
- package/packages/prompts/src/index.ts +2 -5
- package/packages/prompts/src/{files → prompts/files}/index.test.ts +1 -2
- package/packages/prompts/src/prompts/index.ts +5 -0
- package/packages/prompts/src/{knowledgeBaseQA → prompts/knowledgeBaseQA}/index.test.ts +1 -3
- package/packages/prompts/src/{plugin → prompts/plugin}/index.test.ts +2 -0
- package/packages/prompts/vitest.config.ts +7 -0
- package/packages/types/src/index.ts +4 -0
- package/packages/web-crawler/package.json +4 -0
- package/packages/web-crawler/src/crawImpl/__tests__/jina.test.ts +1 -1
- package/packages/web-crawler/src/crawImpl/__tests__/search1api.test.ts +1 -1
- package/packages/web-crawler/src/utils/__tests__/withTimeout.test.ts +1 -1
- package/packages/web-crawler/src/utils/appUrlRules.test.ts +2 -0
- package/packages/web-crawler/src/utils/htmlToMarkdown.test.ts +1 -1
- package/packages/web-crawler/vitest.config.ts +7 -0
- package/src/app/[variants]/(main)/settings/provider/(detail)/[id]/ClientMode.tsx +4 -0
- package/src/features/AgentSetting/store/action.ts +19 -7
- package/src/server/routers/async/ragEval.ts +1 -1
- package/src/store/chat/slices/aiChat/actions/memory.ts +1 -1
- package/src/store/chat/slices/aiChat/actions/rag.ts +1 -1
- package/src/store/chat/slices/thread/action.ts +3 -2
- package/src/store/chat/slices/topic/action.ts +3 -2
- package/src/store/chat/slices/translate/action.test.ts +2 -2
- package/src/store/chat/slices/translate/action.ts +1 -2
- package/src/store/image/slices/generationTopic/action.ts +6 -2
- package/tsconfig.json +1 -1
- package/vitest.config.ts +2 -0
- package/.github/workflows/claude-code-review.yml +0 -78
- package/.github/workflows/wiki-sync.yml +0 -19
- /package/{src → packages/prompts/src}/chains/__tests__/__snapshots__/summaryHistory.test.ts.snap +0 -0
- /package/{src → packages/prompts/src}/chains/__tests__/translate.test.ts +0 -0
- /package/packages/prompts/src/{chatMessages → prompts/chatMessages}/index.test.ts +0 -0
- /package/packages/prompts/src/{chatMessages → prompts/chatMessages}/index.ts +0 -0
- /package/packages/prompts/src/{files → prompts/files}/file.ts +0 -0
- /package/packages/prompts/src/{files → prompts/files}/image.ts +0 -0
- /package/packages/prompts/src/{files → prompts/files}/index.ts +0 -0
- /package/packages/prompts/src/{knowledgeBaseQA → prompts/knowledgeBaseQA}/__snapshots__/index.test.ts.snap +0 -0
- /package/packages/prompts/src/{knowledgeBaseQA → prompts/knowledgeBaseQA}/chunk.ts +0 -0
- /package/packages/prompts/src/{knowledgeBaseQA → prompts/knowledgeBaseQA}/index.ts +0 -0
- /package/packages/prompts/src/{knowledgeBaseQA → prompts/knowledgeBaseQA}/knowledge.ts +0 -0
- /package/packages/prompts/src/{knowledgeBaseQA → prompts/knowledgeBaseQA}/userQuery.ts +0 -0
- /package/packages/prompts/src/{plugin → prompts/plugin}/index.ts +0 -0
- /package/packages/prompts/src/{plugin → prompts/plugin}/tools.test.ts +0 -0
- /package/packages/prompts/src/{plugin → prompts/plugin}/tools.ts +0 -0
- /package/packages/prompts/src/{systemRole → prompts/systemRole}/index.ts +0 -0
@@ -1,23 +1,14 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
import { globalHelpers } from '@/store/global/helpers';
|
1
|
+
import { describe, expect, it } from 'vitest';
|
4
2
|
|
5
3
|
import { chainSummaryDescription } from '../summaryDescription';
|
6
4
|
|
7
|
-
// Mock the globalHelpers.getCurrentLanguage function
|
8
|
-
vi.mock('@/store/global/helpers', () => ({
|
9
|
-
globalHelpers: {
|
10
|
-
getCurrentLanguage: vi.fn(() => 'en-US'),
|
11
|
-
},
|
12
|
-
}));
|
13
|
-
|
14
5
|
describe('chainSummaryDescription', () => {
|
15
6
|
it('should return a payload with the correct structure and content based on the input', () => {
|
16
7
|
const inputContent = '你是一个专业的JavaScript开发者';
|
17
8
|
const expectedOutput = {
|
18
9
|
messages: [
|
19
10
|
{
|
20
|
-
content: `你是一名擅长技能总结的助理,你需要将用户的输入的内容总结为一个角色技能简介,不超过 20
|
11
|
+
content: `你是一名擅长技能总结的助理,你需要将用户的输入的内容总结为一个角色技能简介,不超过 20 个字。内容需要确保信息清晰、逻辑清晰,并有效地传达角色的技能和经验,需要并翻译为目标语言:en-US。格式要求如下:\n输入: {文本作为JSON引用字符串} [locale]\n输出: {简介}`,
|
21
12
|
role: 'system',
|
22
13
|
},
|
23
14
|
{
|
@@ -64,17 +55,14 @@ nav: API
|
|
64
55
|
temperature: 0,
|
65
56
|
};
|
66
57
|
|
67
|
-
const result = chainSummaryDescription(inputContent);
|
58
|
+
const result = chainSummaryDescription(inputContent, 'en-US');
|
68
59
|
|
69
60
|
expect(result).toEqual(expectedOutput);
|
70
61
|
});
|
71
62
|
|
72
63
|
it('should handle different languages', () => {
|
73
|
-
// Override the getCurrentLanguage mock to return a different language
|
74
|
-
(globalHelpers.getCurrentLanguage as Mock).mockReturnValueOnce('zh-CN');
|
75
|
-
|
76
64
|
const inputContent = '你是一个专业的JavaScript开发者';
|
77
|
-
const result = chainSummaryDescription(inputContent);
|
65
|
+
const result = chainSummaryDescription(inputContent, 'zh-CN');
|
78
66
|
|
79
67
|
// Verify that the language in the output matches the mocked language
|
80
68
|
expect(result.messages![0].content).toContain('翻译为目标语言:zh-CN');
|
@@ -1,10 +1,6 @@
|
|
1
|
+
import { ChatMessage } from '@lobechat/types';
|
1
2
|
import { Mock, describe, expect, it, vi } from 'vitest';
|
2
3
|
|
3
|
-
import { chatHelpers } from '@/store/chat/helpers';
|
4
|
-
import { globalHelpers } from '@/store/global/helpers';
|
5
|
-
import { ChatMessage } from '@/types/message';
|
6
|
-
import { OpenAIChatMessage } from '@/types/openai/chat';
|
7
|
-
|
8
4
|
import { chainSummaryHistory } from '../summaryHistory';
|
9
5
|
|
10
6
|
describe('chainSummaryHistory', () => {
|
@@ -1,25 +1,15 @@
|
|
1
1
|
import { Mock, describe, expect, it } from 'vitest';
|
2
2
|
|
3
|
-
import { globalHelpers } from '@/store/global/helpers';
|
4
|
-
|
5
3
|
import { chainSummaryTags } from '../summaryTags';
|
6
4
|
|
7
|
-
// Mock the getCurrentLanguage function
|
8
|
-
vi.mock('@/store/global/helpers', () => ({
|
9
|
-
globalHelpers: {
|
10
|
-
getCurrentLanguage: vi.fn(),
|
11
|
-
},
|
12
|
-
}));
|
13
|
-
|
14
5
|
describe('chainSummaryTags', () => {
|
15
6
|
it('should create a payload with system and user messages including the provided content and current language', () => {
|
16
7
|
// Arrange
|
17
8
|
const content = '这是一段测试文本';
|
18
9
|
const currentLanguage = 'en-US';
|
19
|
-
(globalHelpers.getCurrentLanguage as Mock).mockReturnValue(currentLanguage);
|
20
10
|
|
21
11
|
// Act
|
22
|
-
const result = chainSummaryTags(content);
|
12
|
+
const result = chainSummaryTags(content, currentLanguage);
|
23
13
|
|
24
14
|
// Assert
|
25
15
|
expect(result).toEqual({
|
@@ -47,8 +37,5 @@ describe('chainSummaryTags', () => {
|
|
47
37
|
{ content: `输入: {${content}} [${currentLanguage}]`, role: 'user' },
|
48
38
|
],
|
49
39
|
});
|
50
|
-
|
51
|
-
// Verify that the getCurrentLanguage function was called
|
52
|
-
expect(globalHelpers.getCurrentLanguage).toHaveBeenCalled();
|
53
40
|
});
|
54
41
|
});
|
@@ -1,25 +1,8 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
import { chatHelpers } from '@/store/chat/helpers';
|
4
|
-
import { globalHelpers } from '@/store/global/helpers';
|
5
|
-
import { OpenAIChatMessage } from '@/types/openai/chat';
|
1
|
+
import { OpenAIChatMessage } from '@lobechat/types';
|
2
|
+
import { describe, expect, it, vi } from 'vitest';
|
6
3
|
|
7
4
|
import { chainSummaryTitle } from '../summaryTitle';
|
8
5
|
|
9
|
-
// Mock the getCurrentLanguage function
|
10
|
-
vi.mock('@/store/global/helpers', () => ({
|
11
|
-
globalHelpers: {
|
12
|
-
getCurrentLanguage: vi.fn(),
|
13
|
-
},
|
14
|
-
}));
|
15
|
-
|
16
|
-
// Mock the chatHelpers.getMessagesTokenCount function
|
17
|
-
vi.mock('@/store/chat/helpers', () => ({
|
18
|
-
chatHelpers: {
|
19
|
-
getMessagesTokenCount: vi.fn(),
|
20
|
-
},
|
21
|
-
}));
|
22
|
-
|
23
6
|
describe('chainSummaryTitle', () => {
|
24
7
|
it('should use the default model if the token count is below the GPT-3.5 limit', async () => {
|
25
8
|
// Arrange
|
@@ -29,11 +12,9 @@ describe('chainSummaryTitle', () => {
|
|
29
12
|
];
|
30
13
|
const currentLanguage = 'en-US';
|
31
14
|
const tokenCount = 10000; // Arbitrary token count below the GPT-3.5 limit
|
32
|
-
(globalHelpers.getCurrentLanguage as Mock).mockReturnValue(currentLanguage);
|
33
|
-
(chatHelpers.getMessagesTokenCount as Mock).mockResolvedValue(tokenCount);
|
34
15
|
|
35
16
|
// Act
|
36
|
-
const result = await chainSummaryTitle(messages);
|
17
|
+
const result = await chainSummaryTitle(messages, currentLanguage);
|
37
18
|
|
38
19
|
// Assert
|
39
20
|
expect(result).toEqual({
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { DEFAULT_MODEL } from '
|
2
|
-
import { ChatStreamPayload } from '
|
1
|
+
import { DEFAULT_MODEL } from '@lobechat/const';
|
2
|
+
import { ChatStreamPayload } from '@lobechat/types';
|
3
3
|
|
4
4
|
export const chainAbstractChunkText = (text: string): Partial<ChatStreamPayload> => {
|
5
5
|
return {
|
@@ -0,0 +1,12 @@
|
|
1
|
+
export * from './abstractChunk';
|
2
|
+
export * from './answerWithContext';
|
3
|
+
export * from './langDetect';
|
4
|
+
export * from './pickEmoji';
|
5
|
+
export * from './rewriteQuery';
|
6
|
+
export * from './summaryAgentName';
|
7
|
+
export * from './summaryDescription';
|
8
|
+
export * from './summaryGenerationTitle';
|
9
|
+
export * from './summaryHistory';
|
10
|
+
export * from './summaryTags';
|
11
|
+
export * from './summaryTitle';
|
12
|
+
export * from './translate';
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { DEFAULT_REWRITE_QUERY } from '
|
2
|
-
import { ChatStreamPayload } from '
|
1
|
+
import { DEFAULT_REWRITE_QUERY } from '@lobechat/const';
|
2
|
+
import { ChatStreamPayload } from '@lobechat/types';
|
3
3
|
|
4
4
|
export const chainRewriteQuery = (
|
5
5
|
query: string,
|
@@ -1,11 +1,12 @@
|
|
1
|
-
import {
|
2
|
-
import { ChatStreamPayload } from '@/types/openai/chat';
|
1
|
+
import { ChatStreamPayload } from '@lobechat/types';
|
3
2
|
|
4
3
|
/**
|
5
4
|
* summary agent name for user prompt
|
6
|
-
* @param content
|
7
5
|
*/
|
8
|
-
export const chainSummaryAgentName = (
|
6
|
+
export const chainSummaryAgentName = (
|
7
|
+
content: string,
|
8
|
+
locale: string,
|
9
|
+
): Partial<ChatStreamPayload> => ({
|
9
10
|
messages: [
|
10
11
|
{
|
11
12
|
content: `你是一名擅长起名的起名大师,名字需要有文学内涵,注重精炼和赋子意境,你需要将用户的描述总结为 10 个字以内的角色,并翻译为目标语言。格式要求如下:\n输入: {文本作为JSON引用字符串} [locale]\n输出: {角色名}`,
|
@@ -30,6 +31,6 @@ export const chainSummaryAgentName = (content: string): Partial<ChatStreamPayloa
|
|
30
31
|
role: 'user',
|
31
32
|
},
|
32
33
|
{ content: '邮件优化助理', role: 'assistant' },
|
33
|
-
{ content: `输入: {${content}} [${
|
34
|
+
{ content: `输入: {${content}} [${locale}]`, role: 'user' },
|
34
35
|
],
|
35
36
|
});
|
@@ -1,10 +1,12 @@
|
|
1
|
-
import {
|
2
|
-
import { ChatStreamPayload } from '@/types/openai/chat';
|
1
|
+
import { ChatStreamPayload } from '@lobechat/types';
|
3
2
|
|
4
|
-
export const chainSummaryDescription = (
|
3
|
+
export const chainSummaryDescription = (
|
4
|
+
content: string,
|
5
|
+
locale: string,
|
6
|
+
): Partial<ChatStreamPayload> => ({
|
5
7
|
messages: [
|
6
8
|
{
|
7
|
-
content: `你是一名擅长技能总结的助理,你需要将用户的输入的内容总结为一个角色技能简介,不超过 20 个字。内容需要确保信息清晰、逻辑清晰,并有效地传达角色的技能和经验,需要并翻译为目标语言:${
|
9
|
+
content: `你是一名擅长技能总结的助理,你需要将用户的输入的内容总结为一个角色技能简介,不超过 20 个字。内容需要确保信息清晰、逻辑清晰,并有效地传达角色的技能和经验,需要并翻译为目标语言:${locale}。格式要求如下:\n输入: {文本作为JSON引用字符串} [locale]\n输出: {简介}`,
|
8
10
|
role: 'system',
|
9
11
|
},
|
10
12
|
{
|
@@ -43,7 +45,7 @@ nav: API
|
|
43
45
|
role: 'user',
|
44
46
|
},
|
45
47
|
{ content: '擅长创业计划撰写与咨询', role: 'assistant' },
|
46
|
-
{ content: `输入: {${content}} [${
|
48
|
+
{ content: `输入: {${content}} [${locale}]`, role: 'user' },
|
47
49
|
],
|
48
50
|
temperature: 0,
|
49
51
|
});
|
@@ -1,19 +1,17 @@
|
|
1
|
-
import {
|
2
|
-
import { ChatStreamPayload } from '@/types/openai/chat';
|
1
|
+
import { ChatStreamPayload } from '@lobechat/types';
|
3
2
|
|
4
3
|
export const chainSummaryGenerationTitle = (
|
5
4
|
prompts: string[],
|
6
5
|
modal: 'image' | 'video',
|
6
|
+
locale: string,
|
7
7
|
): Partial<ChatStreamPayload> => {
|
8
|
-
const lang = globalHelpers.getCurrentLanguage();
|
9
|
-
|
10
8
|
// Format multiple prompts for better readability
|
11
9
|
const formattedPrompts = prompts.map((prompt, index) => `${index + 1}. ${prompt}`).join('\n');
|
12
10
|
|
13
11
|
return {
|
14
12
|
messages: [
|
15
13
|
{
|
16
|
-
content: `你是一位资深的 AI 艺术创作者和语言大师。你需要根据用户提供的 AI ${modal} prompt 总结出一个标题。这个标题应简洁地描述创作的核心内容,将用于标识和管理该系列作品。字数需控制在10个字以内,不需要包含标点符号,输出语言为:${
|
14
|
+
content: `你是一位资深的 AI 艺术创作者和语言大师。你需要根据用户提供的 AI ${modal} prompt 总结出一个标题。这个标题应简洁地描述创作的核心内容,将用于标识和管理该系列作品。字数需控制在10个字以内,不需要包含标点符号,输出语言为:${locale}。`,
|
17
15
|
role: 'system',
|
18
16
|
},
|
19
17
|
{
|
@@ -1,7 +1,6 @@
|
|
1
|
-
import {
|
2
|
-
import { ChatMessage } from '@lobechat/types';
|
1
|
+
import { ChatMessage, ChatStreamPayload } from '@lobechat/types';
|
3
2
|
|
4
|
-
import {
|
3
|
+
import { chatHistoryPrompts } from '../prompts';
|
5
4
|
|
6
5
|
export const chainSummaryHistory = (messages: ChatMessage[]): Partial<ChatStreamPayload> => ({
|
7
6
|
messages: [
|
@@ -1,7 +1,6 @@
|
|
1
|
-
import {
|
2
|
-
import { ChatStreamPayload } from '@/types/openai/chat';
|
1
|
+
import { ChatStreamPayload } from '@lobechat/types';
|
3
2
|
|
4
|
-
export const chainSummaryTags = (content: string): Partial<ChatStreamPayload> => ({
|
3
|
+
export const chainSummaryTags = (content: string, locale: string): Partial<ChatStreamPayload> => ({
|
5
4
|
messages: [
|
6
5
|
{
|
7
6
|
content:
|
@@ -23,6 +22,6 @@ export const chainSummaryTags = (content: string): Partial<ChatStreamPayload> =>
|
|
23
22
|
role: 'user',
|
24
23
|
},
|
25
24
|
{ content: 'entrepreneurship,planning,consulting', role: 'assistant' },
|
26
|
-
{ content: `输入: {${content}} [${
|
25
|
+
{ content: `输入: {${content}} [${locale}]`, role: 'user' },
|
27
26
|
],
|
28
27
|
});
|
@@ -1,9 +1,9 @@
|
|
1
|
-
import { globalHelpers } from '@/store/global/helpers';
|
2
1
|
import { ChatStreamPayload, OpenAIChatMessage } from '@/types/openai/chat';
|
3
2
|
|
4
|
-
export const chainSummaryTitle = (
|
5
|
-
|
6
|
-
|
3
|
+
export const chainSummaryTitle = (
|
4
|
+
messages: OpenAIChatMessage[],
|
5
|
+
locale: string,
|
6
|
+
): Partial<ChatStreamPayload> => {
|
7
7
|
return {
|
8
8
|
messages: [
|
9
9
|
{
|
@@ -13,7 +13,7 @@ export const chainSummaryTitle = (messages: OpenAIChatMessage[]): Partial<ChatSt
|
|
13
13
|
{
|
14
14
|
content: `${messages.map((message) => `${message.role}: ${message.content}`).join('\n')}
|
15
15
|
|
16
|
-
请总结上述对话为10个字以内的标题,不需要包含标点符号,输出语言语种为:${
|
16
|
+
请总结上述对话为10个字以内的标题,不需要包含标点符号,输出语言语种为:${locale}`,
|
17
17
|
role: 'user',
|
18
18
|
},
|
19
19
|
],
|
@@ -1,8 +1,6 @@
|
|
1
|
+
import { ChatSemanticSearchChunk, KnowledgeItem, KnowledgeType } from '@lobechat/types';
|
1
2
|
import { describe, expect, it } from 'vitest';
|
2
3
|
|
3
|
-
import { ChatSemanticSearchChunk } from '@/types/chunk';
|
4
|
-
import { KnowledgeItem, KnowledgeType } from '@/types/knowledgeBase';
|
5
|
-
|
6
4
|
import { knowledgeBaseQAPrompts } from './index';
|
7
5
|
|
8
6
|
describe('knowledgeBaseQAPrompts', () => {
|
@@ -1,6 +1,10 @@
|
|
1
1
|
export * from './artifact';
|
2
2
|
export * from './chunk';
|
3
|
+
export * from './clientDB';
|
3
4
|
export * from './fetch';
|
4
5
|
export * from './knowledgeBase';
|
5
6
|
export * from './message';
|
7
|
+
// FIXME: I think we need a refactor for the "openai" types
|
8
|
+
// it more likes the UI message payload
|
9
|
+
export * from './openai/chat';
|
6
10
|
export * from './trace';
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
2
2
|
|
3
3
|
import { NetworkConnectionError, PageNotFoundError, TimeoutError } from '../../utils/errorType';
|
4
4
|
import * as withTimeoutModule from '../../utils/withTimeout';
|
@@ -7,11 +7,15 @@ import { Flexbox } from 'react-layout-kit';
|
|
7
7
|
import Loading from '@/components/Loading/BrandTextLoading';
|
8
8
|
import { useClientDataSWR } from '@/libs/swr';
|
9
9
|
import { aiProviderService } from '@/services/aiProvider';
|
10
|
+
import { useAiInfraStore } from '@/store/aiInfra';
|
10
11
|
|
11
12
|
import ModelList from '../../features/ModelList';
|
12
13
|
import ProviderConfig from '../../features/ProviderConfig';
|
13
14
|
|
14
15
|
const ClientMode = memo<{ id: string }>(({ id }) => {
|
16
|
+
const useFetchAiProviderItem = useAiInfraStore((s) => s.useFetchAiProviderItem);
|
17
|
+
useFetchAiProviderItem(id);
|
18
|
+
|
15
19
|
const { data, isLoading } = useClientDataSWR('get-client-provider', () =>
|
16
20
|
aiProviderService.getAiProviderById(id),
|
17
21
|
);
|
@@ -1,13 +1,16 @@
|
|
1
|
+
import {
|
2
|
+
chainPickEmoji,
|
3
|
+
chainSummaryAgentName,
|
4
|
+
chainSummaryDescription,
|
5
|
+
chainSummaryTags,
|
6
|
+
} from '@lobechat/prompts';
|
1
7
|
import { TraceNameMap, TracePayload, TraceTopicType } from '@lobechat/types';
|
2
8
|
import { getSingletonAnalyticsOptional } from '@lobehub/analytics';
|
3
9
|
import type { PartialDeep } from 'type-fest';
|
4
10
|
import { StateCreator } from 'zustand/vanilla';
|
5
11
|
|
6
|
-
import { chainPickEmoji } from '@/chains/pickEmoji';
|
7
|
-
import { chainSummaryAgentName } from '@/chains/summaryAgentName';
|
8
|
-
import { chainSummaryDescription } from '@/chains/summaryDescription';
|
9
|
-
import { chainSummaryTags } from '@/chains/summaryTags';
|
10
12
|
import { chatService } from '@/services/chat';
|
13
|
+
import { globalHelpers } from '@/store/global/helpers';
|
11
14
|
import { useUserStore } from '@/store/user';
|
12
15
|
import { systemAgentSelectors } from '@/store/user/slices/settings/selectors';
|
13
16
|
import { LobeAgentChatConfig, LobeAgentConfig } from '@/types/agent';
|
@@ -118,7 +121,10 @@ export const store: StateCreator<Store, [['zustand/devtools', never]]> = (set, g
|
|
118
121
|
updateLoadingState('description', loading);
|
119
122
|
},
|
120
123
|
onMessageHandle: streamUpdateMetaString('description'),
|
121
|
-
params: merge(
|
124
|
+
params: merge(
|
125
|
+
get().internal_getSystemAgentForMeta(),
|
126
|
+
chainSummaryDescription(systemRole, globalHelpers.getCurrentLanguage()),
|
127
|
+
),
|
122
128
|
trace: get().getCurrentTracePayload({ traceName: TraceNameMap.SummaryAgentDescription }),
|
123
129
|
});
|
124
130
|
},
|
@@ -145,7 +151,10 @@ export const store: StateCreator<Store, [['zustand/devtools', never]]> = (set, g
|
|
145
151
|
onMessageHandle: streamUpdateMetaArray('tags'),
|
146
152
|
params: merge(
|
147
153
|
get().internal_getSystemAgentForMeta(),
|
148
|
-
chainSummaryTags(
|
154
|
+
chainSummaryTags(
|
155
|
+
[meta.title, meta.description, systemRole].filter(Boolean).join(','),
|
156
|
+
globalHelpers.getCurrentLanguage(),
|
157
|
+
),
|
149
158
|
),
|
150
159
|
trace: get().getCurrentTracePayload({ traceName: TraceNameMap.SummaryAgentTags }),
|
151
160
|
});
|
@@ -172,7 +181,10 @@ export const store: StateCreator<Store, [['zustand/devtools', never]]> = (set, g
|
|
172
181
|
onMessageHandle: streamUpdateMetaString('title'),
|
173
182
|
params: merge(
|
174
183
|
get().internal_getSystemAgentForMeta(),
|
175
|
-
chainSummaryAgentName(
|
184
|
+
chainSummaryAgentName(
|
185
|
+
[meta.description, systemRole].filter(Boolean).join(','),
|
186
|
+
globalHelpers.getCurrentLanguage(),
|
187
|
+
),
|
176
188
|
),
|
177
189
|
trace: get().getCurrentTracePayload({ traceName: TraceNameMap.SummaryAgentTitle }),
|
178
190
|
});
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { ModelProvider } from '@lobechat/model-runtime';
|
2
|
+
import { chainAnswerWithContext } from '@lobechat/prompts';
|
2
3
|
import { TRPCError } from '@trpc/server';
|
3
4
|
import OpenAI from 'openai';
|
4
5
|
import { z } from 'zod';
|
5
6
|
|
6
|
-
import { chainAnswerWithContext } from '@/chains/answerWithContext';
|
7
7
|
import { DEFAULT_EMBEDDING_MODEL, DEFAULT_MODEL } from '@/const/settings';
|
8
8
|
import { ChunkModel } from '@/database/models/chunk';
|
9
9
|
import { EmbeddingModel } from '@/database/models/embedding';
|
@@ -1,7 +1,7 @@
|
|
1
|
+
import { chainSummaryHistory } from '@lobechat/prompts';
|
1
2
|
import { TraceNameMap } from '@lobechat/types';
|
2
3
|
import { StateCreator } from 'zustand/vanilla';
|
3
4
|
|
4
|
-
import { chainSummaryHistory } from '@/chains/summaryHistory';
|
5
5
|
import { chatService } from '@/services/chat';
|
6
6
|
import { topicService } from '@/services/topic';
|
7
7
|
import { ChatStore } from '@/store/chat';
|
@@ -1,6 +1,6 @@
|
|
1
|
+
import { chainRewriteQuery } from '@lobechat/prompts';
|
1
2
|
import { StateCreator } from 'zustand/vanilla';
|
2
3
|
|
3
|
-
import { chainRewriteQuery } from '@/chains/rewriteQuery';
|
4
4
|
import { chatService } from '@/services/chat';
|
5
5
|
import { ragService } from '@/services/rag';
|
6
6
|
import { useAgentStore } from '@/store/agent';
|
@@ -1,10 +1,10 @@
|
|
1
1
|
/* eslint-disable sort-keys-fix/sort-keys-fix, typescript-sort-keys/interface */
|
2
2
|
// Disable the auto sort key eslint rule to make the code more logic and readable
|
3
|
+
import { chainSummaryTitle } from '@lobechat/prompts';
|
3
4
|
import isEqual from 'fast-deep-equal';
|
4
5
|
import { SWRResponse, mutate } from 'swr';
|
5
6
|
import { StateCreator } from 'zustand/vanilla';
|
6
7
|
|
7
|
-
import { chainSummaryTitle } from '@/chains/summaryTitle';
|
8
8
|
import { LOADING_FLAT, THREAD_DRAFT_ID } from '@/const/message';
|
9
9
|
import { isDeprecatedEdition } from '@/const/version';
|
10
10
|
import { useClientDataSWR } from '@/libs/swr';
|
@@ -12,6 +12,7 @@ import { chatService } from '@/services/chat';
|
|
12
12
|
import { threadService } from '@/services/thread';
|
13
13
|
import { threadSelectors } from '@/store/chat/selectors';
|
14
14
|
import { ChatStore } from '@/store/chat/store';
|
15
|
+
import { globalHelpers } from '@/store/global/helpers';
|
15
16
|
import { useSessionStore } from '@/store/session';
|
16
17
|
import { useUserStore } from '@/store/user';
|
17
18
|
import { systemAgentSelectors } from '@/store/user/selectors';
|
@@ -280,7 +281,7 @@ export const chatThreadMessage: StateCreator<
|
|
280
281
|
|
281
282
|
internal_updateThreadTitleInSummary(threadId, output);
|
282
283
|
},
|
283
|
-
params: merge(threadConfig, chainSummaryTitle(messages)),
|
284
|
+
params: merge(threadConfig, chainSummaryTitle(messages, globalHelpers.getCurrentLanguage())),
|
284
285
|
});
|
285
286
|
},
|
286
287
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
/* eslint-disable sort-keys-fix/sort-keys-fix, typescript-sort-keys/interface */
|
2
2
|
// Note: To make the code more logic and readable, we just disable the auto sort key eslint rule
|
3
3
|
// DON'T REMOVE THE FIRST LINE
|
4
|
+
import { chainSummaryTitle } from '@lobechat/prompts';
|
4
5
|
import { TraceNameMap } from '@lobechat/types';
|
5
6
|
import isEqual from 'fast-deep-equal';
|
6
7
|
import { t } from 'i18next';
|
7
8
|
import useSWR, { SWRResponse, mutate } from 'swr';
|
8
9
|
import { StateCreator } from 'zustand/vanilla';
|
9
10
|
|
10
|
-
import { chainSummaryTitle } from '@/chains/summaryTitle';
|
11
11
|
import { message } from '@/components/AntdStaticMethods';
|
12
12
|
import { LOADING_FLAT } from '@/const/message';
|
13
13
|
import { useClientDataSWR } from '@/libs/swr';
|
@@ -16,6 +16,7 @@ import { messageService } from '@/services/message';
|
|
16
16
|
import { topicService } from '@/services/topic';
|
17
17
|
import { CreateTopicParams } from '@/services/topic/type';
|
18
18
|
import type { ChatStore } from '@/store/chat';
|
19
|
+
import { globalHelpers } from '@/store/global/helpers';
|
19
20
|
import { useUserStore } from '@/store/user';
|
20
21
|
import { systemAgentSelectors } from '@/store/user/selectors';
|
21
22
|
import { ChatMessage } from '@/types/message';
|
@@ -167,7 +168,7 @@ export const chatTopic: StateCreator<
|
|
167
168
|
|
168
169
|
internal_updateTopicTitleInSummary(topicId, output);
|
169
170
|
},
|
170
|
-
params: merge(topicConfig, chainSummaryTitle(messages)),
|
171
|
+
params: merge(topicConfig, chainSummaryTitle(messages, globalHelpers.getCurrentLanguage())),
|
171
172
|
trace: get().getCurrentTracePayload({ traceName: TraceNameMap.SummaryTopicTitle, topicId }),
|
172
173
|
});
|
173
174
|
},
|
@@ -1,8 +1,8 @@
|
|
1
|
+
import { chainLangDetect } from '@lobechat/prompts';
|
2
|
+
import { chainTranslate } from '@lobechat/prompts';
|
1
3
|
import { act, renderHook } from '@testing-library/react';
|
2
4
|
import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
3
5
|
|
4
|
-
import { chainLangDetect } from '@/chains/langDetect';
|
5
|
-
import { chainTranslate } from '@/chains/translate';
|
6
6
|
import { chatService } from '@/services/chat';
|
7
7
|
import { messageService } from '@/services/message';
|
8
8
|
import { messageMapKey } from '@/store/chat/utils/messageMapKey';
|