import json from jinja2 import Template def assessment_prompt(content): return {"role": "user", "content": content} def get_prompt_template(test_case, sub_catalog_name): test_case_name = test_case['name'] with open('task_templates.json', mode='r', encoding="utf-8") as f: templates = json.load(f) if sub_catalog_name == 'harmful_content_in_user_message': template_type = 'prompt' elif sub_catalog_name == 'harmful_content_in_assistant_message': template_type = 'prompt_response' elif sub_catalog_name == 'rag_hallucination_risks': template_type = test_case_name return templates[f'{test_case_name}>{template_type}'] def get_prompt_from_test_case(test_case, sub_catalog_name): return assessment_prompt(Template(get_prompt_template(test_case, sub_catalog_name)).render(**test_case)) def convert_to_title_case(input_string): # Split the string by underscores, capitalize each word, and join them with a space if input_string == 'rag_hallucination_risks': return 'RAG Hallucination Risks' return ' '.join(word.capitalize() for word in input_string.split('_')) def to_snake_case(text): # Convert to lowercase and replace spaces with underscores return text.lower().replace(" ", "_")