RagaAI Catalyst
RagaAI Catalyst is a comprehensive platform designed to enhance the management and optimization of LLM projects. It offers a wide range of features, including project management, dataset management, evaluation management, trace management, prompt management, synthetic data generation, and guardrail management. These functionalities enable you to efficiently evaluate, and safeguard your LLM applications.
Table of Contents
Installation
To install RagaAI Catalyst, you can use pip:
pip install ragaai-catalyst
Configuration
Before using RagaAI Catalyst, you need to set up your credentials. You can do this by setting environment variables or passing them directly to the RagaAICatalyst
class:
from ragaai_catalyst import RagaAICatalyst
catalyst = RagaAICatalyst(
access_key="YOUR_ACCESS_KEY",
secret_key="YOUR_SECRET_KEY",
base_url="BASE_URL"
)
Note: Authetication to RagaAICatalyst is necessary to perform any operations below
Usage
Project Management
Create and manage projects using RagaAI Catalyst:
project = catalyst.create_project(
project_name="Test-RAG-App-1",
usecase="Chatbot"
)
catalyst.project_use_cases()
projects = catalyst.list_projects()
print(projects)
Dataset Management
Manage datasets efficiently for your projects:
from ragaai_catalyst import Dataset
dataset_manager = Dataset(project_name="project_name")
datasets = dataset_manager.list_datasets()
print("Existing Datasets:", datasets)
dataset_manager.create_from_csv(
csv_path='path/to/your.csv',
dataset_name='MyDataset',
schema_mapping={'column1': 'schema_element1', 'column2': 'schema_element2'}
)
dataset_manager.get_schema_mapping()
For more detailed information on Dataset Management, including CSV schema handling and advanced usage, please refer to the Dataset Management documentation.
Evaluation
Create and manage metric evaluation of your RAG application:
from ragaai_catalyst import Evaluation
evaluation = Evaluation(
project_name="Test-RAG-App-1",
dataset_name="MyDataset",
)
evaluation.list_metrics()
schema_mapping={
'Query': 'prompt',
'response': 'response',
'Context': 'context',
'expectedResponse': 'expected_response'
}
evaluation.add_metrics(
metrics=[
{"name": "Faithfulness", "config": {"model": "gpt-4o-mini", "provider": "openai", "threshold": {"gte": 0.232323}}, "column_name": "Faithfulness_v1", "schema_mapping": schema_mapping},
]
)
evaluation.add_metrics(
metrics=[
{"name": "Faithfulness", "config": {"model": "gpt-4o-mini", "provider": "openai", "threshold": {"gte": 0.323}}, "column_name": "Faithfulness_gte", "schema_mapping": schema_mapping},
{"name": "Hallucination", "config": {"model": "gpt-4o-mini", "provider": "openai", "threshold": {"lte": 0.323}}, "column_name": "Hallucination_lte", "schema_mapping": schema_mapping},
{"name": "Hallucination", "config": {"model": "gpt-4o-mini", "provider": "openai", "threshold": {"eq": 0.323}}, "column_name": "Hallucination_eq", "schema_mapping": schema_mapping},
]
)
status = evaluation.get_status()
print("Experiment Status:", status)
results = evaluation.get_results()
print("Experiment Results:", results)
Trace Management
Record and analyze traces of your RAG application:
from ragaai_catalyst import Tracer
tracer = Tracer(
project_name="Test-RAG-App-1",
dataset_name="tracer_dataset_name"
metadata={"key1": "value1", "key2": "value2"},
tracer_type="langchain",
pipeline={
"llm_model": "gpt-3.5-turbo",
"vector_store": "faiss",
"embed_model": "text-embedding-ada-002",
}
).start()
tracer.stop()
tracer.get_upload_status()
Prompt Management
Manage and use prompts efficiently in your projects:
from ragaai_catalyst import PromptManager
prompt_manager = PromptManager(project_name="Test-RAG-App-1")
prompts = prompt_manager.list_prompts()
print("Available prompts:", prompts)
prompt_name = "your_prompt_name"
prompt = prompt_manager.get_prompt(prompt_name)
prompt_name = "your_prompt_name"
version = "v1"
prompt = prompt_manager.get_prompt(prompt_name,version)
variable = prompt.get_variables()
print("variable:",variable)
prompt_content = prompt.get_prompt_content()
print("prompt_content:", prompt_content)
compiled_prompt = prompt.compile(query="What's the weather?", context="sunny", llm_response="It's sunny today")
print("Compiled prompt:", compiled_prompt)
import openai
def get_openai_response(prompt):
client = openai.OpenAI()
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=prompt
)
return response.choices[0].message.content
openai_response = get_openai_response(compiled_prompt)
print("openai_response:", openai_response)
import litellm
def get_litellm_response(prompt):
response = litellm.completion(
model="gpt-4o-mini",
messages=prompt
)
return response.choices[0].message.content
litellm_response = get_litellm_response(compiled_prompt)
print("litellm_response:", litellm_response)
For more detailed information on Prompt Management, please refer to the Prompt Management documentation.
Synthetic Data Generation
from ragaai_catalyst import SyntheticDataGeneration
sdg = SyntheticDataGeneration()
text = sdg.process_document(input_data="file_path")
result = sdg.generate_qna(text, question_type ='complex',model_config={"provider":"openai","model":"openai/gpt-3.5-turbo"},n=5)
print(result.head())
sdg.get_supported_qna()
sdg.get_supported_providers()
Guardrail Management
from ragaai_catalyst import GuardrailsManager
gdm = GuardrailsManager(project_name=project_name)
guardrails_list = gdm.list_guardrails()
print('guardrails_list:', guardrails_list)
fail_conditions = gdm.list_fail_condition()
print('fail_conditions;', fail_conditions)
deployment_list = gdm.list_deployment_ids()
print('deployment_list:', deployment_list)
deployment_id_detail = gdm.get_deployment(17)
print('deployment_id_detail:', deployment_id_detail)
guardrails_config = {"guardrailFailConditions": ["FAIL"],
"deploymentFailCondition": "ALL_FAIL",
"alternateResponse": "Your alternate response"}
guardrails = [
{
"displayName": "Response_Evaluator",
"name": "Response Evaluator",
"config":{
"mappings": [{
"schemaName": "Text",
"variableName": "Response"
}],
"params": {
"isActive": {"value": False},
"isHighRisk": {"value": True},
"threshold": {"eq": 0},
"competitors": {"value": ["Google","Amazon"]}
}
}
},
{
"displayName": "Regex_Check",
"name": "Regex Check",
"config":{
"mappings": [{
"schemaName": "Text",
"variableName": "Response"
}],
"params":{
"isActive": {"value": False},
"isHighRisk": {"value": True},
"threshold": {"lt1": 1}
}
}
}
]
gdm.add_guardrails(deployment_id, guardrails, guardrails_config)
from ragaai_catalyst import GuardExecutor
executor = GuardExecutor(deployment_id,gdm,field_map={'context':'document'})
message={'role':'user',
'content':'What is the capital of France'
}
prompt_params={'document':' France'}
model_params = {'temperature':.7,'model':'gpt-4o-mini'}
llm_caller = 'litellm'
executor([message],prompt_params,model_params,llm_caller)