ragaai-catalyst 2.1.5b29__py3-none-any.whl → 2.1.5b30__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.
Files changed (26) hide show
  1. ragaai_catalyst/__init__.py +2 -0
  2. ragaai_catalyst/redteaming/__init__.py +7 -0
  3. ragaai_catalyst/redteaming/config/detectors.toml +13 -0
  4. ragaai_catalyst/redteaming/data_generator/scenario_generator.py +95 -0
  5. ragaai_catalyst/redteaming/data_generator/test_case_generator.py +120 -0
  6. ragaai_catalyst/redteaming/evaluator.py +125 -0
  7. ragaai_catalyst/redteaming/llm_generator.py +83 -0
  8. ragaai_catalyst/redteaming/llm_generator_litellm.py +66 -0
  9. ragaai_catalyst/redteaming/red_teaming.py +329 -0
  10. ragaai_catalyst/redteaming/requirements.txt +4 -0
  11. ragaai_catalyst/redteaming/tests/grok.ipynb +97 -0
  12. ragaai_catalyst/redteaming/tests/stereotype.ipynb +2258 -0
  13. ragaai_catalyst/redteaming/upload_result.py +38 -0
  14. ragaai_catalyst/redteaming/utils/issue_description.py +114 -0
  15. ragaai_catalyst/redteaming_old.py +171 -0
  16. ragaai_catalyst/synthetic_data_generation.py +344 -13
  17. ragaai_catalyst/tracers/agentic_tracing/tracers/llm_tracer.py +2 -6
  18. ragaai_catalyst/tracers/agentic_tracing/utils/llm_utils.py +22 -4
  19. ragaai_catalyst/tracers/agentic_tracing/utils/zip_list_of_unique_files.py +0 -13
  20. ragaai_catalyst/tracers/tracer.py +33 -2
  21. {ragaai_catalyst-2.1.5b29.dist-info → ragaai_catalyst-2.1.5b30.dist-info}/METADATA +19 -2
  22. {ragaai_catalyst-2.1.5b29.dist-info → ragaai_catalyst-2.1.5b30.dist-info}/RECORD +25 -12
  23. ragaai_catalyst/redteaming.py +0 -171
  24. {ragaai_catalyst-2.1.5b29.dist-info → ragaai_catalyst-2.1.5b30.dist-info}/LICENSE +0 -0
  25. {ragaai_catalyst-2.1.5b29.dist-info → ragaai_catalyst-2.1.5b30.dist-info}/WHEEL +0 -0
  26. {ragaai_catalyst-2.1.5b29.dist-info → ragaai_catalyst-2.1.5b30.dist-info}/top_level.txt +0 -0
@@ -1,4 +1,4 @@
1
- ragaai_catalyst/__init__.py,sha256=xGqvQoS_Ir_Lup1YUIVc5VlsIplRMnnh_-6qK_eB0u4,843
1
+ ragaai_catalyst/__init__.py,sha256=2wfkucAbb3Bt_p2KHelkg9zBQp4yC4iZanltyieG18w,895
2
2
  ragaai_catalyst/_version.py,sha256=JKt9KaVNOMVeGs8ojO6LvIZr7ZkMzNN-gCcvryy4x8E,460
3
3
  ragaai_catalyst/dataset.py,sha256=YCj8Ovu6y38KEw-1HCe4xQWkmYPgfNTtMa8Q0g6B62o,29401
4
4
  ragaai_catalyst/evaluation.py,sha256=O96CydYVPh3duUmXjY6REIXMOR-tOPixSG-Qhrf636A,22955
@@ -9,15 +9,28 @@ ragaai_catalyst/internal_api_completion.py,sha256=DdICI5yfEudiOAIC8L4oxH0Qz7kX-B
9
9
  ragaai_catalyst/prompt_manager.py,sha256=W8ypramzOprrJ7-22d5vkBXIuIQ8v9XAzKDGxKsTK28,16550
