mem0ai 2.1.15 → 2.1.16-patch.1

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.
@@ -24,7 +24,8 @@ var MemoryConfigSchema = z.object({
24
24
  provider: z.string(),
25
25
  config: z.object({
26
26
  apiKey: z.string(),
27
- model: z.string().optional()
27
+ model: z.string().optional(),
28
+ modelProperties: z.record(z.string(), z.any()).optional()
28
29
  })
29
30
  }),
30
31
  historyDbPath: z.string().optional(),
@@ -310,6 +311,86 @@ var GroqLLM = class {
310
311
  }
311
312
  };
312
313
 
314
+ // src/oss/src/llms/mistral.ts
315
+ import { Mistral } from "@mistralai/mistralai";
316
+ var MistralLLM = class {
317
+ constructor(config) {
318
+ if (!config.apiKey) {
319
+ throw new Error("Mistral API key is required");
320
+ }
321
+ this.client = new Mistral({
322
+ apiKey: config.apiKey
323
+ });
324
+ this.model = config.model || "mistral-tiny-latest";
325
+ }
326
+ // Helper function to convert content to string
327
+ contentToString(content) {
328
+ if (typeof content === "string") {
329
+ return content;
330
+ }
331
+ if (Array.isArray(content)) {
332
+ return content.map((chunk) => {
333
+ if (chunk.type === "text") {
334
+ return chunk.text;
335
+ } else {
336
+ return JSON.stringify(chunk);
337
+ }
338
+ }).join("");
339
+ }
340
+ return String(content || "");
341
+ }
342
+ async generateResponse(messages, responseFormat, tools) {
343
+ const response = await this.client.chat.complete({
344
+ model: this.model,
345
+ messages: messages.map((msg) => ({
346
+ role: msg.role,
347
+ content: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content)
348
+ })),
349
+ ...tools && { tools },
350
+ ...responseFormat && { response_format: responseFormat }
351
+ });
352
+ if (!response || !response.choices || response.choices.length === 0) {
353
+ return "";
354
+ }
355
+ const message = response.choices[0].message;
356
+ if (!message) {
357
+ return "";
358
+ }
359
+ if (message.toolCalls && message.toolCalls.length > 0) {
360
+ return {
361
+ content: this.contentToString(message.content),
362
+ role: message.role || "assistant",
363
+ toolCalls: message.toolCalls.map((call) => ({
364
+ name: call.function.name,
365
+ arguments: typeof call.function.arguments === "string" ? call.function.arguments : JSON.stringify(call.function.arguments)
366
+ }))
367
+ };
368
+ }
369
+ return this.contentToString(message.content);
370
+ }
371
+ async generateChat(messages) {
372
+ const formattedMessages = messages.map((msg) => ({
373
+ role: msg.role,
374
+ content: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content)
375
+ }));
376
+ const response = await this.client.chat.complete({
377
+ model: this.model,
378
+ messages: formattedMessages
379
+ });
380
+ if (!response || !response.choices || response.choices.length === 0) {
381
+ return {
382
+ content: "",
383
+ role: "assistant"
384
+ };
385
+ }
386
+ const message = response.choices[0].message;
387
+ return {
388
+ content: this.contentToString(message.content),
389
+ role: message.role || "assistant"
390
+ };
391
+ }
392
+ };
393
+
313
394
  // src/oss/src/vector_stores/memory.ts
314
395
  import sqlite3 from "sqlite3";
315
396
  import path from "path";
@@ -1770,6 +1851,67 @@ var GoogleLLM = class {
1770
1851
  }
1771
1852
  };
1772
1853
 
