@lobehub/chat 1.28.5 → 1.29.0

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.
Files changed (88) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/locales/ar/chat.json +1 -0
  3. package/locales/ar/setting.json +7 -2
  4. package/locales/bg-BG/chat.json +1 -0
  5. package/locales/bg-BG/setting.json +7 -2
  6. package/locales/de-DE/chat.json +1 -0
  7. package/locales/de-DE/setting.json +7 -2
  8. package/locales/en-US/chat.json +1 -0
  9. package/locales/en-US/setting.json +7 -2
  10. package/locales/es-ES/chat.json +1 -0
  11. package/locales/es-ES/setting.json +7 -2
  12. package/locales/fa-IR/chat.json +1 -0
  13. package/locales/fa-IR/setting.json +7 -2
  14. package/locales/fr-FR/chat.json +1 -0
  15. package/locales/fr-FR/setting.json +7 -2
  16. package/locales/it-IT/chat.json +1 -0
  17. package/locales/it-IT/setting.json +7 -2
  18. package/locales/ja-JP/chat.json +1 -0
  19. package/locales/ja-JP/setting.json +7 -2
  20. package/locales/ko-KR/chat.json +1 -0
  21. package/locales/ko-KR/setting.json +7 -2
  22. package/locales/nl-NL/chat.json +1 -0
  23. package/locales/nl-NL/setting.json +7 -2
  24. package/locales/pl-PL/chat.json +1 -0
  25. package/locales/pl-PL/setting.json +7 -2
  26. package/locales/pt-BR/chat.json +1 -0
  27. package/locales/pt-BR/setting.json +7 -2
  28. package/locales/ru-RU/chat.json +1 -0
  29. package/locales/ru-RU/setting.json +7 -2
  30. package/locales/tr-TR/chat.json +1 -0
  31. package/locales/tr-TR/setting.json +7 -2
  32. package/locales/vi-VN/chat.json +1 -0
  33. package/locales/vi-VN/setting.json +7 -2
  34. package/locales/zh-CN/chat.json +1 -0
  35. package/locales/zh-CN/setting.json +7 -2
  36. package/locales/zh-TW/chat.json +1 -0
  37. package/locales/zh-TW/setting.json +7 -2
  38. package/package.json +1 -1
  39. package/src/app/(main)/settings/system-agent/index.tsx +1 -0
  40. package/src/chains/__tests__/__snapshots__/summaryHistory.test.ts.snap +21 -0
  41. package/src/chains/__tests__/summaryHistory.test.ts +24 -0
  42. package/src/chains/summaryHistory.ts +19 -0
  43. package/src/const/settings/agent.ts +3 -1
  44. package/src/const/settings/systemAgent.ts +1 -0
  45. package/src/database/client/models/__tests__/session.test.ts +0 -1
  46. package/src/database/server/migrations/0011_add_topic_history_summary.sql +2 -0
  47. package/src/database/server/migrations/meta/0011_snapshot.json +3196 -0
  48. package/src/database/server/migrations/meta/_journal.json +7 -0
  49. package/src/database/server/models/__tests__/topic.test.ts +4 -0
  50. package/src/database/server/models/topic.ts +16 -0
  51. package/src/database/server/schemas/lobechat/topic.ts +3 -2
  52. package/src/features/AgentSetting/AgentChat/index.tsx +4 -18
  53. package/src/features/ChatInput/ActionBar/History.tsx +24 -21
  54. package/src/features/ChatInput/ActionBar/Token/TokenTag.tsx +22 -7
  55. package/src/features/Conversation/Actions/index.ts +2 -2
  56. package/src/features/Conversation/components/ChatItem/index.tsx +6 -6
  57. package/src/features/Conversation/components/History/index.tsx +71 -0
  58. package/src/features/Conversation/types/index.tsx +1 -1
  59. package/src/libs/next-auth/sso-providers/microsoft-entra-id-helper.ts +1 -1
  60. package/src/locales/default/chat.ts +1 -0
  61. package/src/locales/default/setting.ts +7 -2
  62. package/src/prompts/chatMessages/index.test.ts +94 -0
  63. package/src/prompts/chatMessages/index.ts +11 -0
  64. package/src/prompts/systemRole/index.ts +22 -0
  65. package/src/server/routers/lambda/topic.ts +7 -0
  66. package/src/services/__tests__/chat.test.ts +13 -61
  67. package/src/services/chat.ts +45 -11
  68. package/src/store/agent/slices/chat/__snapshots__/selectors.test.ts.snap +3 -1
  69. package/src/store/chat/helpers.ts +6 -2
  70. package/src/store/chat/slices/aiChat/actions/generateAIChat.ts +21 -8
  71. package/src/store/chat/slices/aiChat/actions/helpers.ts +9 -0
  72. package/src/store/chat/slices/aiChat/actions/index.ts +3 -1
  73. package/src/store/chat/slices/aiChat/actions/memory.ts +52 -0
  74. package/src/store/chat/slices/message/selectors.ts +1 -3
  75. package/src/store/chat/slices/topic/selectors.ts +24 -12
  76. package/src/store/chat/slices/{enchance → translate}/action.test.ts +0 -13
  77. package/src/store/chat/slices/{enchance → translate}/action.ts +5 -24
  78. package/src/store/chat/slices/tts/action.test.ts +63 -0
  79. package/src/store/chat/slices/tts/action.ts +35 -0
  80. package/src/store/chat/store.ts +6 -3
  81. package/src/store/file/reducers/uploadFileList.test.ts +197 -0
  82. package/src/store/user/slices/settings/selectors/__snapshots__/settings.test.ts.snap +3 -1
  83. package/src/store/user/slices/settings/selectors/systemAgent.ts +2 -0
  84. package/src/types/agent/index.ts +2 -4
  85. package/src/types/topic.ts +13 -0
  86. package/src/types/user/settings/systemAgent.ts +1 -0
  87. package/src/utils/tokenizer/client.ts +1 -1
  88. /package/src/features/Conversation/components/{ChatItem → History}/HistoryDivider.tsx +0 -0
