-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path04-component-ordering.ts
More file actions
117 lines (106 loc) · 2.84 KB
/
04-component-ordering.ts
File metadata and controls
117 lines (106 loc) · 2.84 KB
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
113
114
115
116
117
/**
* Example 4: Component Ordering & Steps Array
*
* This example shows how to control the order of components
* using the order option, and demonstrates the steps array feature.
*/
import { PromptBuilder } from '../dist';
// Without explicit ordering (uses insertion order)
const prompt1 = new PromptBuilder()
.output('Output format')
.role('You are a helper')
.goal('Help users')
.input('User input')
.build();
console.log('=== Without Explicit Ordering ===');
console.log(prompt1);
console.log('\n');
// With explicit ordering
const prompt2 = new PromptBuilder()
.output('Output format', { order: 3 })
.role('You are a helper', { order: 1 })
.goal('Help users', { order: 2 })
.input('User input', { order: 4 })
.build();
console.log('=== With Explicit Ordering ===');
console.log(prompt2);
console.log('\n');
// Steps with array - auto-prefixed
const prompt3 = new PromptBuilder()
.role('You are a task assistant')
.goal('Help users complete tasks')
.steps([
'Understand the task requirements',
'Break down into smaller steps',
'Execute each step',
'Verify completion'
])
.build();
console.log('=== Steps with Array (Auto-prefixed) ===');
console.log(prompt3);
console.log('\n');
// Steps with function returning array
const prompt4 = new PromptBuilder()
.role('You are a code reviewer')
.steps((params) => {
if (params.complexity === 'high') {
return [
'Review architecture',
'Check performance',
'Verify security',
'Test edge cases'
];
}
return [
'Quick code scan',
'Check best practices',
'Provide feedback'
];
})
.tasks([
'Analyze code structure',
'Check for bugs',
'Review best practices'
])
.constraints([
'Focus on code quality',
'Provide constructive feedback'
])
.build({
complexity: 'high'
});
console.log('=== Steps with Function Returning Array ===');
console.log(prompt4);
console.log('\n');
// Demonstrating all array-based components
const prompt5 = new PromptBuilder()
.role('You are a writing assistant')
.tasks([
'Review the draft',
'Suggest improvements',
'Check grammar and style'
])
.steps([
'Read through the content',
'Identify areas for improvement',
'Provide specific suggestions',
'Review final version'
])
.fewShots([
'Input: "The cat sat on the mat."\nOutput: "The cat sat gracefully on the woven mat."',
'Input: "I went to the store."\nOutput: "I walked to the local grocery store."'
])
.guardrails([
'Maintain the author\'s voice',
'Preserve the original meaning',
'Be respectful and constructive'
])
.constraints([
'Keep suggestions concise',
'Focus on clarity and flow',
'Maintain original intent'
])
.build();
console.log('=== All Array-Based Components ===');
console.log(prompt5);
console.log('\n');