1854
+ // src/oss/src/llms/azure.ts
1855
+ import { AzureOpenAI } from "openai";
1856
+ var AzureOpenAILLM = class {
1857
+ constructor(config) {
1858
+ var _a2;
1859
+ if (!config.apiKey || !((_a2 = config.modelProperties) == null ? void 0 : _a2.endpoint)) {
1860
+ throw new Error("Azure OpenAI requires both API key and endpoint");
1861
+ }
1862
+ const { endpoint, ...rest } = config.modelProperties;
1863
+ this.client = new AzureOpenAI({
1864
+ apiKey: config.apiKey,
1865
+ endpoint,
1866
+ ...rest
1867
+ });
1868
+ this.model = config.model || "gpt-4";
1869
+ }
1870
+ async generateResponse(messages, responseFormat, tools) {
1871
+ const completion = await this.client.chat.completions.create({
1872
+ messages: messages.map((msg) => {
1873
+ const role = msg.role;
1874
+ return {
1875
+ role,
1876
+ content: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content)
1877
+ };
1878
+ }),
1879
+ model: this.model,
1880
+ response_format: responseFormat,
1881
+ ...tools && { tools, tool_choice: "auto" }
1882
+ });
1883
+ const response = completion.choices[0].message;
1884
+ if (response.tool_calls) {
1885
+ return {
1886
+ content: response.content || "",
1887
+ role: response.role,
1888
+ toolCalls: response.tool_calls.map((call) => ({
1889
+ name: call.function.name,
1890
+ arguments: call.function.arguments
1891
+ }))
1892
+ };
1893
+ }
1894
+ return response.content || "";
1895
+ }
1896
+ async generateChat(messages) {
1897
+ const completion = await this.client.chat.completions.create({
1898
+ messages: messages.map((msg) => {
1899
+ const role = msg.role;
1900
+ return {
1901
+ role,
1902
+ content: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content)
1903
+ };
1904
+ }),
1905
+ model: this.model
1906
+ });
1907
+ const response = completion.choices[0].message;
1908
+ return {
1909
+ content: response.content || "",
1910
+ role: response.role
1911
+ };
1912
+ }
1913
+ };
1914
+
1773
1915
  // src/oss/src/utils/factory.ts
1774
1916
  var EmbedderFactory = class {
1775
1917
  static create(provider, config) {
@@ -1800,6 +1942,10 @@ var LLMFactory = class {
1800
1942
  return new OllamaLLM(config);
1801
1943
  case "google":
1802
1944
  return new GoogleLLM(config);
1945
+ case "azure_openai":
1946
+ return new AzureOpenAILLM(config);
1947
+ case "mistral":
1948
+ return new MistralLLM(config);
1803
1949
  default:
1804
1950
  throw new Error(`Unsupported LLM provider: ${provider}`);
1805
1951
  }
@@ -2143,7 +2289,7 @@ var DEFAULT_MEMORY_CONFIG = {
2143
2289
  // src/oss/src/config/manager.ts
2144
2290
  var ConfigManager = class {
2145
2291
  static mergeConfig(userConfig = {}) {
2146
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
2292
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
2147
2293
  const mergedConfig = {
2148
2294
  version: userConfig.version || DEFAULT_MEMORY_CONFIG.version,
2149
2295
  embedder: {
@@ -2165,7 +2311,8 @@ var ConfigManager = class {
2165
2311
  provider: ((_l = userConfig.llm) == null ? void 0 : _l.provider) || DEFAULT_MEMORY_CONFIG.llm.provider,
2166
2312
  config: {
2167
2313
  apiKey: ((_n = (_m = userConfig.llm) == null ? void 0 : _m.config) == null ? void 0 : _n.apiKey) || DEFAULT_MEMORY_CONFIG.llm.config.apiKey,
2168
- model: ((_p = (_o = userConfig.llm) == null ? void 0 : _o.config) == null ? void 0 : _p.model) || DEFAULT_MEMORY_CONFIG.llm.config.model
2314
+ model: ((_p = (_o = userConfig.llm) == null ? void 0 : _o.config) == null ? void 0 : _p.model) || DEFAULT_MEMORY_CONFIG.llm.config.model,
2315
+ modelProperties: ((_r = (_q = userConfig.llm) == null ? void 0 : _q.config) == null ? void 0 : _r.modelProperties) || DEFAULT_MEMORY_CONFIG.llm.config.modelProperties
2169
2316
  }
2170
2317
  },
2171
2318
  historyDbPath: userConfig.historyDbPath || DEFAULT_MEMORY_CONFIG.historyDbPath,
@@ -2941,7 +3088,7 @@ var parse_vision_messages = async (messages) => {
2941
3088
  };
2942
3089
 
2943
3090
  // src/oss/src/utils/telemetry.ts
2944
- var version = "2.1.15";
3091
+ var version = "2.1.16";
2945
3092
  var MEM0_TELEMETRY = true;
2946
3093
  var _a;
2947
3094
  try {
@@ -3507,6 +3654,7 @@ export {
3507
3654
  Memory,
3508
3655
  MemoryConfigSchema,
3509
3656
  MemoryVectorStore,
3657
+ MistralLLM,
3510
3658
  OllamaEmbedder,
3511
3659
  OllamaLLM,
3512
3660
  OpenAIEmbedder,