nemo-evaluator 0.1.76__py3-none-any.whl → 0.1.78__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.
@@ -17,6 +17,7 @@
17
17
 
18
18
  import hashlib
19
19
  import json
20
+ import re
20
21
  import threading
21
22
  from typing import Any, final
22
23
 
@@ -118,6 +119,70 @@ class CachingInterceptor(RequestToResponseInterceptor, ResponseInterceptor):
118
119
  max_saved_responses=self.max_saved_responses,
119
120
  )
120
121
 
122
+ @staticmethod
123
+ def sanitize_request_data_for_logging(data: Any) -> Any:
124
+ """
125
+ Sanitize request data for logging by replacing image content with brief descriptions.
126
+
127
+ Args:
128
+ data: Request data to sanitize (can be dict, list, or any other type)
129
+
130
+ Returns:
131
+ Sanitized version of the data with images replaced by brief descriptions
132
+ """
133
+ if isinstance(data, dict):
134
+ sanitized = {}
135
+ for key, value in data.items():
136
+ # Check if this is an image_url field
137
+ if key == "image_url" and isinstance(value, dict):
138
+ url = value.get("url", "")
139
+ if isinstance(url, str) and url.startswith("data:image/"):
140
+ # Extract image format and calculate approximate size
141
+ match = re.match(r"data:image/([^;]+);base64,(.+)", url)
142
+ if match:
143
+ image_format = match.group(1)
144
+ base64_data = match.group(2)
145
+ size_bytes = (
146
+ len(base64_data) * 3 // 4
147
+ ) # Approximate decoded size
148
+ sanitized[key] = {
149
+ "url": f"<image: format={image_format}, size≈{size_bytes} bytes>"
150
+ }
151
+ else:
152
+ sanitized[key] = {"url": "<image data>"}
153
+ else:
154
+ sanitized[key] = (
155
+ CachingInterceptor.sanitize_request_data_for_logging(value)
156
+ )
157
+ # Check if this is a url field with base64 image data
158
+ elif (
159
+ key == "url"
160
+ and isinstance(value, str)
161
+ and value.startswith("data:image/")
162
+ ):
163
+ match = re.match(r"data:image/([^;]+);base64,(.+)", value)
164
+ if match:
165
+ image_format = match.group(1)
166
+ base64_data = match.group(2)
167
+ size_bytes = len(base64_data) * 3 // 4
168
+ sanitized[key] = (
169
+ f"<image: format={image_format}, size≈{size_bytes} bytes>"
170
+ )
171
+ else:
172
+ sanitized[key] = "<image data>"
173
+ else:
174
+ sanitized[key] = (
175
+ CachingInterceptor.sanitize_request_data_for_logging(value)
176
+ )
177
+ return sanitized
178
+ elif isinstance(data, list):
179
+ return [
180
+ CachingInterceptor.sanitize_request_data_for_logging(item)
181
+ for item in data
182
+ ]
183
+ else:
184
+ return data
185
+
121
186
  @staticmethod
122
187
  def _generate_cache_key(data: Any) -> str:
123
188
  """
@@ -201,7 +266,10 @@ class CachingInterceptor(RequestToResponseInterceptor, ResponseInterceptor):
201
266
 
202
267
  # Check cache. Create cache key that will be used everywhere (also if no cache hit)
203
268
  req.rctx.cache_key = self._generate_cache_key(request_data)
204
- self.logger.debug("Request", request_data=request_data)
269
+
270
+ # Sanitize request data for logging (replace images with brief descriptions)
271
+ sanitized_request_data = self.sanitize_request_data_for_logging(request_data)
272
+ self.logger.debug("Intercepted request", request_data=sanitized_request_data)
205
273
  self.logger.debug(
206
274
  "Processing request for caching",
207
275
  cache_key=req.rctx.cache_key[:8] + "...",
@@ -16,7 +16,7 @@
16
16
  # Below is the _next_ version that will be published, not the currently published one.
17
17
  MAJOR = 0
18
18
  MINOR = 1
19
- PATCH = 76
19
+ PATCH = 78
20
20
  PRE_RELEASE = ""
21
21
 
22
22
  # Use the following formatting: (major, minor, patch, pre-release)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nemo-evaluator
3
- Version: 0.1.76
3
+ Version: 0.1.78
4
4
  Summary: Common utilities for NVIDIA evaluation frameworks
5
5
  Author: NVIDIA
6
6
  Author-email: nemo-toolkit@nvidia.com
@@ -1,5 +1,5 @@
1
1
  nemo_evaluator/__init__.py,sha256=lwW_lnmHxRBVEWkT1g71icmaxDR1_DqMrh4wSR0vk58,1787
2
- nemo_evaluator/package_info.py,sha256=fstloAutEI3XWXgMEgpR4F2REV5v_T56TaT6_moZBhk,1525
2
+ nemo_evaluator/package_info.py,sha256=9JyEFNhdtaRcyfjipVIF3idrff3gGcIXpFUlpv0klf0,1525
3
3
  nemo_evaluator/adapters/__init__.py,sha256=Qbiv8oknyr5yqpWp1npFw3p6EDwZnKUwL3VZXQGtjos,685
4
4
  nemo_evaluator/adapters/adapter_config.py,sha256=kyL2KVi7Zc6sn8BomujTY54SK-0RoCZk5v4gS7KHbYk,28007
5
5
  nemo_evaluator/adapters/decorators.py,sha256=DeeDW4YscGHNbjq-GyW60WXSfu6TKLaWLCyrmWkqpvw,5648
@@ -10,7 +10,7 @@ nemo_evaluator/adapters/types.py,sha256=x_waBWvF53KGbB7rupKaZco7dJYULLQAbPo7H7Nd
10
10
  nemo_evaluator/adapters/caching/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
11
  nemo_evaluator/adapters/caching/diskcaching.py,sha256=rWFDS_GRl_bsrxgQnuslgBNP8IHlZRZqtUaAhfWTAlg,56683
12
12
  nemo_evaluator/adapters/interceptors/__init__.py,sha256=0TTALp1wg6ODU4GJZTE48uQS6KXYLbE24mGtTCb3hME,1630
13
- nemo_evaluator/adapters/interceptors/caching_interceptor.py,sha256=KU3LQ1SL_hQn-ur57z3o3GhJrWx8Rgxrw3SKKU5TPPw,11744
13
+ nemo_evaluator/adapters/interceptors/caching_interceptor.py,sha256=oC5-0T90uYZE0Fxmq6fINvyUC6dKYGaIYoYbOQSW4ms,14806
14
14
  nemo_evaluator/adapters/interceptors/endpoint_interceptor.py,sha256=Ae7CBthw5EnaXksDLfOAfh9nR8bsD36safH4xO57Q2A,5101
15
15
  nemo_evaluator/adapters/interceptors/logging_interceptor.py,sha256=31SFh-zHOe0sKkgtRZUsuuGbWdGkLYoIlFUYckhwNO0,7291
16
16
  nemo_evaluator/adapters/interceptors/payload_modifier_interceptor.py,sha256=CJEKnNpJME4E0rWVKGXU8XJq5oodMNUp4zPp28w3h7c,6303
@@ -46,9 +46,9 @@ nemo_evaluator/resources/output_tpl.py,sha256=7gIjcHy2BUTGu5hdf2zLkJgcHck8b4mPvi
46
46
  nemo_evaluator/sandbox/__init__.py,sha256=J6fFnQwSgOOsSsudWcRgY8LjFKoiwYRh6UFAiwKmxM0,1066
47
47
  nemo_evaluator/sandbox/base.py,sha256=AwAlWcKdSJKLn3DrvENgCUrxcWFu7ItO1NqJBS1z0cY,3199
48
48
  nemo_evaluator/sandbox/ecs_fargate.py,sha256=DI6QToYngqrzl8vf1I4GRj0AwDn1YQO64g36-6naZm8,49785
49
- nemo_evaluator-0.1.76.dist-info/licenses/LICENSE,sha256=COyFnIvgPj0PZK5t89Z_f9mQBR4LH2rDJAkVvR3m7gM,11348
50
- nemo_evaluator-0.1.76.dist-info/METADATA,sha256=u8FBiPiyW9VNMHwNYBMkm6YrQCnIx6XkA33gqrAgD58,14203
51
- nemo_evaluator-0.1.76.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
52
- nemo_evaluator-0.1.76.dist-info/entry_points.txt,sha256=lDcQ6UDEwgoyYdkDx3_YJw8Bzipl_xfVOp3U24IqgcU,289
53
- nemo_evaluator-0.1.76.dist-info/top_level.txt,sha256=Y-IJy0kY4bd0bay8J_cGaZmxNSjZN3MiFhW7B3VyTeU,15
54
- nemo_evaluator-0.1.76.dist-info/RECORD,,
49
+ nemo_evaluator-0.1.78.dist-info/licenses/LICENSE,sha256=COyFnIvgPj0PZK5t89Z_f9mQBR4LH2rDJAkVvR3m7gM,11348
50
+ nemo_evaluator-0.1.78.dist-info/METADATA,sha256=LmYrU6RPCD0veZHRkt6F6dAbXL8t45i7LHXCMdxSX3w,14203
51
+ nemo_evaluator-0.1.78.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
52
+ nemo_evaluator-0.1.78.dist-info/entry_points.txt,sha256=lDcQ6UDEwgoyYdkDx3_YJw8Bzipl_xfVOp3U24IqgcU,289
53
+ nemo_evaluator-0.1.78.dist-info/top_level.txt,sha256=Y-IJy0kY4bd0bay8J_cGaZmxNSjZN3MiFhW7B3VyTeU,15
54
+ nemo_evaluator-0.1.78.dist-info/RECORD,,