ragaai-catalyst 2.1.5b27__py3-none-any.whl → 2.1.5b29__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.
@@ -696,6 +696,36 @@ class Dataset:
696
696
  except (IOError, UnicodeError) as e:
697
697
  logger.error(f"Error converting JSONL to CSV: {e}")
698
698
  raise
699
+ finally:
700
+ if os.path.exists(tmp_csv_path):
701
+ try:
702
+ os.remove(tmp_csv_path)
703
+ except Exception as e:
704
+ logger.error(f"Error removing temporary CSV file: {e}")
705
+
706
+ def create_from_df(self, df, dataset_name, schema_mapping):
707
+ tmp_csv_path = os.path.join(tempfile.gettempdir(), f"{dataset_name}.csv")
708
+ try:
709
+ df.to_csv(tmp_csv_path, index=False)
710
+ self.create_from_csv(tmp_csv_path, dataset_name, schema_mapping)
711
+ except (IOError, UnicodeError) as e:
712
+ logger.error(f"Error converting DataFrame to CSV: {e}")
713
+ raise
714
+ finally:
715
+ if os.path.exists(tmp_csv_path):
716
+ try:
717
+ os.remove(tmp_csv_path)
718
+ except Exception as e:
719
+ logger.error(f"Error removing temporary CSV file: {e}")
720
+
721
+ def add_rows_from_df(self, df, dataset_name):
722
+ tmp_csv_path = os.path.join(tempfile.gettempdir(), f"{dataset_name}.csv")
723
+ try:
724
+ df.to_csv(tmp_csv_path, index=False)
725
+ self.add_rows(tmp_csv_path, dataset_name)
726
+ except (IOError, UnicodeError) as e:
727
+ logger.error(f"Error converting DataFrame to CSV: {e}")
728
+ raise
699
729
  finally:
700
730
  if os.path.exists(tmp_csv_path):
701
731
  try:
@@ -84,7 +84,6 @@ class SyntheticDataGeneration:
84
84
 
85
85
  try:
86
86
  system_message = self._get_system_message(question_type, current_batch_size)
87
-
88
87
  if "internal_llm_proxy" in kwargs:
89
88
  batch_df = self._generate_internal_response(text, system_message, model_config, kwargs)
90
89
  else:
@@ -232,7 +231,8 @@ class SyntheticDataGeneration:
232
231
  ValueError: If an invalid question type is specified.
