mem0ai-azure-mysql 0.1.115__py3-none-any.whl → 0.1.115.1__py3-none-any.whl
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.
- mem0/embeddings/azure_openai.py +17 -3
- mem0/llms/azure_openai.py +13 -3
- mem0/vector_stores/azure_ai_search.py +22 -2
- {mem0ai_azure_mysql-0.1.115.dist-info → mem0ai_azure_mysql-0.1.115.1.dist-info}/METADATA +1 -1
- {mem0ai_azure_mysql-0.1.115.dist-info → mem0ai_azure_mysql-0.1.115.1.dist-info}/RECORD +8 -8
- {mem0ai_azure_mysql-0.1.115.data → mem0ai_azure_mysql-0.1.115.1.data}/data/README.md +0 -0
- {mem0ai_azure_mysql-0.1.115.dist-info → mem0ai_azure_mysql-0.1.115.1.dist-info}/WHEEL +0 -0
- {mem0ai_azure_mysql-0.1.115.dist-info → mem0ai_azure_mysql-0.1.115.1.dist-info}/licenses/LICENSE +0 -0
mem0/embeddings/azure_openai.py
CHANGED
|
@@ -1,32 +1,46 @@
|
|
|
1
1
|
import os
|
|
2
|
+
import logging
|
|
2
3
|
from typing import Literal, Optional
|
|
3
4
|
|
|
4
5
|
from openai import AzureOpenAI
|
|
5
6
|
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
|
|
6
7
|
|
|
8
|
+
|
|
7
9
|
from mem0.configs.embeddings.base import BaseEmbedderConfig
|
|
8
10
|
from mem0.embeddings.base import EmbeddingBase
|
|
9
11
|
|
|
12
|
+
logging.basicConfig(level=logging.INFO)
|
|
13
|
+
logger = logging.getLogger(__name__)
|
|
14
|
+
|
|
10
15
|
|
|
11
16
|
class AzureOpenAIEmbedding(EmbeddingBase):
|
|
12
17
|
def __init__(self, config: Optional[BaseEmbedderConfig] = None):
|
|
13
18
|
super().__init__(config)
|
|
14
19
|
|
|
20
|
+
api_key = self.config.azure_kwargs.api_key or os.getenv("EMBEDDING_AZURE_API_KEY")
|
|
15
21
|
azure_deployment = self.config.azure_kwargs.azure_deployment or os.getenv("EMBEDDING_AZURE_DEPLOYMENT")
|
|
16
22
|
azure_endpoint = self.config.azure_kwargs.azure_endpoint or os.getenv("EMBEDDING_AZURE_ENDPOINT")
|
|
17
23
|
api_version = self.config.azure_kwargs.api_version or os.getenv("EMBEDDING_AZURE_API_VERSION")
|
|
18
24
|
default_headers = self.config.azure_kwargs.default_headers
|
|
19
25
|
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
auth_kwargs = {}
|
|
27
|
+
|
|
28
|
+
if api_key:
|
|
29
|
+
logger.info(f"Using API key for Azure OpenAI embedding authentication. {api_key}")
|
|
30
|
+
auth_kwargs["azure_ad_token"] = api_key
|
|
31
|
+
else:
|
|
32
|
+
logger.info("Using Azure AD token provider for Azure OpenAI embedding authentication.")
|
|
33
|
+
credential = DefaultAzureCredential()
|
|
34
|
+
token_provider = get_bearer_token_provider(credential, "https://cognitiveservices.azure.com/.default")
|
|
35
|
+
auth_kwargs["azure_ad_token_provider"] = token_provider
|
|
22
36
|
|
|
23
37
|
self.client = AzureOpenAI(
|
|
24
38
|
azure_deployment=azure_deployment,
|
|
25
39
|
azure_endpoint=azure_endpoint,
|
|
26
40
|
api_version=api_version,
|
|
27
|
-
azure_ad_token_provider=token_provider,
|
|
28
41
|
http_client=self.config.http_client,
|
|
29
42
|
default_headers=default_headers,
|
|
43
|
+
**auth_kwargs,
|
|
30
44
|
)
|
|
31
45
|
|
|
32
46
|
def embed(self, text, memory_action: Optional[Literal["add", "search", "update"]] = None):
|
mem0/llms/azure_openai.py
CHANGED
|
@@ -18,20 +18,30 @@ class AzureOpenAILLM(LLMBase):
|
|
|
18
18
|
if not self.config.model:
|
|
19
19
|
self.config.model = "gpt-4o"
|
|
20
20
|
|
|
21
|
+
api_key = self.config.azure_kwargs.api_key or os.getenv("LLM_AZURE_API_KEY")
|
|
21
22
|
azure_deployment = self.config.azure_kwargs.azure_deployment or os.getenv("LLM_AZURE_DEPLOYMENT")
|
|
22
23
|
azure_endpoint = self.config.azure_kwargs.azure_endpoint or os.getenv("LLM_AZURE_ENDPOINT")
|
|
23
24
|
api_version = self.config.azure_kwargs.api_version or os.getenv("LLM_AZURE_API_VERSION")
|
|
24
25
|
default_headers = self.config.azure_kwargs.default_headers
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
auth_kwargs = {}
|
|
28
|
+
|
|
29
|
+
if api_key:
|
|
30
|
+
auth_kwargs["azure_ad_token"] = api_key
|
|
31
|
+
else:
|
|
32
|
+
# Use Azure AD token provider if no API key is provided.
|
|
33
|
+
# This is useful for managed identities or when using Azure AD authentication.
|
|
34
|
+
credential = DefaultAzureCredential()
|
|
35
|
+
token_provider = get_bearer_token_provider(credential, "https://cognitiveservices.azure.com/.default")
|
|
36
|
+
auth_kwargs["azure_ad_token_provider"] = token_provider
|
|
37
|
+
|
|
28
38
|
self.client = AzureOpenAI(
|
|
29
39
|
azure_deployment=azure_deployment,
|
|
30
40
|
azure_endpoint=azure_endpoint,
|
|
31
41
|
api_version=api_version,
|
|
32
|
-
azure_ad_token_provider=token_provider,
|
|
33
42
|
http_client=self.config.http_client,
|
|
34
43
|
default_headers=default_headers,
|
|
44
|
+
**auth_kwargs,
|
|
35
45
|
)
|
|
36
46
|
|
|
37
47
|
def _parse_response(self, response, tools):
|
|
@@ -2,8 +2,11 @@ import json
|
|
|
2
2
|
import logging
|
|
3
3
|
import re
|
|
4
4
|
from typing import List, Optional
|
|
5
|
+
from datetime import datetime, timedelta, timezone
|
|
5
6
|
|
|
6
7
|
from pydantic import BaseModel
|
|
8
|
+
from azure.core.credentials import AccessToken
|
|
9
|
+
from azure.core.credentials import TokenCredential
|
|
7
10
|
from azure.identity import DefaultAzureCredential
|
|
8
11
|
|
|
9
12
|
from mem0.memory.utils import extract_json
|
|
@@ -33,6 +36,18 @@ except ImportError:
|
|
|
33
36
|
logger = logging.getLogger(__name__)
|
|
34
37
|
|
|
35
38
|
|
|
39
|
+
class StaticTokenCredential(TokenCredential):
|
|
40
|
+
def __init__(self, token: str, expires_on: int | None = None):
|
|
41
|
+
self._token = token
|
|
42
|
+
|
|
43
|
+
if expires_on is None:
|
|
44
|
+
expires_on = int((datetime.now(timezone.utc) + timedelta(days=2)).timestamp())
|
|
45
|
+
self._expires_on = expires_on
|
|
46
|
+
|
|
47
|
+
def get_token(self, *scopes, **kwargs) -> AccessToken:
|
|
48
|
+
return AccessToken(self._token, self._expires_on)
|
|
49
|
+
|
|
50
|
+
|
|
36
51
|
class OutputData(BaseModel):
|
|
37
52
|
id: Optional[str]
|
|
38
53
|
score: Optional[float]
|
|
@@ -77,7 +92,12 @@ class AzureAISearch(VectorStoreBase):
|
|
|
77
92
|
self.hybrid_search = hybrid_search
|
|
78
93
|
self.vector_filter_mode = vector_filter_mode
|
|
79
94
|
|
|
80
|
-
|
|
95
|
+
if api_key is None:
|
|
96
|
+
logger.info("No API key provided. Using DefaultAzureCredential for authentication.")
|
|
97
|
+
credential = DefaultAzureCredential()
|
|
98
|
+
else:
|
|
99
|
+
logger.info("Using StaticTokenCredential for authentication.")
|
|
100
|
+
credential = StaticTokenCredential(api_key)
|
|
81
101
|
self.search_client = SearchClient(
|
|
82
102
|
endpoint=f"https://{service_name}.search.windows.net",
|
|
83
103
|
index_name=self.index_name,
|
|
@@ -360,7 +380,7 @@ class AzureAISearch(VectorStoreBase):
|
|
|
360
380
|
self.delete_col()
|
|
361
381
|
|
|
362
382
|
# Reinitialize the clients
|
|
363
|
-
credential = DefaultAzureCredential()
|
|
383
|
+
credential = StaticTokenCredential(self.api_key) if self.api_key else DefaultAzureCredential()
|
|
364
384
|
service_endpoint = f"https://{self.service_name}.search.windows.net"
|
|
365
385
|
self.search_client = SearchClient(
|
|
366
386
|
endpoint=service_endpoint,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mem0ai-azure-mysql
|
|
3
|
-
Version: 0.1.115
|
|
3
|
+
Version: 0.1.115.1
|
|
4
4
|
Summary: Long-term memory for AI Agents with Azure DefaultAzureCredential authentication and MySQL history database support
|
|
5
5
|
License-File: LICENSE
|
|
6
6
|
Requires-Python: <4.0,>=3.9
|
|
@@ -38,7 +38,7 @@ mem0/dbs/configs.py,sha256=EoWnTNM_YPR39VgDDv8wS0KfA1nJ8Q0bpGtJdx1wu84,624
|
|
|
38
38
|
mem0/dbs/mysql.py,sha256=AdrJQPrzqAN1cDjYgT-tA5n7CLPjJwR8LPlBhIJbT80,12731
|
|
39
39
|
mem0/embeddings/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
40
40
|
mem0/embeddings/aws_bedrock.py,sha256=MvlmXfUxua2sIEoxzJKN9RPA5Xk9pN9peeDr3QBjuGw,3531
|
|
41
|
-
mem0/embeddings/azure_openai.py,sha256=
|
|
41
|
+
mem0/embeddings/azure_openai.py,sha256=rJqPzA4XdLgZrEuEhk4UI2NPfCg_0w82wIa6x5RdrAw,2390
|
|
42
42
|
mem0/embeddings/base.py,sha256=O-oFuizpx9tyL8qjhRu0l42GDkjgORy_UMtMCkRfc4k,973
|
|
43
43
|
mem0/embeddings/configs.py,sha256=ucqSXa_Wiiy_LQJRpulD_-VFQQc2tWOOzEV3pLrHMow,881
|
|
44
44
|
mem0/embeddings/gemini.py,sha256=6WPlY1GRYSfX2aD0ywou3uM4XenEQm6oB1c7x7R5oOk,1509
|
|
@@ -60,7 +60,7 @@ mem0/graphs/neptune/main.py,sha256=JoyMpFqRe9RNLnh4f_HyfUaxwHtaDC6ZCdr0hqR8Vcw,1
|
|
|
60
60
|
mem0/llms/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
61
61
|
mem0/llms/anthropic.py,sha256=LtKWVTAQxQnpiMrB0jwihn4mOO9RBjUT_vEjeXPBYhE,2250
|
|
62
62
|
mem0/llms/aws_bedrock.py,sha256=awRKZvsYpab3jYFu0e3_gTRxAToF3-M1nm9Sbr1QwzA,10520
|
|
63
|
-
mem0/llms/azure_openai.py,sha256=
|
|
63
|
+
mem0/llms/azure_openai.py,sha256=t1gZsMX48xYjAbG20kQtBZ7dWiZGW5oPDQqTOw5X14Q,4579
|
|
64
64
|
mem0/llms/azure_openai_structured.py,sha256=gWFt73wn7okFcJAI8_a7SSxcnoV8_Qrf9axiV5qKNf8,2722
|
|
65
65
|
mem0/llms/base.py,sha256=Uit80Gs0MNKKH2z9h0Fkmr-4u4QATCpKFlPXj_8DBuo,1061
|
|
66
66
|
mem0/llms/configs.py,sha256=yvtU5WDBsiygCiMHjhG9ZCb1NIAMv8uXYD_KL8_X54w,997
|
|
@@ -90,7 +90,7 @@ mem0/proxy/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
90
90
|
mem0/proxy/main.py,sha256=DhGH9dvVd3GTS1yyZzTBpyYvgArDRcYIgKLBCcosCLE,7398
|
|
91
91
|
mem0/utils/factory.py,sha256=FZ-8qKK4K7unnEfcmcYAY77i2IVDK1nbcsB1WeGlR2I,5448
|
|
92
92
|
mem0/vector_stores/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
93
|
-
mem0/vector_stores/azure_ai_search.py,sha256=
|
|
93
|
+
mem0/vector_stores/azure_ai_search.py,sha256=AXcuvzll3dMWiisATZRIsEygc1tMVvAp7xdy8ei7rCE,15706
|
|
94
94
|
mem0/vector_stores/baidu.py,sha256=Cp7TGtMnZRkuDAnRw0F0OjNg229dH31dXYZL1JmPQes,12683
|
|
95
95
|
mem0/vector_stores/base.py,sha256=yb9TCcxximzdJd8vfNJRROHBrUyYLbH26-E63fclcDo,1344
|
|
96
96
|
mem0/vector_stores/chroma.py,sha256=fHGbvecYPvlhHrS4lkSWt4S1EnxicEWuqG6qOqDleQA,7539
|
|
@@ -109,8 +109,8 @@ mem0/vector_stores/supabase.py,sha256=RCegadYW4Q8CT_NSeCywUVW01TLJQT4mDzeStNHEJH
|
|
|
109
109
|
mem0/vector_stores/upstash_vector.py,sha256=dAIef-bIB6AE_dVR8UpVWZUPQs-wLhqfxEHyyXO5kQU,9073
|
|
110
110
|
mem0/vector_stores/vertex_ai_vector_search.py,sha256=RaaPLTTbTPftlg7nm9WTROOhurSxqnAyx-g3tYoxv0I,24659
|
|
111
111
|
mem0/vector_stores/weaviate.py,sha256=v91CA79Z_zJBohwaXlOW6jtudDlGq0kYKQFHMHGqUy4,11833
|
|
112
|
-
mem0ai_azure_mysql-0.1.115.data/data/README.md,sha256=HhoTn6hBxTIsFwbm5zHT7aNmQOa5yaTgwdRIF6V7hX4,6525
|
|
113
|
-
mem0ai_azure_mysql-0.1.115.dist-info/METADATA,sha256=
|
|
114
|
-
mem0ai_azure_mysql-0.1.115.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
115
|
-
mem0ai_azure_mysql-0.1.115.dist-info/licenses/LICENSE,sha256=C7y-kxw1MpOi-vzggyYYHf7qDlaMVmr9TOgzenD14hk,11349
|
|
116
|
-
mem0ai_azure_mysql-0.1.115.dist-info/RECORD,,
|
|
112
|
+
mem0ai_azure_mysql-0.1.115.1.data/data/README.md,sha256=HhoTn6hBxTIsFwbm5zHT7aNmQOa5yaTgwdRIF6V7hX4,6525
|
|
113
|
+
mem0ai_azure_mysql-0.1.115.1.dist-info/METADATA,sha256=onCN-qJDuXyPZkn5b99HeNv_BPR_r_pubXYvp4sJjYA,8950
|
|
114
|
+
mem0ai_azure_mysql-0.1.115.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
115
|
+
mem0ai_azure_mysql-0.1.115.1.dist-info/licenses/LICENSE,sha256=C7y-kxw1MpOi-vzggyYYHf7qDlaMVmr9TOgzenD14hk,11349
|
|
116
|
+
mem0ai_azure_mysql-0.1.115.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
{mem0ai_azure_mysql-0.1.115.dist-info → mem0ai_azure_mysql-0.1.115.1.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|