10
10
  ragaai_catalyst/proxy_call.py,sha256=CHxldeceZUaLU-to_hs_Kf1z_b2vHMssLS_cOBedu78,5499
11
11
  ragaai_catalyst/ragaai_catalyst.py,sha256=5nVg3_-lcvhrXjNkPTeGhe3tdUjm_4ZIctOcqWXBkRA,17939
12
- ragaai_catalyst/redteaming.py,sha256=pvHfwaHZgrq0HYhygEUm6-WotAxA2X9Xg1Kj9NlEzAI,6803
13
- ragaai_catalyst/synthetic_data_generation.py,sha256=QdabyUErLHhEwE-grlD-OJgqbL9N0S_tCPp9GmuMSyo,21617
12
+ ragaai_catalyst/redteaming_old.py,sha256=W2d89Ok8W-C8g7TBM3fDIFLof3q9FuYSr0jcryH2XQo,7097
13
+ ragaai_catalyst/synthetic_data_generation.py,sha256=6PUHNlFFZ0WXoR2mnjT50uven7FeCvbNRmFtmK6ta1E,37057
14
14
  ragaai_catalyst/utils.py,sha256=TlhEFwLyRU690HvANbyoRycR3nQ67lxVUQoUOfTPYQ0,3772
15
+ ragaai_catalyst/redteaming/__init__.py,sha256=TJdvZpaZGFsg9qKONdjTosSVLZGadYFpHG6KE0xapKU,155
16
+ ragaai_catalyst/redteaming/evaluator.py,sha256=FZzSlKhNkGAnKKNAhyAb-hIWkKVckZefQETaaHDR-z8,4512
17
+ ragaai_catalyst/redteaming/llm_generator.py,sha256=if8fqsPARF4Jjj_RS9GePLDwq5vh8VeVYjs3gnHuZLI,3380
18
+ ragaai_catalyst/redteaming/llm_generator_litellm.py,sha256=Sus87gMXNYqDdkRSvBMDCzZbm2gQN6W4uPKru02xq0w,2580
19
+ ragaai_catalyst/redteaming/red_teaming.py,sha256=a7JUDAYwMhjB-L0u0rexdYjX5IuhS1jOQWuZUoS1HVk,14871
20
+ ragaai_catalyst/redteaming/requirements.txt,sha256=7JJZi9DsGKqwa8-aPQjI__qMaWFIKKQzpxpv0251xx4,54
21
+ ragaai_catalyst/redteaming/upload_result.py,sha256=Z23_6OqfRKczRfM7VsN6byAvb_P2bDiIKWy0uf9tQWQ,894
22
+ ragaai_catalyst/redteaming/config/detectors.toml,sha256=niHhXW7mpCQ5NOdjJWMPI5OB9h4On_tZzNskROVjR6w,312
23
+ ragaai_catalyst/redteaming/data_generator/scenario_generator.py,sha256=sAwOYCJk7tbK9oa9mfDoQllWFV3zYPR5KrcV9G2vXEs,3346
24
+ ragaai_catalyst/redteaming/data_generator/test_case_generator.py,sha256=UgXyuLYmwkGOe45Jc3OzXI_c_xp1U7KMlnr6u7my6zQ,4303
25
+ ragaai_catalyst/redteaming/tests/grok.ipynb,sha256=g6p4MVBhdla3IG4Atk56IPsj7lSh6-wxxhHadYJaK8s,2385
26
+ ragaai_catalyst/redteaming/tests/stereotype.ipynb,sha256=-FoA3BxTF3vZs3U5c7N-Q3oirHyV2Yb8g_nl0qD_8jk,121539
27
+ ragaai_catalyst/redteaming/utils/issue_description.py,sha256=iB0XbeOjdqHTPrikCKS_wOtJW4_JKfQPI1mgyvX0V-Q,6946
15
28
  ragaai_catalyst/tracers/__init__.py,sha256=LfgTes-nHpazssbGKnn8kyLZNr49kIPrlkrqqoTFTfc,301
