@nocobase/plugin-ai 2.0.0-beta.6 → 2.0.0-beta.7
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/dist/client/6a4c1ee12f864e38.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/collections/ai-employees.d.ts +1 -0
- package/dist/collections/ai-employees.js +4 -0
- package/dist/externalVersion.js +11 -11
- package/dist/locale/en-US.json +2 -0
- package/dist/locale/zh-CN.json +2 -0
- package/dist/node_modules/@langchain/anthropic/package.json +1 -1
- package/dist/node_modules/@langchain/core/package.json +1 -1
- package/dist/node_modules/@langchain/deepseek/package.json +1 -1
- package/dist/node_modules/@langchain/google-genai/LICENSE +6 -6
- package/dist/node_modules/@langchain/google-genai/dist/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/node_modules/@langchain/google-genai/dist/chat_models.cjs +680 -842
- package/dist/node_modules/@langchain/google-genai/dist/chat_models.d.cts +581 -0
- package/dist/node_modules/@langchain/google-genai/dist/chat_models.d.ts +196 -157
- package/dist/node_modules/@langchain/google-genai/dist/chat_models.js +678 -837
- package/dist/node_modules/@langchain/google-genai/dist/embeddings.cjs +97 -151
- package/dist/node_modules/@langchain/google-genai/dist/embeddings.d.cts +104 -0
- package/dist/node_modules/@langchain/google-genai/dist/embeddings.d.ts +76 -70
- package/dist/node_modules/@langchain/google-genai/dist/embeddings.js +93 -144
- package/dist/node_modules/@langchain/google-genai/dist/index.cjs +252 -18
- package/dist/node_modules/@langchain/google-genai/dist/index.d.cts +3 -0
- package/dist/node_modules/@langchain/google-genai/dist/index.d.ts +3 -2
- package/dist/node_modules/@langchain/google-genai/dist/index.js +4 -2
- package/dist/node_modules/@langchain/google-genai/dist/output_parsers.cjs +47 -75
- package/dist/node_modules/@langchain/google-genai/dist/output_parsers.js +47 -72
- package/dist/node_modules/@langchain/google-genai/dist/profiles.cjs +345 -0
- package/dist/node_modules/@langchain/google-genai/dist/profiles.js +344 -0
- package/dist/node_modules/@langchain/google-genai/dist/types.d.cts +17 -0
- package/dist/node_modules/@langchain/google-genai/dist/types.d.ts +16 -2
- package/dist/node_modules/@langchain/google-genai/dist/utils/common.cjs +419 -551
- package/dist/node_modules/@langchain/google-genai/dist/utils/common.js +417 -545
- package/dist/node_modules/@langchain/google-genai/dist/utils/tools.cjs +65 -102
- package/dist/node_modules/@langchain/google-genai/dist/utils/tools.js +64 -99
- package/dist/node_modules/@langchain/google-genai/dist/utils/zod_to_genai_parameters.cjs +31 -49
- package/dist/node_modules/@langchain/google-genai/dist/utils/zod_to_genai_parameters.js +29 -45
- package/dist/node_modules/@langchain/google-genai/package.json +1 -1
- package/dist/node_modules/@langchain/ollama/package.json +1 -1
- package/dist/node_modules/@langchain/openai/package.json +1 -1
- package/dist/node_modules/nodejs-snowflake/package.json +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/node_modules/zod-to-json-schema/package.json +1 -1
- package/dist/server/ai-employees/ai-employee.js +5 -2
- package/dist/server/llm-providers/anthropic.js +4 -5
- package/dist/server/llm-providers/provider.js +5 -1
- package/dist/server/manager/ai-chat-conversation.js +3 -2
- package/dist/server/manager/built-in-manager.js +3 -3
- package/dist/server/migrations/20260107000000-reset-builtin-about.d.ts +14 -0
- package/dist/server/migrations/20260107000000-reset-builtin-about.js +48 -0
- package/dist/server/resource/ai.js +8 -2
- package/dist/server/resource/aiEmployees.d.ts +0 -1
- package/dist/server/resource/aiEmployees.js +0 -15
- package/dist/server/types/ai-message.type.d.ts +2 -0
- package/package.json +3 -3
- package/dist/client/a7f0550514128d80.js +0 -10
- package/dist/node_modules/@langchain/google-genai/dist/output_parsers.d.ts +0 -20
- package/dist/node_modules/@langchain/google-genai/dist/types.cjs +0 -2
- package/dist/node_modules/@langchain/google-genai/dist/types.js +0 -1
- package/dist/node_modules/@langchain/google-genai/dist/utils/common.d.ts +0 -22
- package/dist/node_modules/@langchain/google-genai/dist/utils/tools.d.ts +0 -10
- package/dist/node_modules/@langchain/google-genai/dist/utils/zod_to_genai_parameters.d.ts +0 -14
- package/dist/node_modules/@langchain/google-genai/index.cjs +0 -252
- package/dist/node_modules/@langchain/google-genai/index.d.cts +0 -1
- package/dist/node_modules/@langchain/google-genai/index.d.ts +0 -1
- package/dist/node_modules/@langchain/google-genai/index.js +0 -1
|
@@ -2,148 +2,97 @@ import { GoogleGenerativeAI } from "@google/generative-ai";
|
|
|
2
2
|
import { getEnvironmentVariable } from "@langchain/core/utils/env";
|
|
3
3
|
import { Embeddings } from "@langchain/core/embeddings";
|
|
4
4
|
import { chunkArray } from "@langchain/core/utils/chunk_array";
|
|
5
|
+
|
|
6
|
+
//#region src/embeddings.ts
|
|
5
7
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
baseUrl: fields?.baseUrl,
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
_convertToContent(text) {
|
|
101
|
-
const cleanedText = this.stripNewLines ? text.replace(/\n/g, " ") : text;
|
|
102
|
-
return {
|
|
103
|
-
content: { role: "user", parts: [{ text: cleanedText }] },
|
|
104
|
-
taskType: this.taskType,
|
|
105
|
-
title: this.title,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
async _embedQueryContent(text) {
|
|
109
|
-
const req = this._convertToContent(text);
|
|
110
|
-
const res = await this.client.embedContent(req);
|
|
111
|
-
return res.embedding.values ?? [];
|
|
112
|
-
}
|
|
113
|
-
async _embedDocumentsContent(documents) {
|
|
114
|
-
const batchEmbedChunks = chunkArray(documents, this.maxBatchSize);
|
|
115
|
-
const batchEmbedRequests = batchEmbedChunks.map((chunk) => ({
|
|
116
|
-
requests: chunk.map((doc) => this._convertToContent(doc)),
|
|
117
|
-
}));
|
|
118
|
-
const responses = await Promise.allSettled(batchEmbedRequests.map((req) => this.client.batchEmbedContents(req)));
|
|
119
|
-
const embeddings = responses.flatMap((res, idx) => {
|
|
120
|
-
if (res.status === "fulfilled") {
|
|
121
|
-
return res.value.embeddings.map((e) => e.values || []);
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
return Array(batchEmbedChunks[idx].length).fill([]);
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
return embeddings;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Method that takes a document as input and returns a promise that
|
|
131
|
-
* resolves to an embedding for the document. It calls the _embedText
|
|
132
|
-
* method with the document as the input.
|
|
133
|
-
* @param document Document for which to generate an embedding.
|
|
134
|
-
* @returns Promise that resolves to an embedding for the input document.
|
|
135
|
-
*/
|
|
136
|
-
embedQuery(document) {
|
|
137
|
-
return this.caller.call(this._embedQueryContent.bind(this), document);
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Method that takes an array of documents as input and returns a promise
|
|
141
|
-
* that resolves to a 2D array of embeddings for each document. It calls
|
|
142
|
-
* the _embedText method for each document in the array.
|
|
143
|
-
* @param documents Array of documents for which to generate embeddings.
|
|
144
|
-
* @returns Promise that resolves to a 2D array of embeddings for each input document.
|
|
145
|
-
*/
|
|
146
|
-
embedDocuments(documents) {
|
|
147
|
-
return this.caller.call(this._embedDocumentsContent.bind(this), documents);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
8
|
+
* Class that extends the Embeddings class and provides methods for
|
|
9
|
+
* generating embeddings using the Google Palm API.
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const model = new GoogleGenerativeAIEmbeddings({
|
|
13
|
+
* apiKey: "<YOUR API KEY>",
|
|
14
|
+
* modelName: "embedding-001",
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* // Embed a single query
|
|
18
|
+
* const res = await model.embedQuery(
|
|
19
|
+
* "What would be a good company name for a company that makes colorful socks?"
|
|
20
|
+
* );
|
|
21
|
+
* console.log({ res });
|
|
22
|
+
*
|
|
23
|
+
* // Embed multiple documents
|
|
24
|
+
* const documentRes = await model.embedDocuments(["Hello world", "Bye bye"]);
|
|
25
|
+
* console.log({ documentRes });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
var GoogleGenerativeAIEmbeddings = class extends Embeddings {
|
|
29
|
+
apiKey;
|
|
30
|
+
modelName = "embedding-001";
|
|
31
|
+
model = "embedding-001";
|
|
32
|
+
taskType;
|
|
33
|
+
title;
|
|
34
|
+
stripNewLines = true;
|
|
35
|
+
maxBatchSize = 100;
|
|
36
|
+
client;
|
|
37
|
+
constructor(fields) {
|
|
38
|
+
super(fields ?? {});
|
|
39
|
+
this.modelName = fields?.model?.replace(/^models\//, "") ?? fields?.modelName?.replace(/^models\//, "") ?? this.modelName;
|
|
40
|
+
this.model = this.modelName;
|
|
41
|
+
this.taskType = fields?.taskType ?? this.taskType;
|
|
42
|
+
this.title = fields?.title ?? this.title;
|
|
43
|
+
if (this.title && this.taskType !== "RETRIEVAL_DOCUMENT") throw new Error("title can only be sepcified with TaskType.RETRIEVAL_DOCUMENT");
|
|
44
|
+
this.apiKey = fields?.apiKey ?? getEnvironmentVariable("GOOGLE_API_KEY");
|
|
45
|
+
if (!this.apiKey) throw new Error("Please set an API key for Google GenerativeAI in the environmentb variable GOOGLE_API_KEY or in the `apiKey` field of the GoogleGenerativeAIEmbeddings constructor");
|
|
46
|
+
this.client = new GoogleGenerativeAI(this.apiKey).getGenerativeModel({ model: this.model }, { baseUrl: fields?.baseUrl });
|
|
47
|
+
}
|
|
48
|
+
_convertToContent(text) {
|
|
49
|
+
const cleanedText = this.stripNewLines ? text.replace(/\n/g, " ") : text;
|
|
50
|
+
return {
|
|
51
|
+
content: {
|
|
52
|
+
role: "user",
|
|
53
|
+
parts: [{ text: cleanedText }]
|
|
54
|
+
},
|
|
55
|
+
taskType: this.taskType,
|
|
56
|
+
title: this.title
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
async _embedQueryContent(text) {
|
|
60
|
+
const req = this._convertToContent(text);
|
|
61
|
+
const res = await this.client.embedContent(req);
|
|
62
|
+
return res.embedding.values ?? [];
|
|
63
|
+
}
|
|
64
|
+
async _embedDocumentsContent(documents) {
|
|
65
|
+
const batchEmbedChunks = chunkArray(documents, this.maxBatchSize);
|
|
66
|
+
const batchEmbedRequests = batchEmbedChunks.map((chunk) => ({ requests: chunk.map((doc) => this._convertToContent(doc)) }));
|
|
67
|
+
const responses = await Promise.allSettled(batchEmbedRequests.map((req) => this.client.batchEmbedContents(req)));
|
|
68
|
+
const embeddings = responses.flatMap((res, idx) => {
|
|
69
|
+
if (res.status === "fulfilled") return res.value.embeddings.map((e) => e.values || []);
|
|
70
|
+
else return Array(batchEmbedChunks[idx].length).fill([]);
|
|
71
|
+
});
|
|
72
|
+
return embeddings;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Method that takes a document as input and returns a promise that
|
|
76
|
+
* resolves to an embedding for the document. It calls the _embedText
|
|
77
|
+
* method with the document as the input.
|
|
78
|
+
* @param document Document for which to generate an embedding.
|
|
79
|
+
* @returns Promise that resolves to an embedding for the input document.
|
|
80
|
+
*/
|
|
81
|
+
embedQuery(document) {
|
|
82
|
+
return this.caller.call(this._embedQueryContent.bind(this), document);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Method that takes an array of documents as input and returns a promise
|
|
86
|
+
* that resolves to a 2D array of embeddings for each document. It calls
|
|
87
|
+
* the _embedText method for each document in the array.
|
|
88
|
+
* @param documents Array of documents for which to generate embeddings.
|
|
89
|
+
* @returns Promise that resolves to a 2D array of embeddings for each input document.
|
|
90
|
+
*/
|
|
91
|
+
embedDocuments(documents) {
|
|
92
|
+
return this.caller.call(this._embedDocumentsContent.bind(this), documents);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
//#endregion
|
|
97
|
+
export { GoogleGenerativeAIEmbeddings };
|
|
98
|
+
//# sourceMappingURL=embeddings.js.map
|