@@ -175,8 +175,8 @@
175
175
  "desc": "對話過程中是否自動建立話題,僅在臨時話題中生效",
176
176
  "title": "自動建立話題"
177
177
  },
178
- "enableCompressThreshold": {
179
- "title": "是否開啟歷史訊息長度壓縮閾值"
178
+ "enableCompressHistory": {
179
+ "title": "開啟歷史消息自動總結"
180
180
  },
181
181
  "enableHistoryCount": {
182
182
  "alias": "不限制",
@@ -378,6 +378,11 @@
378
378
  "placeholder": "請輸入自訂提示詞",
379
379
  "title": "自訂提示詞"
380
380
  },
381
+ "historyCompress": {
382
+ "label": "會話歷史模型",
383
+ "modelDesc": "指定用於壓縮會話歷史的模型",
384
+ "title": "自動總結會話歷史"
385
+ },
381
386
  "queryRewrite": {
382
387
  "label": "提問重寫模型",
383
388
  "modelDesc": "指定用於優化用戶提問的模型",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "1.28.5",
3
+ "version": "1.29.0",
4
4
  "description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
5
5
  "keywords": [
6
6
  "framework",
@@ -12,6 +12,7 @@ const Page = () => {
12
12
  <>
13
13
  <SystemAgentForm systemAgentKey="topic" />
14
14
  <SystemAgentForm systemAgentKey="translation" />
15
+ <SystemAgentForm systemAgentKey="historyCompress" />
15
16
  <SystemAgentForm systemAgentKey="agentMeta" />
16
17
  {isServerMode && enableKnowledgeBase && (
17
18
  <SystemAgentForm
@@ -0,0 +1,21 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`chainSummaryHistory > should use the default model if the token count is below the GPT-3.5 limit 1`] = `
4
+ {
5
+ "messages": [
6
+ {
7
+ "content": "You're an assistant who's good at extracting key takeaways from conversations and summarizing them. Please summarize according to the user's needs. The content you need to summarize is located in the <chat_history> </chat_history> group of xml tags. The summary needs to maintain the original language.",
8
+ "role": "system",
9
+ },
10
+ {
11
+ "content": "<chat_history>
12
+ <assistant>Hello, how can I assist you?</assistant>
13
+ <user>I need help with my account.</user>
14
+ </chat_history>
15
+
16
+ Please summarize the above conversation and retain key information. The summarized content will be used as context for subsequent prompts, and should be limited to 400 tokens.",
17
+ "role": "user",
18
+ },
19
+ ],
20
+ }
21
+ `;
@@ -0,0 +1,24 @@
1
+ import { Mock, describe, expect, it, vi } from 'vitest';
2
+
3
+ import { chatHelpers } from '@/store/chat/helpers';
4
+ import { globalHelpers } from '@/store/user/helpers';
5
+ import { ChatMessage } from '@/types/message';
6
+ import { OpenAIChatMessage } from '@/types/openai/chat';
7
+
8
+ import { chainSummaryHistory } from '../summaryHistory';
9
+
10
+ describe('chainSummaryHistory', () => {
11
+ it('should use the default model if the token count is below the GPT-3.5 limit', async () => {
12
+ // Arrange
13
+ const messages = [
14
+ { content: 'Hello, how can I assist you?', role: 'assistant' },
15
+ { content: 'I need help with my account.', role: 'user' },
16
+ ] as ChatMessage[];
17
+
18
+ // Act
19
+ const result = chainSummaryHistory(messages);
20
+
21
+ // Assert
22
+ expect(result).toMatchSnapshot();
23
+ });
24
+ });
@@ -0,0 +1,19 @@
1
+ import { chatHistoryPrompts } from '@/prompts/chatMessages';
2
+ import { ChatMessage } from '@/types/message';
3
+ import { ChatStreamPayload } from '@/types/openai/chat';
4
+
5
+ export const chainSummaryHistory = (messages: ChatMessage[]): Partial<ChatStreamPayload> => ({
6
+ messages: [
7
+ {
8
+ content: `You're an assistant who's good at extracting key takeaways from conversations and summarizing them. Please summarize according to the user's needs. The content you need to summarize is located in the <chat_history> </chat_history> group of xml tags. The summary needs to maintain the original language.`,
9
+ role: 'system',
10
+ },
11
+ {
12
+ content: `${chatHistoryPrompts(messages)}
13
+
14
+ Please summarize the above conversation and retain key information. The summarized content will be used as context for subsequent prompts, and should be limited to 400 tokens.`,
15
+
16
+ role: 'user',
17
+ },
18
+ ],
19
+ });
@@ -17,7 +17,9 @@ export const DEFAULT_AGENT_CHAT_CONFIG: LobeAgentChatConfig = {
17
17
  autoCreateTopicThreshold: 2,
18
18
  displayMode: 'chat',
19
19
  enableAutoCreateTopic: true,
20
- historyCount: 1,
20
+ enableCompressHistory: true,
21
+ enableHistoryCount: true,
22
+ historyCount: 8,
21
23
  };
22
24
 
23
25
  export const DEFAULT_AGENT_CONFIG: LobeAgentConfig = {
@@ -22,6 +22,7 @@ export const DEFAULT_QUERY_REWRITE_SYSTEM_AGENT_ITEM: QueryRewriteSystemAgent =
22
22
 
23
23
  export const DEFAULT_SYSTEM_AGENT_CONFIG: UserSystemAgentConfig = {
24
24
  agentMeta: DEFAULT_SYSTEM_AGENT_ITEM,
25
+ historyCompress: DEFAULT_SYSTEM_AGENT_ITEM,
25
26
  queryRewrite: DEFAULT_QUERY_REWRITE_SYSTEM_AGENT_ITEM,
26
27
  topic: DEFAULT_SYSTEM_AGENT_ITEM,
27
28
  translation: DEFAULT_SYSTEM_AGENT_ITEM,
@@ -24,7 +24,6 @@ describe('SessionModel', () => {
24
24
  group: 'testGroup',
25
25
  meta: {},
26
26
  config: DEFAULT_AGENT_CONFIG,
27
- // ... other properties based on LobeAgentSession
28
27
  };
29
28
  });
30
29
 
@@ -0,0 +1,2 @@
1
+ ALTER TABLE "topics" ADD COLUMN "history_summary" text;--> statement-breakpoint
2
+ ALTER TABLE "topics" ADD COLUMN "metadata" jsonb;