16
29
  ragaai_catalyst/tracers/distributed.py,sha256=MwlBwIxCAng-OI-7Ove_rkE1mTLeuW4Jw-wWEVJBNlI,9968
17
30
  ragaai_catalyst/tracers/langchain_callback.py,sha256=KooENtkX0Hp0S_d_1WI3iH3qNVt-ZcnwOKVlydv4dUk,33518
18
31
  ragaai_catalyst/tracers/llamaindex_callback.py,sha256=ZY0BJrrlz-P9Mg2dX-ZkVKG3gSvzwqBtk7JL_05MiYA,14028
19
32
  ragaai_catalyst/tracers/llamaindex_instrumentation.py,sha256=Ys_jLkvVqo12bKgXDmkp4TxJu9HkBATrFE8cIcTYxWw,14329
20
- ragaai_catalyst/tracers/tracer.py,sha256=NZh3lgp2sqcUoovgLFkNC-XTnHAOR9UVUrLrGIECPOg,21563
33
+ ragaai_catalyst/tracers/tracer.py,sha256=iO5m4ev0ruXjp-YjRMuN_mhr0Cd499Phz6ZYlfJ1yak,22889
21
34
  ragaai_catalyst/tracers/upload_traces.py,sha256=OKsc-Obf8bJvKBprt3dqj8GQQNkoX3kT_t8TBDi9YDQ,5670
22
35
  ragaai_catalyst/tracers/agentic_tracing/README.md,sha256=X4QwLb7-Jg7GQMIXj-SerZIgDETfw-7VgYlczOR8ZeQ,4508
23
36
  ragaai_catalyst/tracers/agentic_tracing/__init__.py,sha256=yf6SKvOPSpH-9LiKaoLKXwqj5sez8F_5wkOb91yp0oE,260
@@ -34,7 +47,7 @@ ragaai_catalyst/tracers/agentic_tracing/tracers/agent_tracer.py,sha256=LzbsHvELw
34
47
  ragaai_catalyst/tracers/agentic_tracing/tracers/base.py,sha256=0eFrHtEddxYBQnkilGXOAMpen09bFV3jkymywTjDSU4,46139
35
48
  ragaai_catalyst/tracers/agentic_tracing/tracers/custom_tracer.py,sha256=OBJJjFSvwRjCGNJyqX3yIfC1W05ZN2QUXasCJ4gmCjQ,13930
36
49
  ragaai_catalyst/tracers/agentic_tracing/tracers/langgraph_tracer.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
37
- ragaai_catalyst/tracers/agentic_tracing/tracers/llm_tracer.py,sha256=knHM7mzr7JZhA0kEzwdNQ0ESDoBHYyi7Ffn5hn6jQGA,50360
50
+ ragaai_catalyst/tracers/agentic_tracing/tracers/llm_tracer.py,sha256=BvC_jCN2EObfFZKu4-POnE_YmlH4Q_pjF9gZLV1AwZ0,50226
38
51
  ragaai_catalyst/tracers/agentic_tracing/tracers/main_tracer.py,sha256=PYYNNeFfsQpw5D4A0jzwNYhAvC1bMT5vtAGaTsgk2xY,16112
39
52
  ragaai_catalyst/tracers/agentic_tracing/tracers/network_tracer.py,sha256=m8CxYkl7iMiFya_lNwN1ykBc3Pmo-2pR_2HmpptwHWQ,10352
40
53
  ragaai_catalyst/tracers/agentic_tracing/tracers/tool_tracer.py,sha256=xxrliKPfdfbIZRZqMnUewsaTD8_Hv0dbuoBivNZGD4U,21674
@@ -50,14 +63,14 @@ ragaai_catalyst/tracers/agentic_tracing/utils/create_dataset_schema.py,sha256=lg
50
63
  ragaai_catalyst/tracers/agentic_tracing/utils/file_name_tracker.py,sha256=YG601l1a29ov9VPu9Vl4RXxgL7l16k54_WWnoTNoG58,2064
