mem0ai 3.0.8 → 3.0.9
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/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -3
- package/dist/index.mjs.map +1 -1
- package/dist/oss/index.d.mts +28 -1
- package/dist/oss/index.d.ts +28 -1
- package/dist/oss/index.js +55 -23
- package/dist/oss/index.js.map +1 -1
- package/dist/oss/index.mjs +55 -23
- package/dist/oss/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/oss/index.mjs
CHANGED
|
@@ -41,7 +41,10 @@ var MemoryConfigSchema = z.object({
|
|
|
41
41
|
modelProperties: z.record(z.string(), z.any()).optional(),
|
|
42
42
|
baseURL: z.string().optional(),
|
|
43
43
|
url: z.string().optional(),
|
|
44
|
-
timeout: z.number().optional()
|
|
44
|
+
timeout: z.number().optional(),
|
|
45
|
+
temperature: z.number().optional(),
|
|
46
|
+
topP: z.number().optional(),
|
|
47
|
+
maxTokens: z.number().optional()
|
|
45
48
|
})
|
|
46
49
|
}),
|
|
47
50
|
historyDbPath: z.string().optional(),
|
|
@@ -331,25 +334,54 @@ var OpenAIStructuredLLM = class {
|
|
|
331
334
|
import Anthropic from "@anthropic-ai/sdk";
|
|
332
335
|
var AnthropicLLM = class {
|
|
333
336
|
constructor(config) {
|
|
337
|
+
var _a2, _b2;
|
|
334
338
|
const apiKey = config.apiKey || process.env.ANTHROPIC_API_KEY;
|
|
335
339
|
if (!apiKey) {
|
|
336
340
|
throw new Error("Anthropic API key is required");
|
|
337
341
|
}
|
|
338
342
|
this.client = new Anthropic({ apiKey });
|
|
339
|
-
this.model = config.model || "claude-
|
|
343
|
+
this.model = config.model || "claude-sonnet-4-6";
|
|
344
|
+
this.maxTokens = (_a2 = config.maxTokens) != null ? _a2 : 2e3;
|
|
345
|
+
this.temperature = (_b2 = config.temperature) != null ? _b2 : 0.1;
|
|
346
|
+
this.topP = config.topP;
|
|
340
347
|
}
|
|
341
|
-
async generateResponse(messages, responseFormat) {
|
|
348
|
+
async generateResponse(messages, responseFormat, tools) {
|
|
342
349
|
const systemMessage = messages.find((msg) => msg.role === "system");
|
|
343
350
|
const otherMessages = messages.filter((msg) => msg.role !== "system");
|
|
344
|
-
const
|
|
351
|
+
const params = {
|
|
345
352
|
model: this.model,
|
|
346
353
|
messages: otherMessages.map((msg) => ({
|
|
347
354
|
role: msg.role,
|
|
348
355
|
content: typeof msg.content === "string" ? msg.content : msg.content.image_url.url
|
|
349
356
|
})),
|
|
350
357
|
system: typeof (systemMessage == null ? void 0 : systemMessage.content) === "string" ? systemMessage.content : void 0,
|
|
351
|
-
max_tokens:
|
|
352
|
-
}
|
|
358
|
+
max_tokens: this.maxTokens
|
|
359
|
+
};
|
|
360
|
+
if (this.temperature !== void 0) {
|
|
361
|
+
params.temperature = this.temperature;
|
|
362
|
+
} else if (this.topP !== void 0) {
|
|
363
|
+
params.top_p = this.topP;
|
|
364
|
+
}
|
|
365
|
+
if (tools) {
|
|
366
|
+
params.tools = tools;
|
|
367
|
+
params.tool_choice = { type: "auto" };
|
|
368
|
+
}
|
|
369
|
+
const response = await this.client.messages.create(params);
|
|
370
|
+
if (tools) {
|
|
371
|
+
let content = "";
|
|
372
|
+
const toolCalls = [];
|
|
373
|
+
for (const block of response.content) {
|
|
374
|
+
if (block.type === "text") {
|
|
375
|
+
content = block.text;
|
|
376
|
+
} else if (block.type === "tool_use") {
|
|
377
|
+
toolCalls.push({
|
|
378
|
+
name: block.name,
|
|
379
|
+
arguments: JSON.stringify(block.input)
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
return { content, role: "assistant", toolCalls };
|
|
384
|
+
}
|
|
353
385
|
const firstBlock = response.content[0];
|
|
354
386
|
if (firstBlock.type === "text") {
|
|
355
387
|
return firstBlock.text;
|
|
@@ -359,10 +391,10 @@ var AnthropicLLM = class {
|
|
|
359
391
|
}
|
|
360
392
|
async generateChat(messages) {
|
|
361
393
|
const response = await this.generateResponse(messages);
|
|
362
|
-
|
|
363
|
-
content: response,
|
|
364
|
-
|
|
365
|
-
|
|
394
|
+
if (typeof response === "string") {
|
|
395
|
+
return { content: response, role: "assistant" };
|
|
396
|
+
}
|
|
397
|
+
return response;
|
|
366
398
|
}
|
|
367
399
|
};
|
|
368
400
|
|
|
@@ -4994,7 +5026,7 @@ var ConfigManager = class {
|
|
|
4994
5026
|
llm: {
|
|
4995
5027
|
provider: ((_c = userConfig.llm) == null ? void 0 : _c.provider) || DEFAULT_MEMORY_CONFIG.llm.provider,
|
|
4996
5028
|
config: (() => {
|
|
4997
|
-
var _a3, _b3, _c2, _d2;
|
|
5029
|
+
var _a3, _b3, _c2, _d2, _e2, _f2, _g2;
|
|
4998
5030
|
const defaultConf = DEFAULT_MEMORY_CONFIG.llm.config;
|
|
4999
5031
|
const userConf = (_a3 = userConfig.llm) == null ? void 0 : _a3.config;
|
|
5000
5032
|
let finalModel = defaultConf.model;
|
|
@@ -5004,12 +5036,19 @@ var ConfigManager = class {
|
|
|
5004
5036
|
finalModel = userConf.model;
|
|
5005
5037
|
}
|
|
5006
5038
|
const llmBaseURL = (_d2 = (_c2 = (_b3 = userConf == null ? void 0 : userConf.baseURL) != null ? _b3 : userConf == null ? void 0 : userConf.lmstudio_base_url) != null ? _c2 : userConf == null ? void 0 : userConf.url) != null ? _d2 : defaultConf.baseURL;
|
|
5039
|
+
const llmRaw = userConf;
|
|
5040
|
+
const temperature = (_e2 = userConf == null ? void 0 : userConf.temperature) != null ? _e2 : llmRaw == null ? void 0 : llmRaw.temperature;
|
|
5041
|
+
const topP = (_f2 = userConf == null ? void 0 : userConf.topP) != null ? _f2 : llmRaw == null ? void 0 : llmRaw.top_p;
|
|
5042
|
+
const maxTokens = (_g2 = userConf == null ? void 0 : userConf.maxTokens) != null ? _g2 : llmRaw == null ? void 0 : llmRaw.max_tokens;
|
|
5007
5043
|
return {
|
|
5008
5044
|
baseURL: llmBaseURL,
|
|
5009
5045
|
url: userConf == null ? void 0 : userConf.url,
|
|
5010
5046
|
apiKey: (userConf == null ? void 0 : userConf.apiKey) !== void 0 ? userConf.apiKey : defaultConf.apiKey,
|
|
5011
5047
|
model: finalModel,
|
|
5012
|
-
modelProperties: (userConf == null ? void 0 : userConf.modelProperties) !== void 0 ? userConf.modelProperties : defaultConf.modelProperties
|
|
5048
|
+
modelProperties: (userConf == null ? void 0 : userConf.modelProperties) !== void 0 ? userConf.modelProperties : defaultConf.modelProperties,
|
|
5049
|
+
temperature,
|
|
5050
|
+
topP,
|
|
5051
|
+
maxTokens
|
|
5013
5052
|
};
|
|
5014
5053
|
})()
|
|
5015
5054
|
},
|
|
@@ -5075,7 +5114,7 @@ var parse_vision_messages = async (messages) => {
|
|
|
5075
5114
|
};
|
|
5076
5115
|
|
|
5077
5116
|
// src/oss/src/utils/telemetry.ts
|
|
5078
|
-
var version = true ? "3.0.
|
|
5117
|
+
var version = true ? "3.0.9" : "dev";
|
|
5079
5118
|
var MEM0_TELEMETRY = true;
|
|
5080
5119
|
var _a, _b;
|
|
5081
5120
|
try {
|
|
@@ -8374,20 +8413,13 @@ var Memory = class _Memory {
|
|
|
8374
8413
|
const prevValue = existingMemory.payload.data;
|
|
8375
8414
|
const embedding = existingEmbeddings[data] || await this.embedder.embed(data);
|
|
8376
8415
|
const newMetadata = {
|
|
8416
|
+
...existingMemory.payload,
|
|
8377
8417
|
...metadata,
|
|
8378
8418
|
data,
|
|
8379
8419
|
hash: createHash("md5").update(data).digest("hex"),
|
|
8420
|
+
textLemmatized: lemmatizeForBm25(data),
|
|
8380
8421
|
createdAt: existingMemory.payload.createdAt,
|
|
8381
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
8382
|
-
...existingMemory.payload.user_id && {
|
|
8383
|
-
user_id: existingMemory.payload.user_id
|
|
8384
|
-
},
|
|
8385
|
-
...existingMemory.payload.agent_id && {
|
|
8386
|
-
agent_id: existingMemory.payload.agent_id
|
|
8387
|
-
},
|
|
8388
|
-
...existingMemory.payload.run_id && {
|
|
8389
|
-
run_id: existingMemory.payload.run_id
|
|
8390
|
-
}
|
|
8422
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
8391
8423
|
};
|
|
8392
8424
|
await this.vectorStore.update(memoryId, embedding, newMetadata);
|
|
8393
8425
|
await this.db.addHistory(
|