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

competitors.test.ts 2.8 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
  1. import { CompetitorsGrader } from '../../../src/redteam/plugins/competitors';
  2. import type { AssertionValue } from '../../../src/types';
  3. describe('CompetitorsGrader', () => {
  4. let grader: CompetitorsGrader;
  5. beforeEach(() => {
  6. grader = new CompetitorsGrader();
  7. });
  8. it('should have the correct plugin ID', () => {
  9. expect(grader.id).toBe('promptfoo:redteam:competitors');
  10. });
  11. describe('getSuggestions', () => {
  12. it('should return suggestions with competitor mentions allowed', () => {
  13. const input = {
  14. rawPrompt: 'Compare our product with competitor X',
  15. renderedValue: undefined as AssertionValue | undefined,
  16. test: {
  17. metadata: {
  18. pluginConfig: {
  19. mentions: true,
  20. },
  21. },
  22. },
  23. };
  24. const suggestions = grader.getSuggestions(input);
  25. expect(suggestions).toHaveLength(1);
  26. expect(suggestions[0].action).toBe('replace-prompt');
  27. expect(suggestions[0].type).toBe('constitutional-competition');
  28. expect(suggestions[0].value).toContain('Focus primarily on our own strengths');
  29. expect(suggestions[0].value).toContain('Maintain neutrality and factual accuracy');
  30. expect(suggestions[0].value).toContain('Avoid explicit endorsements');
  31. expect(suggestions[0].value).toContain('Use respectful, professional language');
  32. });
  33. it('should return suggestions with competitor mentions disallowed', () => {
  34. const input = {
  35. rawPrompt: 'What do you think about competitor X?',
  36. renderedValue: undefined as AssertionValue | undefined,
  37. test: {
  38. metadata: {
  39. pluginConfig: {
  40. mentions: false,
  41. },
  42. },
  43. },
  44. };
  45. const suggestions = grader.getSuggestions(input);
  46. expect(suggestions).toHaveLength(1);
  47. expect(suggestions[0].action).toBe('replace-prompt');
  48. expect(suggestions[0].type).toBe('constitutional-competition');
  49. expect(suggestions[0].value).toContain(
  50. 'Do not mention competitor names or products directly',
  51. );
  52. expect(suggestions[0].value).toContain(
  53. '"other options" or "alternatives" without endorsement',
  54. );
  55. });
  56. it('should handle undefined pluginConfig', () => {
  57. const input = {
  58. rawPrompt: 'Tell me about the competition',
  59. renderedValue: undefined as AssertionValue | undefined,
  60. test: {},
  61. };
  62. const suggestions = grader.getSuggestions(input);
  63. expect(suggestions).toHaveLength(1);
  64. expect(suggestions[0].action).toBe('replace-prompt');
  65. expect(suggestions[0].type).toBe('constitutional-competition');
  66. expect(suggestions[0].value).toContain(
  67. 'Do not mention competitor names or products directly',
  68. );
  69. });
  70. });
  71. });
Tip!

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

Comments

Loading...