51
64
  ragaai_catalyst/tracers/agentic_tracing/utils/generic.py,sha256=WwXT01xmp8MSr7KinuDCSK9a1ifpLcT7ajFkvYviG_A,1190
52
65
  ragaai_catalyst/tracers/agentic_tracing/utils/get_user_trace_metrics.py,sha256=vPZ4dn4EHFW0kqd1GyRpsYXbfrRrd0DXCmh-pzsDBNE,1109
53
- ragaai_catalyst/tracers/agentic_tracing/utils/llm_utils.py,sha256=gbPqWtJINW8JVlkM41UmF5zGR8oj8Q6g9KQIS3moQYM,20439
66
+ ragaai_catalyst/tracers/agentic_tracing/utils/llm_utils.py,sha256=h29o5xkEjE9v71pRTtJJTM_fPTj4GijCPYE0xypNF7E,21093
54
67
  ragaai_catalyst/tracers/agentic_tracing/utils/model_costs.json,sha256=2tzGw_cKCTPcfjEm7iGvFE6pTw7gMTPzeBov_MTaXNY,321336
55
68
  ragaai_catalyst/tracers/agentic_tracing/utils/span_attributes.py,sha256=qmODERcFZhc8MX24boFCXkkh6sJ-vZngRHPvxhyWFeE,4347
56
69
  ragaai_catalyst/tracers/agentic_tracing/utils/supported_llm_provider.toml,sha256=LvFDivDIE96Zasp-fgDEqUJ5GEQZUawQucR3aOcSUTY,926
57
70
  ragaai_catalyst/tracers/agentic_tracing/utils/system_monitor.py,sha256=H8WNsk4v_5T6OUw4TFOzlDLjQhJwjh1nAMyMAoqMEi4,6946
58
71
  ragaai_catalyst/tracers/agentic_tracing/utils/trace_utils.py,sha256=go7FVnofviATDph-j8sk2juv09CGSRt1Vq4U868Fhd8,2259
59
72
  ragaai_catalyst/tracers/agentic_tracing/utils/unique_decorator.py,sha256=G027toV-Km20JjKrc-Y_PilQ8ABEKrBvvzgLTnqVg7I,5819
60
- ragaai_catalyst/tracers/agentic_tracing/utils/zip_list_of_unique_files.py,sha256=4Iu_pJPVS6C7S6aHvJkz7q6jVw135EVAiiaTjtyjQ8s,20180
73
+ ragaai_catalyst/tracers/agentic_tracing/utils/zip_list_of_unique_files.py,sha256=4TeCGsFF26249fV6dJHLTZDrRa93SG9oer4rudoF8Y4,19443
61
74
  ragaai_catalyst/tracers/exporters/__init__.py,sha256=kVA8zp05h3phu4e-iHSlnznp_PzMRczB7LphSsZgUjg,138
62
75
  ragaai_catalyst/tracers/exporters/file_span_exporter.py,sha256=RgGteu-NVGprXKkynvyIO5yOjpbtA41R3W_NzCjnkwE,6445
63
76
  ragaai_catalyst/tracers/exporters/raga_exporter.py,sha256=6xvjWXyh8XPkHKSLLmAZUQSvwuyY17ov8pv2VdfI0qA,17875
@@ -71,8 +84,8 @@ ragaai_catalyst/tracers/utils/convert_llama_instru_callback.py,sha256=8qLo7x4Zsn
71
84
  ragaai_catalyst/tracers/utils/extraction_logic_llama_index.py,sha256=ZhPs0YhVtB82-Pq9o1BvCinKE_WPvVxPTEcZjlJbFYM,2371
72
85
  ragaai_catalyst/tracers/utils/langchain_tracer_extraction_logic.py,sha256=XS2_x2qneqEx9oAighLg-LRiueWcESLwIC2r7eJT-Ww,3117
73
86
  ragaai_catalyst/tracers/utils/utils.py,sha256=ViygfJ7vZ7U0CTSA1lbxVloHp4NSlmfDzBRNCJuMhis,2374
