@lobehub/chat 1.32.1 → 1.32.3

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/CHANGELOG.md CHANGED
@@ -2,6 +2,49 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 1.32.3](https://github.com/lobehub/lobe-chat/compare/v1.32.2...v1.32.3)
6
+
7
+ <sup>Released on **2024-11-20**</sup>
8
+
9
+ #### 💄 Styles
10
+
11
+ - **misc**: Add grok-vision-beta model, update Mistral model list, add `pixtral-large-latest`.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### Styles
19
+
20
+ - **misc**: Add grok-vision-beta model, closes [#4734](https://github.com/lobehub/lobe-chat/issues/4734) ([744ea30](https://github.com/lobehub/lobe-chat/commit/744ea30))
21
+ - **misc**: Update Mistral model list, add `pixtral-large-latest`, closes [#4744](https://github.com/lobehub/lobe-chat/issues/4744) ([7ee6fdd](https://github.com/lobehub/lobe-chat/commit/7ee6fdd))
22
+
23
+ </details>
24
+
25
+ <div align="right">
26
+
27
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
28
+
29
+ </div>
30
+
31
+ ### [Version 1.32.2](https://github.com/lobehub/lobe-chat/compare/v1.32.1...v1.32.2)
32
+
33
+ <sup>Released on **2024-11-19**</sup>
34
+
35
+ <br/>
36
+
37
+ <details>
38
+ <summary><kbd>Improvements and Fixes</kbd></summary>
39
+
40
+ </details>
41
+
42
+ <div align="right">
43
+
44
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
45
+
46
+ </div>
47
+
5
48
  ### [Version 1.32.1](https://github.com/lobehub/lobe-chat/compare/v1.32.0...v1.32.1)
6
49
 
7
50
  <sup>Released on **2024-11-19**</sup>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "1.32.1",
3
+ "version": "1.32.3",
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",
@@ -53,6 +53,20 @@ const Mistral: ModelProviderCard = {
53
53
  },
54
54
  tokens: 32_768,
55
55
  },
56
+ {
57
+ description:
58
+ 'Pixtral Large 是一款拥有 1240 亿参数的开源多模态模型,基于 Mistral Large 2 构建。这是我们多模态家族中的第二款模型,展现了前沿水平的图像理解能力。',
59
+ displayName: 'Pixtral Large',
60
+ enabled: true,
61
+ functionCall: true,
62
+ id: 'pixtral-large-latest',
63
+ pricing: {
64
+ input: 2,
65
+ output: 6,
66
+ },
67
+ tokens: 128_000,
68
+ vision: true,
69
+ },
56
70
  {
57
71
  description:
58
72
  'Pixtral 模型在图表和图理解、文档问答、多模态推理和指令遵循等任务上表现出强大的能力,能够以自然分辨率和宽高比摄入图像,还能够在长达 128K 令牌的长上下文窗口中处理任意数量的图像。',
@@ -15,6 +15,19 @@ const XAI: ModelProviderCard = {
15
15
  },
16
16
  tokens: 131_072,
17
17
  },
18
+ {
19
+ description: '最新的图像理解模型,可以处理各种各样的视觉信息,包括文档、图表、截图和照片等。',
20
+ displayName: 'Grok Vision Beta',
21
+ enabled: true,
22
+ functionCall: true,
23
+ id: 'grok-vision-beta',
24
+ pricing: {
25
+ input: 5,
26
+ output: 15,
27
+ },
28
+ tokens: 8192,
29
+ vision: true,
30
+ },
18
31
  ],
19
32
  checkModel: 'grok-beta',
20
33
  description:
@@ -23,7 +36,10 @@ const XAI: ModelProviderCard = {
23
36
  modelList: { showModelFetcher: true },
24
37
  modelsUrl: 'https://docs.x.ai/docs#models',
25
38
  name: 'xAI',
26
- url: 'https://console.x.ai',
39
+ proxyUrl: {
40
+ placeholder: 'https://api.x.ai/v1',
41
+ },
42
+ url: 'https://x.ai/api',
27
43
  };
28
44
 
29
45
  export default XAI;
@@ -1,5 +1,6 @@
1
1
  import { asc, count, eq, ilike, inArray, notExists, or, sum } from 'drizzle-orm';
2
2
  import { and, desc, like } from 'drizzle-orm/expressions';
3
+ import type { PgTransaction } from 'drizzle-orm/pg-core';
3
4
 
4
5
  import { serverDBEnv } from '@/config/db';
5
6
  import { serverDB } from '@/database/server/core/db';
@@ -9,6 +10,9 @@ import {
9
10
  FileItem,
10
11
  NewFile,
11
12
  NewGlobalFile,
13
+ chunks,
14
+ embeddings,
15
+ fileChunks,
12
16
  files,
13
17
  globalFiles,
14
18
  knowledgeBaseFiles,
@@ -68,6 +72,10 @@ export class FileModel {
68
72
  const fileHash = file.fileHash!;
69
73
 
70
74
  return await serverDB.transaction(async (trx) => {
75
+ // 1. 删除相关的 chunks
76
+ await this.deleteFileChunks(trx as any, [id]);
77
+
78
+ // 2. 删除文件记录
71
79
  await trx.delete(files).where(and(eq(files.id, id), eq(files.userId, this.userId)));
72
80
 
73
81
  const result = await trx
@@ -107,6 +115,9 @@ export class FileModel {
107
115
  const hashList = fileList.map((file) => file.fileHash!);
108
116
 
109
117
  return await serverDB.transaction(async (trx) => {
118
+ // 1. 删除相关的 chunks
119
+ await this.deleteFileChunks(trx as any, ids);
120
+
110
121
  // delete the files
111
122
  await trx.delete(files).where(and(inArray(files.id, ids), eq(files.userId, this.userId)));
112
123
 
@@ -289,4 +300,30 @@ export class FileModel {
289
300
  ),
290
301
  });
291
302
  }
303
+
304
+ // 抽象出通用的删除 chunks 方法
305
+ private async deleteFileChunks(trx: PgTransaction<any>, fileIds: string[]) {
306
+ const BATCH_SIZE = 1000; // 每批处理的数量
307
+
308
+ // 1. 获取所有关联的 chunk IDs
309
+ const relatedChunks = await trx
310
+ .select({ chunkId: fileChunks.chunkId })
311
+ .from(fileChunks)
312
+ .where(inArray(fileChunks.fileId, fileIds));
313
+
314
+ const chunkIds = relatedChunks.map((c) => c.chunkId).filter(Boolean) as string[];
315
+
316
+ if (chunkIds.length === 0) return;
317
+
318
+ // 2. 分批处理删除
319
+ for (let i = 0; i < chunkIds.length; i += BATCH_SIZE) {
320
+ const batchChunkIds = chunkIds.slice(i, i + BATCH_SIZE);
321
+
322
+ await trx.delete(embeddings).where(inArray(embeddings.chunkId, batchChunkIds));
323
+
324
+ await trx.delete(chunks).where(inArray(chunks.id, batchChunkIds));
325
+ }
326
+
327
+ return chunkIds;
328
+ }
292
329
  }
@@ -154,8 +154,6 @@ export const fileRouter = router({
154
154
  removeFile: fileProcedure.input(z.object({ id: z.string() })).mutation(async ({ input, ctx }) => {
155
155
  const file = await ctx.fileModel.delete(input.id);
156
156
 
157
- // delete the orphan chunks
158
- await ctx.chunkModel.deleteOrphanChunks();
159
157
  if (!file) return;
160
158
 
161
159
  // delele the file from remove from S3 if it is not used by other files
@@ -187,9 +185,6 @@ export const fileRouter = router({
187
185
  .mutation(async ({ input, ctx }) => {
188
186
  const needToRemoveFileList = await ctx.fileModel.deleteMany(input.ids);
189
187
 
190
- // delete the orphan chunks
191
- await ctx.chunkModel.deleteOrphanChunks();
192
-
193
188
  if (!needToRemoveFileList || needToRemoveFileList.length === 0) return;
194
189
 
195
190
  // remove from S3