datarobot-moderations 11.2.2__py3-none-any.whl → 11.2.3__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.
- datarobot_dome/guard.py +5 -1
- datarobot_dome/guard_helpers.py +14 -3
- datarobot_dome/guards/guard_llm_mixin.py +2 -8
- {datarobot_moderations-11.2.2.dist-info → datarobot_moderations-11.2.3.dist-info}/METADATA +1 -1
- {datarobot_moderations-11.2.2.dist-info → datarobot_moderations-11.2.3.dist-info}/RECORD +6 -6
- {datarobot_moderations-11.2.2.dist-info → datarobot_moderations-11.2.3.dist-info}/WHEEL +0 -0
datarobot_dome/guard.py
CHANGED
|
@@ -23,6 +23,7 @@ from llama_index.core.evaluation import FaithfulnessEvaluator
|
|
|
23
23
|
from nemoguardrails import LLMRails
|
|
24
24
|
from nemoguardrails import RailsConfig
|
|
25
25
|
from ragas.llms import LangchainLLMWrapper
|
|
26
|
+
from ragas.llms import LlamaIndexLLMWrapper
|
|
26
27
|
from ragas.metrics import AgentGoalAccuracyWithoutReference
|
|
27
28
|
|
|
28
29
|
from datarobot_dome.constants import AGENT_GOAL_ACCURACY_COLUMN_NAME
|
|
@@ -734,7 +735,10 @@ class AgentGoalAccuracyGuard(OOTBGuard, GuardLLMMixin):
|
|
|
734
735
|
# Default LLM Type for Agent Goal Accuracy is set to Azure OpenAI
|
|
735
736
|
self._llm_type = config.get("llm_type", GuardLLMType.AZURE_OPENAI)
|
|
736
737
|
llm = self.get_llm(config, self._llm_type)
|
|
737
|
-
|
|
738
|
+
if self._llm_type == GuardLLMType.AZURE_OPENAI:
|
|
739
|
+
evaluator_llm = LangchainLLMWrapper(llm)
|
|
740
|
+
else:
|
|
741
|
+
evaluator_llm = LlamaIndexLLMWrapper(llm)
|
|
738
742
|
self.scorer = AgentGoalAccuracyWithoutReference(llm=evaluator_llm)
|
|
739
743
|
|
|
740
744
|
@property
|
datarobot_dome/guard_helpers.py
CHANGED
|
@@ -19,6 +19,7 @@ import tiktoken
|
|
|
19
19
|
from deepeval.metrics import TaskCompletionMetric
|
|
20
20
|
from deepeval.models import DeepEvalBaseLLM
|
|
21
21
|
from deepeval.test_case import LLMTestCase
|
|
22
|
+
from langchain_core.language_models import BaseLanguageModel
|
|
22
23
|
from langchain_nvidia_ai_endpoints import ChatNVIDIA
|
|
23
24
|
from langchain_nvidia_ai_endpoints import Model
|
|
24
25
|
from langchain_nvidia_ai_endpoints import register_model
|
|
@@ -441,11 +442,21 @@ class ModerationDeepEvalLLM(DeepEvalBaseLLM):
|
|
|
441
442
|
return self.llm
|
|
442
443
|
|
|
443
444
|
def generate(self, prompt: str) -> str:
|
|
444
|
-
|
|
445
|
+
if isinstance(self.llm, BaseLanguageModel):
|
|
446
|
+
# Langchain LLM
|
|
447
|
+
return self.llm.invoke(prompt).content
|
|
448
|
+
else:
|
|
449
|
+
# LlamaIndex LLM
|
|
450
|
+
return self.llm.complete(prompt)
|
|
445
451
|
|
|
446
452
|
async def a_generate(self, prompt: str) -> str:
|
|
447
|
-
|
|
448
|
-
|
|
453
|
+
if isinstance(self.llm, BaseLanguageModel):
|
|
454
|
+
# Langchain LLM
|
|
455
|
+
res = await self.llm.ainvoke(prompt)
|
|
456
|
+
return res.content
|
|
457
|
+
else:
|
|
458
|
+
res = await self.llm.acomplete(prompt)
|
|
459
|
+
return res.text
|
|
449
460
|
|
|
450
461
|
def get_model_name(self):
|
|
451
462
|
return "DeepEval LLM for Moderation"
|
|
@@ -14,6 +14,7 @@ import os
|
|
|
14
14
|
|
|
15
15
|
import datarobot as dr
|
|
16
16
|
import trafaret as t
|
|
17
|
+
from llama_index.llms.openai import OpenAI
|
|
17
18
|
|
|
18
19
|
from datarobot_dome.constants import AWS_ACCOUNT_SECRET_DEFINITION_SUFFIX
|
|
19
20
|
from datarobot_dome.constants import GOOGLE_SERVICE_ACCOUNT_SECRET_DEFINITION_SUFFIX
|
|
@@ -172,7 +173,7 @@ class GuardLLMMixin:
|
|
|
172
173
|
"api_key": openai_api_key,
|
|
173
174
|
}
|
|
174
175
|
os.environ["OPENAI_API_KEY"] = openai_api_key
|
|
175
|
-
llm =
|
|
176
|
+
llm = OpenAI()
|
|
176
177
|
elif llm_type == GuardLLMType.AZURE_OPENAI:
|
|
177
178
|
if openai_api_base is None:
|
|
178
179
|
raise ValueError("OpenAI API base url is required for LLM Guard")
|
|
@@ -229,13 +230,6 @@ class GuardLLMMixin:
|
|
|
229
230
|
aws_region=config["aws_region"],
|
|
230
231
|
)
|
|
231
232
|
elif llm_type == GuardLLMType.DATAROBOT:
|
|
232
|
-
if config["type"] == GuardType.OOTB and config["ootb_type"] in [
|
|
233
|
-
OOTBType.AGENT_GOAL_ACCURACY,
|
|
234
|
-
OOTBType.TASK_ADHERENCE,
|
|
235
|
-
]:
|
|
236
|
-
# DataRobot LLM does not implement generate / agenerate yet
|
|
237
|
-
# so can't support it for Agent Goal Accuracy
|
|
238
|
-
raise NotImplementedError
|
|
239
233
|
if config.get("deployment_id") is None:
|
|
240
234
|
raise ValueError("Deployment ID is required for LLM Guard")
|
|
241
235
|
deployment = dr.Deployment.get(config["deployment_id"])
|
|
@@ -3,11 +3,11 @@ datarobot_dome/async_http_client.py,sha256=wkB4irwvnchNGzO1bk2C_HWM-GOSB3AUn5TXK
|
|
|
3
3
|
datarobot_dome/chat_helper.py,sha256=BzvtUyZSZxzOqq-5a2wQKhHhr2kMlcP1MFrHaDAeD_o,9671
|
|
4
4
|
datarobot_dome/constants.py,sha256=vM2_JkXbn4dkWARCqxNfLriSo0E05LDXVrwNktptpuc,10416
|
|
5
5
|
datarobot_dome/drum_integration.py,sha256=BnhAP-D4AaEeh4ferZ-qXnORuWQzYzw9qKAZUTZZnJU,40542
|
|
6
|
-
datarobot_dome/guard.py,sha256=
|
|
6
|
+
datarobot_dome/guard.py,sha256=xJds9hcbUaS-KD5nC1mn0GiPdBrileFUu6BuTAjDNuY,34668
|
|
7
7
|
datarobot_dome/guard_executor.py,sha256=ox5_jOHcqMaxaaagIYJJHhCwEI7Wg-rUEiu5rutsfVU,35363
|
|
8
|
-
datarobot_dome/guard_helpers.py,sha256=
|
|
8
|
+
datarobot_dome/guard_helpers.py,sha256=jfu8JTWCcxu4WD1MKxeP1n53DeebY3SSuP-t5sWyV1U,17187
|
|
9
9
|
datarobot_dome/guards/__init__.py,sha256=B5Rx8_CNCNsOpxBbRj27XOXCfRZmvmrAR-NzlzIKnDw,583
|
|
10
|
-
datarobot_dome/guards/guard_llm_mixin.py,sha256=
|
|
10
|
+
datarobot_dome/guards/guard_llm_mixin.py,sha256=OIjOHeIAwJiM8BQOfqj1fY2jy-jJfc_CNToYrzG_6xk,11871
|
|
11
11
|
datarobot_dome/llm.py,sha256=L02OvTrflmD34-FrfXebfF-zzKTeuin7fpne1Cl5psg,5719
|
|
12
12
|
datarobot_dome/metrics/__init__.py,sha256=B5Rx8_CNCNsOpxBbRj27XOXCfRZmvmrAR-NzlzIKnDw,583
|
|
13
13
|
datarobot_dome/metrics/citation_metrics.py,sha256=l2mnV1gz7nQeJ_yfaS4dcP3DFWf0p5QIBnKQ6shLnw4,4652
|
|
@@ -19,6 +19,6 @@ datarobot_dome/pipeline/pipeline.py,sha256=7UmvrZtNxTGewpgM4cf2oThHPoJSarEU1Dyp7
|
|
|
19
19
|
datarobot_dome/pipeline/vdb_pipeline.py,sha256=q3c_Z-hGUqhH6j6n8VpS3wZiBIkWgpRDsBnyJyZhiw4,9855
|
|
20
20
|
datarobot_dome/runtime.py,sha256=FD8wXOweqoQVzbZMh-mucL66xT2kGxPsJUGAcJBgwxw,1468
|
|
21
21
|
datarobot_dome/streaming.py,sha256=DkvKEH0yN0aPEWMTAjMFJB3Kx4iLGdjUMQU1pAplbeg,17751
|
|
22
|
-
datarobot_moderations-11.2.
|
|
23
|
-
datarobot_moderations-11.2.
|
|
24
|
-
datarobot_moderations-11.2.
|
|
22
|
+
datarobot_moderations-11.2.3.dist-info/METADATA,sha256=dzpTYxhAXg-NEm8Rrko8U8qvbQncQoGw93a9ZhWV3jo,4742
|
|
23
|
+
datarobot_moderations-11.2.3.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
24
|
+
datarobot_moderations-11.2.3.dist-info/RECORD,,
|
|
File without changes
|