Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

graders.test.ts 5.6 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
  1. import { getGraderById } from '../../src/redteam/graders';
  2. import { AegisGrader } from '../../src/redteam/plugins/aegis';
  3. import { AsciiSmugglingGrader } from '../../src/redteam/plugins/asciiSmuggling';
  4. import { BeavertailsGrader } from '../../src/redteam/plugins/beavertails';
  5. import { BiasGrader } from '../../src/redteam/plugins/bias';
  6. import { FinancialCalculationErrorPluginGrader } from '../../src/redteam/plugins/financial/financialCalculationError';
  7. import { FinancialComplianceViolationPluginGrader } from '../../src/redteam/plugins/financial/financialComplianceViolation';
  8. import { FinancialDataLeakagePluginGrader } from '../../src/redteam/plugins/financial/financialDataLeakage';
  9. import { FinancialHallucinationPluginGrader } from '../../src/redteam/plugins/financial/financialHallucination';
  10. import { FinancialSycophancyPluginGrader } from '../../src/redteam/plugins/financial/financialSycophancy';
  11. import {
  12. HarmfulGrader,
  13. MisinformationDisinformationGrader,
  14. } from '../../src/redteam/plugins/harmful/graders';
  15. import { MCPPluginGrader } from '../../src/redteam/plugins/mcp';
  16. import { MedicalAnchoringBiasPluginGrader } from '../../src/redteam/plugins/medical/medicalAnchoringBias';
  17. import { MedicalHallucinationPluginGrader } from '../../src/redteam/plugins/medical/medicalHallucination';
  18. import { OffTopicPluginGrader } from '../../src/redteam/plugins/offTopic';
  19. import { PlinyGrader } from '../../src/redteam/plugins/pliny';
  20. import { ToolDiscoveryGrader } from '../../src/redteam/plugins/toolDiscovery';
  21. import { ToxicChatGrader } from '../../src/redteam/plugins/toxicChat';
  22. import { UnsafeBenchGrader } from '../../src/redteam/plugins/unsafebench';
  23. describe('getGraderById', () => {
  24. it('should return correct grader for valid ID', () => {
  25. const asciiGrader = getGraderById('promptfoo:redteam:ascii-smuggling');
  26. expect(asciiGrader).toBeInstanceOf(AsciiSmugglingGrader);
  27. const beavertailsGrader = getGraderById('promptfoo:redteam:beavertails');
  28. expect(beavertailsGrader).toBeInstanceOf(BeavertailsGrader);
  29. const harmfulGrader = getGraderById('promptfoo:redteam:harmful');
  30. expect(harmfulGrader).toBeInstanceOf(HarmfulGrader);
  31. const unsafebenchGrader = getGraderById('promptfoo:redteam:unsafebench');
  32. expect(unsafebenchGrader).toBeInstanceOf(UnsafeBenchGrader);
  33. const plinyGrader = getGraderById('promptfoo:redteam:pliny');
  34. expect(plinyGrader).toBeInstanceOf(PlinyGrader);
  35. const toxicChatGrader = getGraderById('promptfoo:redteam:toxic-chat');
  36. expect(toxicChatGrader).toBeInstanceOf(ToxicChatGrader);
  37. const financialCalculationGrader = getGraderById(
  38. 'promptfoo:redteam:financial:calculation-error',
  39. );
  40. expect(financialCalculationGrader).toBeInstanceOf(FinancialCalculationErrorPluginGrader);
  41. const financialComplianceGrader = getGraderById(
  42. 'promptfoo:redteam:financial:compliance-violation',
  43. );
  44. expect(financialComplianceGrader).toBeInstanceOf(FinancialComplianceViolationPluginGrader);
  45. const financialDataLeakageGrader = getGraderById('promptfoo:redteam:financial:data-leakage');
  46. expect(financialDataLeakageGrader).toBeInstanceOf(FinancialDataLeakagePluginGrader);
  47. const financialHallucinationGrader = getGraderById('promptfoo:redteam:financial:hallucination');
  48. expect(financialHallucinationGrader).toBeInstanceOf(FinancialHallucinationPluginGrader);
  49. const financialSycophancyGrader = getGraderById('promptfoo:redteam:financial:sycophancy');
  50. expect(financialSycophancyGrader).toBeInstanceOf(FinancialSycophancyPluginGrader);
  51. const aegisGrader = getGraderById('promptfoo:redteam:aegis');
  52. expect(aegisGrader).toBeInstanceOf(AegisGrader);
  53. const mcpGrader = getGraderById('promptfoo:redteam:mcp');
  54. expect(mcpGrader).toBeInstanceOf(MCPPluginGrader);
  55. const medicalAnchoringBiasGrader = getGraderById('promptfoo:redteam:medical:anchoring-bias');
  56. expect(medicalAnchoringBiasGrader).toBeInstanceOf(MedicalAnchoringBiasPluginGrader);
  57. const medicalHallucinationGrader = getGraderById('promptfoo:redteam:medical:hallucination');
  58. expect(medicalHallucinationGrader).toBeInstanceOf(MedicalHallucinationPluginGrader);
  59. const offTopicGrader = getGraderById('promptfoo:redteam:off-topic');
  60. expect(offTopicGrader).toBeInstanceOf(OffTopicPluginGrader);
  61. const toolDiscoveryGrader = getGraderById('promptfoo:redteam:tool-discovery');
  62. expect(toolDiscoveryGrader).toBeInstanceOf(ToolDiscoveryGrader);
  63. const biasGrader = getGraderById('promptfoo:redteam:bias');
  64. expect(biasGrader).toBeInstanceOf(BiasGrader);
  65. });
  66. it('should return specific grader for misinformation-disinformation', () => {
  67. const misinformationGrader = getGraderById(
  68. 'promptfoo:redteam:harmful:misinformation-disinformation',
  69. );
  70. expect(misinformationGrader).toBeInstanceOf(MisinformationDisinformationGrader);
  71. expect(misinformationGrader?.id).toBe(
  72. 'promptfoo:redteam:harmful:misinformation-disinformation',
  73. );
  74. });
  75. it('should return harmful grader for IDs starting with promptfoo:redteam:harmful', () => {
  76. const specificHarmfulGrader = getGraderById('promptfoo:redteam:harmful:specific-type');
  77. expect(specificHarmfulGrader).toBeInstanceOf(HarmfulGrader);
  78. const anotherHarmfulGrader = getGraderById('promptfoo:redteam:harmful:another-type');
  79. expect(anotherHarmfulGrader).toBeInstanceOf(HarmfulGrader);
  80. });
  81. it('should return undefined for invalid ID', () => {
  82. const invalidGrader = getGraderById('invalid-id');
  83. expect(invalidGrader).toBeUndefined();
  84. });
  85. it('should return undefined for empty ID', () => {
  86. const emptyGrader = getGraderById('');
  87. expect(emptyGrader).toBeUndefined();
  88. });
  89. });
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...