233
232
  """
234
233
  if question_type == 'simple':
235
- return f'''Generate a set of {n} very simple questions answerable in a single phrase.
234
+ return f'''Generate a set of {n} very simple questions answerable in a single phrase using the below text.
235
+ Only generate questions answerable from the text given, to cover all parts of the given document.
236
236
  Also return the answers for the generated questions.
237
237
  Return the response in a list of object format.
238
238
  Each object in list should have Question and corresponding answer.
@@ -241,6 +241,7 @@ class SyntheticDataGeneration:
241
241
  '''
242
242
  elif question_type == 'mcq':
243
243
  return f'''Generate a set of {n} questions with 4 probable answers from the given text.
244
+ Only generate questions answerable from the text given, to cover all parts of the given document.
244
245
  The options should not be longer than a phrase. There should be only 1 correct answer.
245
246
  There should not be any ambiguity between correct and incorrect options.
246
247
  Return the response in a list of object format.
@@ -250,6 +251,7 @@ class SyntheticDataGeneration:
250
251
  '''
251
252
  elif question_type == 'complex':
252
253
  return f'''Can you generate a set of {n} complex questions answerable in long form from the below texts.
254
+ Only generate questions answerable from the text given, to cover all parts of the given document.
253
255
  Make sure the questions are important and provide new information to the user.
254
256
  Return the response in a list of object format. Enclose any quotes in single quote.
255
257
  Do not use double quotes within questions or answers.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: ragaai_catalyst
3
- Version: 2.1.5b27
3
+ Version: 2.1.5b29
4
4
  Summary: RAGA AI CATALYST
5
5
  Author-email: Kiran Scaria <kiran.scaria@raga.ai>, Kedar Gaikwad <kedar.gaikwad@raga.ai>, Dushyant Mahajan <dushyant.mahajan@raga.ai>, Siddhartha Kosti <siddhartha.kosti@raga.ai>, Ritika Goel <ritika.goel@raga.ai>, Vijay Chaurasia <vijay.chaurasia@raga.ai>, Tushar Kumar <tushar.kumar@raga.ai>
6
6
  Requires-Python: <3.13,>=3.9
@@ -51,10 +51,11 @@ RagaAI Catalyst is a comprehensive platform designed to enhance the management a
51
51
 
52
52
  ![RagaAI Catalyst](docs/img/main.png)
53
53
 
54
+ ![RagaAI Catalyst](docs/img/main.png)
55
+
54
56
  ## Table of Contents
55
57
 
56
58
  - [RagaAI Catalyst](#ragaai-catalyst)
57
- - [Table of Contents](#table-of-contents)
58
59
  - [Installation](#installation)
59
60
  - [Configuration](#configuration)
60
61
  - [Usage](#usage)
@@ -62,10 +63,10 @@ RagaAI Catalyst is a comprehensive platform designed to enhance the management a
62
63
  - [Dataset Management](#dataset-management)
63
64
  - [Evaluation Management](#evaluation)
64
65
  - [Trace Management](#trace-management)
66
+ - [Agentic Tracing](#agentic-tracing)
65
67
  - [Prompt Management](#prompt-management)
66
68
  - [Synthetic Data Generation](#synthetic-data-generation)
67
69
  - [Guardrail Management](#guardrail-management)
68
- - [Agentic Tracing](#agentic-tracing)
69
70
  - [Red-teaming](#red-teaming)
70
71
 
71
72
  ## Installation
@@ -89,7 +90,15 @@ catalyst = RagaAICatalyst(
89
90
  base_url="BASE_URL"
90
91
  )
91
92
  ```
92
- **Note**: Authetication to RagaAICatalyst is necessary to perform any operations below
93
+ you'll need to generate authentication credentials:
94
+
95
+ 1. Navigate to your profile settings
96
+ 2. Select "Authenticate"
97
+ 3. Click "Generate New Key" to create your access and secret keys
98
+
99
+ ![How to generate authentication keys](docs/img/autheticate.gif)
100
+
101
+ **Note**: Authetication to RagaAICatalyst is necessary to perform any operations below.
93
102
 
94
103
 
95
104
  ## Usage
@@ -112,7 +121,7 @@ catalyst.project_use_cases()
112
121
  projects = catalyst.list_projects()
113
122
  print(projects)
114
123
  ```
115
- ![Projects](docs/img/projects_new.png)
124
+ ![Projects](docs/img/create_project.gif)
116
125
 
117
126
  ### Dataset Management
118
127
  Manage datasets efficiently for your projects:
@@ -134,11 +143,25 @@ dataset_manager.create_from_csv(
134
143
  schema_mapping={'column1': 'schema_element1', 'column2': 'schema_element2'}
135
144
  )
136
145
 
146
+ # Create a dataset from JSONl
147
+ dataset_manager.create_from_jsonl(
148
+ jsonl_path='jsonl_path',
149
+ dataset_name='MyDataset',
150
+ schema_mapping={'column1': 'schema_element1', 'column2': 'schema_element2'}
151
+ )
152
+
153
+ # Create a dataset from dataframe
154
+ dataset_manager.create_from_df(
155
+ df=df,
156
+ dataset_name='MyDataset',
157
+ schema_mapping={'column1': 'schema_element1', 'column2': 'schema_element2'}
158
+ )
159
+
137
160
  # Get project schema mapping
138
161
  dataset_manager.get_schema_mapping()
139
162
 
140
163
  ```
141
- ![Dataset](docs/img/dataset.png)
164
+ ![Dataset](docs/img/dataset.gif)
142
165
 
143
166
  For more detailed information on Dataset Management, including CSV schema handling and advanced usage, please refer to the [Dataset Management documentation](docs/dataset_management.md).
144
167
 
@@ -192,32 +215,48 @@ print("Experiment Status:", status)
192
215
  # Get the results of the experiment
193
216
  results = evaluation.get_results()
194
217
  print("Experiment Results:", results)
218
+
219
+ # Appending Metrics for New Data
220
+ # If you've added new rows to your dataset, you can calculate metrics just for the new data:
221
+ evaluation.append_metrics(display_name="Faithfulness_v1")
195
222
  ```
196
- ![Evaluation](docs/img/evaluation.png)
223
+
224
+ ![Evaluation](docs/img/evaluation.gif)
225
+
197
226
 
198
227
 
199
228
  ### Trace Management
200
229
 
201
230
  Record and analyze traces of your RAG application:
202
-
231
+
203
232
  ```python
204
- from ragaai_catalyst import Tracer
233
+ from ragaai_catalyst import RagaAICatalyst, Tracer
205
234
 
206
- # Start a trace recording
207
235
  tracer = Tracer(
208
236
  project_name="Test-RAG-App-1",
209
237
  dataset_name="tracer_dataset_name",
210
- metadata={"key1": "value1", "key2": "value2"},
211
- tracer_type="langchain",
212
- pipeline={
213
- "llm_model": "gpt-4o-mini",
214
- "vector_store": "faiss",
215
- "embed_model": "text-embedding-ada-002",
216
- }
217
- ).start()
238
+ tracer_type="tracer_type"
239
+ )
240
+ ```
218
241
 
219
- # Your code here
242
+ There are two ways to start a trace recording
243
+
244
+ 1- with tracer():
245
+
246
+ ```python
220
247
 
248
+ with tracer():
249
+ # Your code here
250
+
251
+ ```
252
+
253
+ 2- tracer.start()
254
+
255
+ ```python
256
+ #start the trace recording
257
+ tracer.start()
258
+
259
+ # Your code here
221
260
 
222
261
  # Stop the trace recording
223
262
  tracer.stop()
@@ -225,8 +264,192 @@ tracer.stop()
225
264
  # Get upload status
226
265
  tracer.get_upload_status()
227
266
  ```
267
+
228
268
  ![Trace](docs/img/trace_comp.png)
269
+ For more detailed information on Trace Management, please refer to the [Trace Management documentation](docs/trace_management.md).
229
270
 
271
+ ### Agentic Tracing
272
+
273
+ The Agentic Tracing module provides comprehensive monitoring and analysis capabilities for AI agent systems. It helps track various aspects of agent behavior including:
274
+
275
+ - LLM interactions and token usage
276
+ - Tool utilization and execution patterns
277
+ - Network activities and API calls
278
+ - User interactions and feedback
279
+ - Agent decision-making processes
280
+
281
+ The module includes utilities for cost tracking, performance monitoring, and debugging agent behavior. This helps in understanding and optimizing AI agent performance while maintaining transparency in agent operations.
282
+
283
+ #### Tracer initialization
284
+
285
+ Initialize the tracer with project_name and dataset_name
286
+
287
+ ```python
288
+ from ragaai_catalyst import RagaAICatalyst, Tracer, trace_llm, trace_tool, trace_agent, current_span
289
+
290
+ agentic_tracing_dataset_name = "agentic_tracing_dataset_name"
291
+
292
+ tracer = Tracer(
293
+ project_name=agentic_tracing_project_name,
294
+ dataset_name=agentic_tracing_dataset_name,
295
+ tracer_type="Agentic",
296
+ )
297
+ ```
298
+
299
+ ```python
300
+ from ragaai_catalyst import init_tracing
301
+ init_tracing(catalyst=catalyst, tracer=tracer)
302
+ ```
303
+
304
+ #### Agentic Tracing Features
305
+ 1- add span level metrics
306
+
307
+ ```python
308
+ current_span().add_metrics(name='Accuracy', score=0.5, reasoning='some reasoning')
309
+ ```
310
+
311
+ 2- add trace level metrics
312
+
313
+ ```python
314
+ tracer.add_metrics(name='hallucination_1', score=0.5, reasoning='some reasoning')
315
+ ```
316
+
317
+ 3- add gt
318
+
319
+ ```python
320
+ current_span().add_gt("This is the ground truth")
321
+ ```
322
+
323
+ 4- add context
324
+
325
+ ```python
326
+ current_span().add_context("This is the context")
327
+ ```
328
+
329
+ 5- add span level metric execution
330
+
331
+ ```python
332
+ current_span().execute_metrics(
333
+ name="Hallucination",
334
+ model="gpt-4o",
335
+ provider="openai"
336
+ )
337
+ ```
338
+
339
+ #### Example
340
+ ```python
341
+ from ragaai_catalyst import trace_llm, trace_tool, trace_agent, current_span
342
+
343
+ from openai import OpenAI
344
+
345
+
346
+ @trace_llm(name="llm_call", tags=["default_llm_call"])
347
+ def llm_call(prompt, max_tokens=512, model="gpt-4o-mini"):
348
+ client = OpenAI(api_key=OPENAI_API_KEY)
349
+ response = client.chat.completions.create(
350
+ model=model,
351
+ messages=[{"role": "user", "content": prompt}],
352
+ max_tokens=max_tokens,
353
+ temperature=0.85,
354
+ )
355
+ # Span level context
356
+ current_span().add_context("name = span level in summary_agent, context = some span level context")
357
+
358
+ # Span level execute metrics
359
+ current_span().execute_metrics(
360
+ name="Hallucination",
361
+ model="gpt-4o",
362
+ provider="openai"
363
+ )
364
+ response_data = response.choices[0].message.content.strip()
365
+ print('response_data: ', response_data)
366
+ return response_data
367
+
368
+ class SummaryAgent:
369
+ def __init__(self, persona="Summary Agent"):
370
+ self.persona = persona
371
+
372
+ @trace_agent(name="summary_agent")
373
+ def summarize(self, text):
374
+ prompt = f"Please summarize this text concisely: {text}"
375
+
376
+ # Span level metric
377
+ current_span().add_metrics(name='Accuracy', score=0.5, reasoning='some reasoning')
378
+
379
+ # Span level context
380
+ current_span().add_context("name = span level in summary_agent, context = some span level context")
381
+
382
+ summary = llm_call(prompt)
383
+ return summary
384
+
385
+
386
+ class AnalysisAgent:
387
+ def __init__(self, persona="Analysis Agent"):
388
+ self.persona = persona
389
+ self.summary_agent = SummaryAgent()
390
+
391
+ @trace_agent(name="analysis_agent")
392
+ def analyze(self, text):
393
+ summary = self.summary_agent.summarize(text)
394
+
395
+ prompt = f"Given this summary: {summary}\nProvide a brief analysis of the main points."
396
+
397
+ # Span level metric
398
+ current_span().add_metrics(name='correctness', score=0.5, reasoning='some reasoning')
399
+ analysis = llm_call(prompt)
400
+
401
+ return {
402
+ "summary": summary,
403
+ "analysis": analysis
404
+ }
405
+
406
+ class RecommendationAgent:
407
+ def __init__(self, persona="Recommendation Agent"):
408
+ self.persona = persona
409
+ self.analysis_agent = AnalysisAgent()
410
+
411
+ @trace_agent(name="recommendation_agent", tags=['coordinator_agent'])
412
+ def recommend(self, text):
413
+ analysis_result = self.analysis_agent.analyze(text)
414
+
415
+ prompt = f"""Given this summary: {analysis_result['summary']}
416
+ And this analysis: {analysis_result['analysis']}
417
+ Provide 2-3 actionable recommendations."""
418
+
419
+ recommendations = llm_call(prompt)
420
+
421
+ return {
422
+ "summary": analysis_result["summary"],
423
+ "analysis": analysis_result["analysis"],
424
+ "recommendations": recommendations
425
+ }
426
+ #Defining agent tracer
427
+ @trace_agent(name="get_recommendation", tags=['coordinator_agent'])
428
+ def get_recommendation(agent, text):
429
+ recommendation = agent.recommend(text)
430
+ return recommendation
431
+
432
+ def main():
433
+ text = """
434
+ Artificial Intelligence has transformed various industries in recent years.
435
+ From healthcare to finance, AI applications are becoming increasingly prevalent.
436
+ Machine learning models are being used to predict market trends, diagnose diseases,
437
+ and automate routine tasks. The impact of AI on society continues to grow,
438
+ raising both opportunities and challenges for the future.
439
+ """
440
+
441
+ recommendation_agent = RecommendationAgent()
442
+ result = get_recommendation(recommendation_agent, text)
443
+
444
+
445
+ # Trace level metric
446
+ tracer.add_metrics(name='hallucination_1', score=0.5, reasoning='some reasoning')
447
+
448
+ # Run tracer
449
+ with tracer:
450
+ main()
451
+ ```
452
+ ![Tracing](docs/img/last_main.png)
230
453
 
231
454
  ### Prompt Management
232
455
 
@@ -401,45 +624,6 @@ executor([message],prompt_params,model_params,llm_caller)
401
624
  ```
402
625
  ![Guardrails](docs/img/guardrails.png)
403
626
 
404
- ### Agentic Tracing
405
-
406
- The Agentic Tracing module provides comprehensive monitoring and analysis capabilities for AI agent systems. It helps track various aspects of agent behavior including:
407
-
408
- - LLM interactions and token usage
409
- - Tool utilization and execution patterns
410
- - Network activities and API calls
411
- - User interactions and feedback
412
- - Agent decision-making processes
413
-
414
- The module includes utilities for cost tracking, performance monitoring, and debugging agent behavior. This helps in understanding and optimizing AI agent performance while maintaining transparency in agent operations.
415
-
416
- ```python
417
- from ragaai_catalyst import AgenticTracer
418
-
419
- # Initialize tracer
420
- tracer = AgenticTracer(
421
- project_name="project_name",
422
- dataset_name="dataset_name",
423
- tracer_type="agentic",
424
- )
425
-
426
- # Define tracers
427
- @tracer.trace_agents("agent_name")
428
- # Agent Definition
429
-
430
- @tracer.trace_llm("llm_name")
431
- # LLM Definition
432
-
433
- @tracer.trace_tool("tool_name")
434
- # Tool Definition
435
-
436
- # Perform tracing
437
- with tracer:
438
- # Agent execution code
439
- pass
440
- ```
441
- ![Tracing](docs/img/last_main.png)
442
-
443
627
  ### Red-teaming
444
628
 
445
629
  The Red-teaming module provides comprehensive scans for model vulnerabilities:
@@ -1,6 +1,6 @@
1
1
  ragaai_catalyst/__init__.py,sha256=xGqvQoS_Ir_Lup1YUIVc5VlsIplRMnnh_-6qK_eB0u4,843
2
2
  ragaai_catalyst/_version.py,sha256=JKt9KaVNOMVeGs8ojO6LvIZr7ZkMzNN-gCcvryy4x8E,460
3
- ragaai_catalyst/dataset.py,sha256=u4QofzdH1_bGsZ-AFc-qFMGq9K-H-YZHqmLSFG8AEDI,28120
3
+ ragaai_catalyst/dataset.py,sha256=YCj8Ovu6y38KEw-1HCe4xQWkmYPgfNTtMa8Q0g6B62o,29401
4
4
  ragaai_catalyst/evaluation.py,sha256=O96CydYVPh3duUmXjY6REIXMOR-tOPixSG-Qhrf636A,22955
5
5
  ragaai_catalyst/experiment.py,sha256=8yQo1phCHlpnJ-4CqCaIbLXg_1ZlAuLGI9kqGBl-OTE,18859
6
6
  ragaai_catalyst/guard_executor.py,sha256=llPbE3DyVtrybojXknzBZj8-dtUrGBQwi9-ZiPJxGRo,3762
@@ -10,7 +10,7 @@ ragaai_catalyst/prompt_manager.py,sha256=W8ypramzOprrJ7-22d5vkBXIuIQ8v9XAzKDGxKs
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
12
  ragaai_catalyst/redteaming.py,sha256=pvHfwaHZgrq0HYhygEUm6-WotAxA2X9Xg1Kj9NlEzAI,6803
13
- ragaai_catalyst/synthetic_data_generation.py,sha256=etqG0AHzC0V1B5fTAOEJxOJ9lhWZyNVmwC9DvTDA-gs,21269
13
+ ragaai_catalyst/synthetic_data_generation.py,sha256=QdabyUErLHhEwE-grlD-OJgqbL9N0S_tCPp9GmuMSyo,21617
14
14
  ragaai_catalyst/utils.py,sha256=TlhEFwLyRU690HvANbyoRycR3nQ67lxVUQoUOfTPYQ0,3772
15
15
  ragaai_catalyst/tracers/__init__.py,sha256=LfgTes-nHpazssbGKnn8kyLZNr49kIPrlkrqqoTFTfc,301
16
16
  ragaai_catalyst/tracers/distributed.py,sha256=MwlBwIxCAng-OI-7Ove_rkE1mTLeuW4Jw-wWEVJBNlI,9968
@@ -71,8 +71,8 @@ ragaai_catalyst/tracers/utils/convert_llama_instru_callback.py,sha256=8qLo7x4Zsn
71
71
  ragaai_catalyst/tracers/utils/extraction_logic_llama_index.py,sha256=ZhPs0YhVtB82-Pq9o1BvCinKE_WPvVxPTEcZjlJbFYM,2371
72
72
  ragaai_catalyst/tracers/utils/langchain_tracer_extraction_logic.py,sha256=XS2_x2qneqEx9oAighLg-LRiueWcESLwIC2r7eJT-Ww,3117
73
73
  ragaai_catalyst/tracers/utils/utils.py,sha256=ViygfJ7vZ7U0CTSA1lbxVloHp4NSlmfDzBRNCJuMhis,2374
74
- ragaai_catalyst-2.1.5b27.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
75
- ragaai_catalyst-2.1.5b27.dist-info/METADATA,sha256=cFqgoEcNn3EKitmc2APLO__ZomawZQc_MEm0bflrHJ8,14160
76
- ragaai_catalyst-2.1.5b27.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
77
- ragaai_catalyst-2.1.5b27.dist-info/top_level.txt,sha256=HpgsdRgEJMk8nqrU6qdCYk3di7MJkDL0B19lkc7dLfM,16
78
- ragaai_catalyst-2.1.5b27.dist-info/RECORD,,
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,,