datarobot-moderations 11.2.6__py3-none-any.whl → 11.2.8__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.
@@ -232,9 +232,10 @@ class AsyncHTTPClient:
232
232
  try:
233
233
  response = await self.session.post(url, json=payload, headers=self.json_headers)
234
234
  if response.status != HTTPStatus.ACCEPTED:
235
+ response_text = await response.text()
235
236
  raise Exception(
236
237
  f"Error uploading custom metrics: Status Code: {response.status}"
237
- f"Message: {response.text}"
238
+ f"Message: {response_text}"
238
239
  )
239
240
  self._logger.info("Successfully uploaded custom metrics")
240
241
  except Exception as e:
@@ -18,6 +18,7 @@ import time
18
18
  import traceback
19
19
  import uuid
20
20
  from collections.abc import Iterable
21
+ from inspect import signature
21
22
  from typing import Optional
22
23
 
23
24
  import numpy as np
@@ -483,7 +484,15 @@ def run_user_chat_function(completion_create_params, model, pipeline, drum_chat_
483
484
  start_time = time.time()
484
485
 
485
486
  try:
486
- chat_completion = drum_chat_fn(completion_create_params, model, **kwargs)
487
+ # the standard chat hook takes only the first 2 parameters
488
+ # if so, passing in extra (such as headers=headers) will trigger a TypeError
489
+ # same logic is in DRUM PythonModelAdapter.chat()
490
+ chat_fn_params = signature(drum_chat_fn).parameters
491
+ if len(chat_fn_params) > 2:
492
+ chat_completion = drum_chat_fn(completion_create_params, model, **kwargs)
493
+ else:
494
+ _logger.debug("run_user_chat_function: chat hook takes 2 args; kwargs are discarded")
495
+ chat_completion = drum_chat_fn(completion_create_params, model)
487
496
  except Exception as e:
488
497
  _logger.error(f"Failed to execute user chat function: {e}")
489
498
  raise
@@ -798,6 +807,13 @@ def guard_chat_wrapper(
798
807
  if association_id:
799
808
  data[association_id_column_name] = [association_id]
800
809
 
810
+ # DRUM initializes the pipeline (which reads the deployment's list of custom metrics)
811
+ # at start time.
812
+ # If there are no extra_body fields (meaning no user-defined custom metrics to report),
813
+ # then the list does not need to be reread.
814
+ if chat_extra_body_params:
815
+ pipeline.lookup_custom_metric_ids()
816
+
801
817
  # report any metrics from extra_body. They are not tied to a prompt or response phase.
802
818
  _logger.debug("Report extra_body params as custom metrics")
803
819
  pipeline.report_custom_metrics_from_extra_body(association_id, chat_extra_body_params)
@@ -385,6 +385,8 @@ class LLMPipeline(Pipeline):
385
385
  ) -> None:
386
386
  """
387
387
  Add any key-value pairs extracted from extra_body as custom metrics.
388
+ The custom metrics must be deployment-based, not model-specific.
389
+ (Bulk upload does not support heterogeneous model/non-model metrics.)
388
390
  :param association_id: Association ID of the chat request
389
391
  :param extra_params: a dict of {"name": value} for all extra_body parameters found
390
392
  """
@@ -203,12 +203,11 @@ class Pipeline:
203
203
  The complete set of guard metrics is also known at that time.
204
204
  However, the extra_body metrics needed are not known until guard_chat_wrapper
205
205
  parses extra_body.
206
- For that reason, read and cache all the metric name/id pairs at pipeline create time.
206
+ For that reason, refresh the list when a chat request arrives.
207
207
  Side effect: updates self.custom_metric_names_to_ids
208
208
  """
209
- if self.custom_metric_names_to_ids:
210
- self._logger.debug("lookup_custom_metric_ids(): IDs were already read; skipping")
211
- return
209
+ # set up DataRobot API client, only if not already set up
210
+ self.create_dr_client()
212
211
 
213
212
  # Manually paginate; the dmm list_custom_metrics does not implement pagination
214
213
  custom_metrics_list = []
@@ -222,7 +221,13 @@ class Pipeline:
222
221
  if response_list["next"] is None:
223
222
  break
224
223
 
224
+ if not custom_metrics_list:
225
+ self._logger.warning(
226
+ "lookup_custom_metric_ids: result list is empty; no custom metrics to process"
227
+ )
228
+
225
229
  self.custom_metric_names_to_ids = {m["name"]: m["id"] for m in custom_metrics_list}
230
+ self._logger.debug(f"lookup_custom_metric_ids(): found {self.custom_metric_names_to_ids}")
226
231
 
227
232
  def create_custom_metrics(self):
228
233
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: datarobot-moderations
3
- Version: 11.2.6
3
+ Version: 11.2.8
4
4
  Summary: DataRobot Monitoring and Moderation framework
5
5
  License: DataRobot Tool and Utility Agreement
6
6
  Author: DataRobot
@@ -1,8 +1,8 @@
1
1
  datarobot_dome/__init__.py,sha256=B5Rx8_CNCNsOpxBbRj27XOXCfRZmvmrAR-NzlzIKnDw,583
2
- datarobot_dome/async_http_client.py,sha256=cQFoSI2ovt0Kyk4XWQPXod5PAfA-ZPkjLYVWQZhDGDE,9809
2
+ datarobot_dome/async_http_client.py,sha256=YVkzSSP7ItOEwEskjH0MAs1kJW0jXfbvJWkF_52K7CE,9863
3
3
  datarobot_dome/chat_helper.py,sha256=BzvtUyZSZxzOqq-5a2wQKhHhr2kMlcP1MFrHaDAeD_o,9671
4
4
  datarobot_dome/constants.py,sha256=jvgpHa3Wh_nZVZmfU-6ab8FHnKNW3KxOPYIIEb_oS6U,10662
5
- datarobot_dome/drum_integration.py,sha256=NWTYJWGPM_z8RQYXteEOWQkCVBXzJ5XRZEWJYeUdHf8,45656
5
+ datarobot_dome/drum_integration.py,sha256=XcQRaUKQWCGCX9WwiViQQnUy4ZGMzS_FKpkVygg3W1M,46511
6
6
  datarobot_dome/guard.py,sha256=xJds9hcbUaS-KD5nC1mn0GiPdBrileFUu6BuTAjDNuY,34668
7
7
  datarobot_dome/guard_executor.py,sha256=ox5_jOHcqMaxaaagIYJJHhCwEI7Wg-rUEiu5rutsfVU,35363
8
8
  datarobot_dome/guard_helpers.py,sha256=jfu8JTWCcxu4WD1MKxeP1n53DeebY3SSuP-t5sWyV1U,17187
@@ -14,11 +14,11 @@ datarobot_dome/metrics/citation_metrics.py,sha256=l2mnV1gz7nQeJ_yfaS4dcP3DFWf0p5
14
14
  datarobot_dome/metrics/factory.py,sha256=7caa8paI9LuFXDgguXdC4on28V7IwwIsKJT2Z-Aps8A,2187
15
15
  datarobot_dome/metrics/metric_scorer.py,sha256=uJ_IJRw7ZFHueg8xjsaXbt0ypO7JiydZ0WapCp96yng,2540
16
16
  datarobot_dome/pipeline/__init__.py,sha256=B5Rx8_CNCNsOpxBbRj27XOXCfRZmvmrAR-NzlzIKnDw,583
17
- datarobot_dome/pipeline/llm_pipeline.py,sha256=PRJ7t5Bc8S2ZbD0yK8ztdTD1hPC7Yo8IvhFlWEkMkmU,20810
18
- datarobot_dome/pipeline/pipeline.py,sha256=m8m_QtoQNwJ5U-bbJGdtlmAbdI-UpobcMCuRz-U_H_Y,19052
17
+ datarobot_dome/pipeline/llm_pipeline.py,sha256=bindyorJq9VSPZt2X8w0-3REaXui7wIA-8c-zNOIdZU,20961
18
+ datarobot_dome/pipeline/pipeline.py,sha256=vCcP8dgu4TE-af6wUt7RqD4Xg7MzfwfK8njjC4XLnIA,19249
19
19
  datarobot_dome/pipeline/vdb_pipeline.py,sha256=zt5d_41oJjdT8qOtvpgz-l5uvImwKE9f6pQsAU_TdR4,9866
20
20
  datarobot_dome/runtime.py,sha256=FD8wXOweqoQVzbZMh-mucL66xT2kGxPsJUGAcJBgwxw,1468
21
21
  datarobot_dome/streaming.py,sha256=DkvKEH0yN0aPEWMTAjMFJB3Kx4iLGdjUMQU1pAplbeg,17751
22
- datarobot_moderations-11.2.6.dist-info/METADATA,sha256=U20ej2pA1_79GwOl4f7qShgB9Q4F_zb-phsOBTITOF0,4741
23
- datarobot_moderations-11.2.6.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
24
- datarobot_moderations-11.2.6.dist-info/RECORD,,
22
+ datarobot_moderations-11.2.8.dist-info/METADATA,sha256=WDKeoX2WMqkNUzqirtogVxJ4R5ItpPSA33Gp7I1q86c,4741
23
+ datarobot_moderations-11.2.8.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
24
+ datarobot_moderations-11.2.8.dist-info/RECORD,,