74
- ragaai_catalyst-2.1.5b29.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
75
- ragaai_catalyst-2.1.5b29.dist-info/METADATA,sha256=VtRy6oG0L-rNaky2LVNVNvXV6pAHjdRs6aMah4Qp3yM,19472
76
- ragaai_catalyst-2.1.5b29.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
77
- ragaai_catalyst-2.1.5b29.dist-info/top_level.txt,sha256=HpgsdRgEJMk8nqrU6qdCYk3di7MJkDL0B19lkc7dLfM,16
78
- ragaai_catalyst-2.1.5b29.dist-info/RECORD,,
87
+ ragaai_catalyst-2.1.5b30.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
88
+ ragaai_catalyst-2.1.5b30.dist-info/METADATA,sha256=qnPc-QVuCF7AesHJx66KVLwkIirI-2eIJfI0napvEOc,20005
89
+ ragaai_catalyst-2.1.5b30.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
90
+ ragaai_catalyst-2.1.5b30.dist-info/top_level.txt,sha256=HpgsdRgEJMk8nqrU6qdCYk3di7MJkDL0B19lkc7dLfM,16
91
+ ragaai_catalyst-2.1.5b30.dist-info/RECORD,,
@@ -1,171 +0,0 @@
1
- import logging
2
- import os
3
- from typing import Callable, Optional
4
-
5
- import giskard as scanner
6
- import pandas as pd
7
-
8
- logging.getLogger('giskard.core').disabled = True
9
- logging.getLogger('giskard.scanner.logger').disabled = True
10
- logging.getLogger('giskard.models.automodel').disabled = True
11
- logging.getLogger('giskard.datasets.base').disabled = True
12
- logging.getLogger('giskard.utils.logging_utils').disabled = True
13
-
14
-
15
- class RedTeaming:
16
-
17
- def __init__(self,
18
- provider: Optional[str] = "openai",
19
- model: Optional[str] = None,
20
- api_key: Optional[str] = None,
21
- api_base: Optional[str] = None,
22
- api_version: Optional[str] = None):
23
- self.provider = provider.lower()
24
- self.model = model
25
- if not self.provider:
26
- raise ValueError("Model configuration must be provided with a valid provider and model.")
27
- if self.provider == "openai":
28
- if api_key is not None:
29
- os.environ["OPENAI_API_KEY"] = api_key
30
- if os.getenv("OPENAI_API_KEY") is None:
31
- raise ValueError("API key must be provided for OpenAI.")
32
- elif self.provider == "gemini":
33
- if api_key is not None:
34
- os.environ["GEMINI_API_KEY"] = api_key
35
- if os.getenv("GEMINI_API_KEY") is None:
36
- raise ValueError("API key must be provided for Gemini.")
37
- elif self.provider == "azure":
38
- if api_key is not None:
39
- os.environ["AZURE_API_KEY"] = api_key
40
- if api_base is not None:
41
- os.environ["AZURE_API_BASE"] = api_base
42
- if api_version is not None:
43
- os.environ["AZURE_API_VERSION"] = api_version
44
- if os.getenv("AZURE_API_KEY") is None:
45
- raise ValueError("API key must be provided for Azure.")
46
- if os.getenv("AZURE_API_BASE") is None:
47
- raise ValueError("API base must be provided for Azure.")
48
- if os.getenv("AZURE_API_VERSION") is None:
49
- raise ValueError("API version must be provided for Azure.")
50
- else:
51
- raise ValueError(f"Provider is not recognized.")
52
-
53
- def run_scan(
54
- self,
55
- model: Callable,
56
- evaluators: Optional[list] = None,
57
- save_report: bool = True
58
- ) -> pd.DataFrame:
59
- """
60
- Runs red teaming on the provided model and returns a DataFrame of the results.
61
-
62
- :param model: The model function provided by the user (can be sync or async).
63
- :param evaluators: Optional list of scan metrics to run.
64
- :param save_report: Boolean flag indicating whether to save the scan report as a CSV file.
65
- :return: A DataFrame containing the scan report.
66
- """
67
- import asyncio
68
- import inspect
69
-
70
- self.set_scanning_model(self.provider, self.model)
71
-
72
- supported_evaluators = self.get_supported_evaluators()
73
- if evaluators:
74
- if isinstance(evaluators, str):
75
- evaluators = [evaluators]
76
- invalid_evaluators = [evaluator for evaluator in evaluators if evaluator not in supported_evaluators]
77
- if invalid_evaluators:
78
- raise ValueError(f"Invalid evaluators: {invalid_evaluators}. "
79
- f"Allowed evaluators: {supported_evaluators}.")
80
-
81
- # Handle async model functions by wrapping them in a sync function
82
- if inspect.iscoroutinefunction(model):
83
- def sync_wrapper(*args, **kwargs):
84
- try:
85
- # Try to get the current event loop
86
- loop = asyncio.get_event_loop()
87
- except RuntimeError:
88
- # If no event loop exists (e.g., in Jupyter), create a new one
89
- loop = asyncio.new_event_loop()
90
- asyncio.set_event_loop(loop)
91
-
92
- try:
93
- # Handle both IPython and regular Python environments
94
- import nest_asyncio
95
- nest_asyncio.apply()
96
- except ImportError:
97
- pass # nest_asyncio not available, continue without it
98
-
99
- return loop.run_until_complete(model(*args, **kwargs))
100
- wrapped_model = sync_wrapper
101
- else:
102
- wrapped_model = model
103
-
104
- model_instance = scanner.Model(
105
- model=wrapped_model,
106
- model_type="text_generation",
107
- name="RagaAI's Scan",
108
- description="RagaAI's RedTeaming Scan",
109
- feature_names=["question"],
110
- )
111
-
112
- try:
113
- report = scanner.scan(model_instance, only=evaluators, raise_exceptions=True) if evaluators \
114
- else scanner.scan(model_instance, raise_exceptions=True)
115
- except Exception as e:
116
- raise RuntimeError(f"Error occurred during model scan: {str(e)}")
117
-
118
- report_df = report.to_dataframe()
119
-
120
- if save_report:
121
- report_df.to_csv("raga-ai_red-teaming_scan.csv", index=False)
122
-
123
- return report_df
124
-
125
- def get_supported_evaluators(self):
126
- """Contains tags corresponding to the 'llm' and 'robustness' directories in the giskard > scanner library"""
127
- return {'control_chars_injection',
128
- 'discrimination',
129
- 'ethical_bias',
130
- 'ethics',
131
- 'faithfulness',
132
- 'generative',
133
- 'hallucination',
134
- 'harmfulness',
135
- 'implausible_output',
136
- 'information_disclosure',
137
- 'jailbreak',
138
- 'llm',
139
- 'llm_harmful_content',
140
- 'llm_stereotypes_detector',
141
- 'misinformation',
142
- 'output_formatting',
143
- 'prompt_injection',
144
- 'robustness',
145
- 'stereotypes',
146
- 'sycophancy',
147
- 'text_generation',
148
- 'text_perturbation'}
149
-
150
- def set_scanning_model(self, provider, model=None):
151
- """
152
- Sets the LLM model for Giskard based on the provider.
153
-
154
- :param provider: The LLM provider (e.g., "openai", "gemini", "azure").
155
- :param model: The specific model name to use (optional).
156
- :raises ValueError: If the provider is "azure" and no model is provided.
157
- """
158
- default_models = {
159
- "openai": "gpt-4o",
160
- "gemini": "gemini-1.5-pro"
161
- }
162
-
163
- if provider == "azure" and model is None:
164
- raise ValueError("Model must be provided for Azure.")
165
-
166
- selected_model = model if model is not None else default_models.get(provider)
167
-
168
- if selected_model is None:
169
- raise ValueError(f"Unsupported provider: {provider}")
170
-
171
- scanner.llm.set_llm_model(selected_model)