@lobehub/chat 1.26.14 → 1.26.15
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 +25 -0
- package/package.json +1 -1
- package/src/database/server/models/user.ts +6 -0
- package/src/libs/agent-runtime/BaseAI.ts +3 -3
- package/src/libs/agent-runtime/types/embeddings.ts +6 -16
- package/src/libs/agent-runtime/utils/openaiCompatibleFactory/index.ts +3 -3
- package/src/libs/langchain/loaders/index.ts +1 -1
- package/src/server/routers/async/file.ts +3 -3
- package/src/server/routers/async/ragEval.ts +1 -1
- package/src/server/routers/lambda/chunk.ts +2 -2
package/CHANGELOG.md
CHANGED
@@ -2,6 +2,31 @@
|
|
2
2
|
|
3
3
|
# Changelog
|
4
4
|
|
5
|
+
### [Version 1.26.15](https://github.com/lobehub/lobe-chat/compare/v1.26.14...v1.26.15)
|
6
|
+
|
7
|
+
<sup>Released on **2024-10-31**</sup>
|
8
|
+
|
9
|
+
#### ♻ Code Refactoring
|
10
|
+
|
11
|
+
- **misc**: Refactor embedding as plain vector array.
|
12
|
+
|
13
|
+
<br/>
|
14
|
+
|
15
|
+
<details>
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
17
|
+
|
18
|
+
#### Code refactoring
|
19
|
+
|
20
|
+
- **misc**: Refactor embedding as plain vector array, closes [#4551](https://github.com/lobehub/lobe-chat/issues/4551) ([e2cae36](https://github.com/lobehub/lobe-chat/commit/e2cae36))
|
21
|
+
|
22
|
+
</details>
|
23
|
+
|
24
|
+
<div align="right">
|
25
|
+
|
26
|
+
[](#readme-top)
|
27
|
+
|
28
|
+
</div>
|
29
|
+
|
5
30
|
### [Version 1.26.14](https://github.com/lobehub/lobe-chat/compare/v1.26.13...v1.26.14)
|
6
31
|
|
7
32
|
<sup>Released on **2024-10-30**</sup>
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@lobehub/chat",
|
3
|
-
"version": "1.26.
|
3
|
+
"version": "1.26.15",
|
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",
|
@@ -19,6 +19,12 @@ export class UserNotFoundError extends TRPCError {
|
|
19
19
|
|
20
20
|
export class UserModel {
|
21
21
|
static createUser = async (params: NewUser) => {
|
22
|
+
// if user already exists, skip creation
|
23
|
+
if (params.id) {
|
24
|
+
const user = await serverDB.query.users.findFirst({ where: eq(users.id, params.id) });
|
25
|
+
if (!!user) return;
|
26
|
+
}
|
27
|
+
|
22
28
|
const [user] = await serverDB
|
23
29
|
.insert(users)
|
24
30
|
.values({ ...params })
|
@@ -5,7 +5,7 @@ import { ChatModelCard } from '@/types/llm';
|
|
5
5
|
import {
|
6
6
|
ChatCompetitionOptions,
|
7
7
|
ChatStreamPayload,
|
8
|
-
|
8
|
+
Embeddings,
|
9
9
|
EmbeddingsOptions,
|
10
10
|
EmbeddingsPayload,
|
11
11
|
TextToImagePayload,
|
@@ -17,7 +17,7 @@ export interface LobeRuntimeAI {
|
|
17
17
|
baseURL?: string;
|
18
18
|
chat(payload: ChatStreamPayload, options?: ChatCompetitionOptions): Promise<Response>;
|
19
19
|
|
20
|
-
embeddings?(payload: EmbeddingsPayload, options?: EmbeddingsOptions): Promise<
|
20
|
+
embeddings?(payload: EmbeddingsPayload, options?: EmbeddingsOptions): Promise<Embeddings[]>;
|
21
21
|
|
22
22
|
models?(): Promise<any>;
|
23
23
|
|
@@ -40,5 +40,5 @@ export abstract class LobeOpenAICompatibleRuntime {
|
|
40
40
|
abstract embeddings(
|
41
41
|
payload: EmbeddingsPayload,
|
42
42
|
options?: EmbeddingsOptions,
|
43
|
-
): Promise<
|
43
|
+
): Promise<Embeddings[]>;
|
44
44
|
}
|
@@ -25,19 +25,9 @@ export interface EmbeddingsOptions {
|
|
25
25
|
user?: string;
|
26
26
|
}
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
embedding: Array<number>;
|
35
|
-
/**
|
36
|
-
* The index of the embedding in the list of embeddings.
|
37
|
-
*/
|
38
|
-
index: number;
|
39
|
-
/**
|
40
|
-
* The object type, which is always "embedding".
|
41
|
-
*/
|
42
|
-
object: 'embedding';
|
43
|
-
}
|
28
|
+
/**
|
29
|
+
* The embedding vector, which is a list of floats. The length of vector depends on
|
30
|
+
* the model as listed in the
|
31
|
+
* [embedding guide](https://platform.openai.com/docs/guides/embeddings).
|
32
|
+
*/
|
33
|
+
export type Embeddings = Array<number>;
|
@@ -10,7 +10,7 @@ import {
|
|
10
10
|
ChatCompetitionOptions,
|
11
11
|
ChatCompletionErrorPayload,
|
12
12
|
ChatStreamPayload,
|
13
|
-
|
13
|
+
Embeddings,
|
14
14
|
EmbeddingsOptions,
|
15
15
|
EmbeddingsPayload,
|
16
16
|
TextToImagePayload,
|
@@ -271,14 +271,14 @@ export const LobeOpenAICompatibleFactory = <T extends Record<string, any> = any>
|
|
271
271
|
async embeddings(
|
272
272
|
payload: EmbeddingsPayload,
|
273
273
|
options?: EmbeddingsOptions,
|
274
|
-
): Promise<
|
274
|
+
): Promise<Embeddings[]> {
|
275
275
|
try {
|
276
276
|
const res = await this.client.embeddings.create(
|
277
277
|
{ ...payload, user: options?.user },
|
278
278
|
{ headers: options?.headers, signal: options?.signal },
|
279
279
|
);
|
280
280
|
|
281
|
-
return res.data;
|
281
|
+
return res.data.map((item) => item.embedding);
|
282
282
|
} catch (error) {
|
283
283
|
throw this.handleError(error);
|
284
284
|
}
|
@@ -61,7 +61,7 @@ export class ChunkingLoader {
|
|
61
61
|
|
62
62
|
default: {
|
63
63
|
throw new Error(
|
64
|
-
|
64
|
+
`Unsupported file type [${type}], please check your file is supported, or create report issue here: https://github.com/lobehub/lobe-chat/discussions/3550`,
|
65
65
|
);
|
66
66
|
}
|
67
67
|
}
|
@@ -105,9 +105,9 @@ export const fileRouter = router({
|
|
105
105
|
console.timeEnd(`任务[${number}]: embeddings`);
|
106
106
|
|
107
107
|
const items: NewEmbeddingsItem[] =
|
108
|
-
embeddings?.map((e) => ({
|
109
|
-
chunkId: chunks[
|
110
|
-
embeddings: e
|
108
|
+
embeddings?.map((e, idx) => ({
|
109
|
+
chunkId: chunks[idx].id,
|
110
|
+
embeddings: e,
|
111
111
|
fileId: input.fileId,
|
112
112
|
model: input.model,
|
113
113
|
})) || [];
|
@@ -120,7 +120,7 @@ export const chunkRouter = router({
|
|
120
120
|
console.timeEnd('embedding');
|
121
121
|
|
122
122
|
return ctx.chunkModel.semanticSearch({
|
123
|
-
embedding: embeddings![0]
|
123
|
+
embedding: embeddings![0],
|
124
124
|
fileIds: input.fileIds,
|
125
125
|
query: input.query,
|
126
126
|
});
|
@@ -147,7 +147,7 @@ export const chunkRouter = router({
|
|
147
147
|
model: input.model || DEFAULT_EMBEDDING_MODEL,
|
148
148
|
});
|
149
149
|
|
150
|
-
embedding = embeddings![0]
|
150
|
+
embedding = embeddings![0];
|
151
151
|
const embeddingsId = await ctx.embeddingModel.create({
|
152
152
|
embeddings: embedding,
|
153
153
|
model: input.model,
|