@theia/ai-core 1.61.0 → 1.62.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/ai-core-frontend-module.js +2 -2
- package/lib/browser/ai-core-frontend-module.js.map +1 -1
- package/lib/browser/frontend-language-model-service.d.ts +1 -1
- package/lib/browser/frontend-language-model-service.d.ts.map +1 -1
- package/lib/browser/frontend-language-model-service.js.map +1 -1
- package/lib/browser/frontend-prompt-customization-service.d.ts +142 -48
- package/lib/browser/frontend-prompt-customization-service.d.ts.map +1 -1
- package/lib/browser/frontend-prompt-customization-service.js +452 -153
- package/lib/browser/frontend-prompt-customization-service.js.map +1 -1
- package/lib/browser/prompttemplate-contribution.d.ts +1 -2
- package/lib/browser/prompttemplate-contribution.d.ts.map +1 -1
- package/lib/browser/prompttemplate-contribution.js +5 -9
- package/lib/browser/prompttemplate-contribution.js.map +1 -1
- package/lib/common/agent-service.d.ts.map +1 -1
- package/lib/common/agent-service.js +14 -2
- package/lib/common/agent-service.js.map +1 -1
- package/lib/common/agent.d.ts +8 -3
- package/lib/common/agent.d.ts.map +1 -1
- package/lib/common/agent.js.map +1 -1
- package/lib/common/index.d.ts +0 -1
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +0 -1
- package/lib/common/index.js.map +1 -1
- package/lib/common/language-model-interaction-model.d.ts +74 -0
- package/lib/common/language-model-interaction-model.d.ts.map +1 -0
- package/lib/common/language-model-interaction-model.js +3 -0
- package/lib/common/language-model-interaction-model.js.map +1 -0
- package/lib/common/language-model-service.d.ts +26 -3
- package/lib/common/language-model-service.d.ts.map +1 -1
- package/lib/common/language-model-service.js +83 -6
- package/lib/common/language-model-service.js.map +1 -1
- package/lib/common/language-model-util.d.ts +3 -2
- package/lib/common/language-model-util.d.ts.map +1 -1
- package/lib/common/language-model-util.js +8 -0
- package/lib/common/language-model-util.js.map +1 -1
- package/lib/common/language-model.d.ts +25 -2
- package/lib/common/language-model.d.ts.map +1 -1
- package/lib/common/language-model.js +3 -1
- package/lib/common/language-model.js.map +1 -1
- package/lib/common/prompt-service.d.ts +332 -126
- package/lib/common/prompt-service.d.ts.map +1 -1
- package/lib/common/prompt-service.js +363 -102
- package/lib/common/prompt-service.js.map +1 -1
- package/lib/common/prompt-service.spec.js +104 -114
- package/lib/common/prompt-service.spec.js.map +1 -1
- package/lib/common/prompt-variable-contribution.d.ts +1 -2
- package/lib/common/prompt-variable-contribution.d.ts.map +1 -1
- package/lib/common/prompt-variable-contribution.js +17 -26
- package/lib/common/prompt-variable-contribution.js.map +1 -1
- package/package.json +10 -10
- package/src/browser/ai-core-frontend-module.ts +4 -4
- package/src/browser/frontend-language-model-service.ts +1 -1
- package/src/browser/frontend-prompt-customization-service.ts +574 -183
- package/src/browser/prompttemplate-contribution.ts +6 -9
- package/src/common/agent-service.ts +14 -4
- package/src/common/agent.ts +9 -3
- package/src/common/index.ts +0 -1
- package/src/common/language-model-interaction-model.ts +98 -0
- package/src/common/language-model-service.ts +115 -6
- package/src/common/language-model-util.ts +10 -2
- package/src/common/language-model.ts +28 -2
- package/src/common/prompt-service.spec.ts +108 -114
- package/src/common/prompt-service.ts +694 -221
- package/src/common/prompt-variable-contribution.ts +22 -27
- package/lib/common/communication-recording-service.d.ts +0 -30
- package/lib/common/communication-recording-service.d.ts.map +0 -1
- package/lib/common/communication-recording-service.js +0 -20
- package/lib/common/communication-recording-service.js.map +0 -1
- package/src/common/communication-recording-service.ts +0 -55
|
@@ -42,236 +42,235 @@ describe('PromptService', () => {
|
|
|
42
42
|
container.bind<AIVariableService>(AIVariableService).toConstantValue(variableService);
|
|
43
43
|
|
|
44
44
|
promptService = container.get<PromptService>(PromptService);
|
|
45
|
-
promptService.
|
|
46
|
-
promptService.
|
|
47
|
-
promptService.
|
|
48
|
-
promptService.
|
|
45
|
+
promptService.addBuiltInPromptFragment({ id: '1', template: 'Hello, {{name}}!' });
|
|
46
|
+
promptService.addBuiltInPromptFragment({ id: '2', template: 'Goodbye, {{name}}!' });
|
|
47
|
+
promptService.addBuiltInPromptFragment({ id: '3', template: 'Ciao, {{invalid}}!' });
|
|
48
|
+
promptService.addBuiltInPromptFragment({ id: '8', template: 'Hello, {{{name}}}' });
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
-
it('should initialize
|
|
52
|
-
const allPrompts = promptService.
|
|
53
|
-
expect(allPrompts
|
|
54
|
-
expect(allPrompts
|
|
55
|
-
expect(allPrompts
|
|
56
|
-
expect(allPrompts
|
|
51
|
+
it('should successfully initialize and retrieve built-in prompt fragments', () => {
|
|
52
|
+
const allPrompts = promptService.getActivePromptFragments();
|
|
53
|
+
expect(allPrompts.find(prompt => prompt.id === '1')!.template).to.equal('Hello, {{name}}!');
|
|
54
|
+
expect(allPrompts.find(prompt => prompt.id === '2')!.template).to.equal('Goodbye, {{name}}!');
|
|
55
|
+
expect(allPrompts.find(prompt => prompt.id === '3')!.template).to.equal('Ciao, {{invalid}}!');
|
|
56
|
+
expect(allPrompts.find(prompt => prompt.id === '8')!.template).to.equal('Hello, {{{name}}}');
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
-
it('should retrieve raw prompt by id', () => {
|
|
60
|
-
const rawPrompt = promptService.
|
|
59
|
+
it('should retrieve raw prompt fragment by id', () => {
|
|
60
|
+
const rawPrompt = promptService.getRawPromptFragment('1');
|
|
61
61
|
expect(rawPrompt?.template).to.equal('Hello, {{name}}!');
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
-
it('should format prompt with provided arguments', async () => {
|
|
65
|
-
const formattedPrompt = await promptService.
|
|
64
|
+
it('should format prompt fragment with provided arguments', async () => {
|
|
65
|
+
const formattedPrompt = await promptService.getResolvedPromptFragment('1', { name: 'John' });
|
|
66
66
|
expect(formattedPrompt?.text).to.equal('Hello, John!');
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
-
it('should store a new prompt', () => {
|
|
70
|
-
promptService.
|
|
71
|
-
const newPrompt = promptService.
|
|
69
|
+
it('should store a new prompt fragment', () => {
|
|
70
|
+
promptService.addBuiltInPromptFragment({ id: '3', template: 'Welcome, {{name}}!' });
|
|
71
|
+
const newPrompt = promptService.getRawPromptFragment('3');
|
|
72
72
|
expect(newPrompt?.template).to.equal('Welcome, {{name}}!');
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
-
it('should replace placeholders with provided arguments', async () => {
|
|
76
|
-
const prompt = await promptService.
|
|
75
|
+
it('should replace variable placeholders with provided arguments', async () => {
|
|
76
|
+
const prompt = await promptService.getResolvedPromptFragment('1', { name: 'John' });
|
|
77
77
|
expect(prompt?.text).to.equal('Hello, John!');
|
|
78
78
|
});
|
|
79
79
|
|
|
80
|
-
it('should use variable service to resolve placeholders
|
|
81
|
-
const prompt = await promptService.
|
|
80
|
+
it('should use variable service to resolve placeholders when argument values are not provided', async () => {
|
|
81
|
+
const prompt = await promptService.getResolvedPromptFragment('1');
|
|
82
82
|
expect(prompt?.text).to.equal('Hello, Jane!');
|
|
83
83
|
});
|
|
84
84
|
|
|
85
|
-
it('should return the prompt even if there are no replacements', async () => {
|
|
86
|
-
const prompt = await promptService.
|
|
85
|
+
it('should return the prompt fragment even if there are no valid replacements', async () => {
|
|
86
|
+
const prompt = await promptService.getResolvedPromptFragment('3');
|
|
87
87
|
expect(prompt?.text).to.equal('Ciao, {{invalid}}!');
|
|
88
88
|
});
|
|
89
89
|
|
|
90
|
-
it('should return undefined if the prompt id is not found', async () => {
|
|
91
|
-
const prompt = await promptService.
|
|
90
|
+
it('should return undefined if the prompt fragment id is not found', async () => {
|
|
91
|
+
const prompt = await promptService.getResolvedPromptFragment('4');
|
|
92
92
|
expect(prompt).to.be.undefined;
|
|
93
93
|
});
|
|
94
94
|
|
|
95
95
|
it('should ignore whitespace in variables', async () => {
|
|
96
|
-
promptService.
|
|
97
|
-
promptService.
|
|
98
|
-
promptService.
|
|
99
|
-
promptService.
|
|
96
|
+
promptService.addBuiltInPromptFragment({ id: '4', template: 'Hello, {{name }}!' });
|
|
97
|
+
promptService.addBuiltInPromptFragment({ id: '5', template: 'Hello, {{ name}}!' });
|
|
98
|
+
promptService.addBuiltInPromptFragment({ id: '6', template: 'Hello, {{ name }}!' });
|
|
99
|
+
promptService.addBuiltInPromptFragment({ id: '7', template: 'Hello, {{ name }}!' });
|
|
100
100
|
for (let i = 4; i <= 7; i++) {
|
|
101
|
-
const prompt = await promptService.
|
|
101
|
+
const prompt = await promptService.getResolvedPromptFragment(`${i}`, { name: 'John' });
|
|
102
102
|
expect(prompt?.text).to.equal('Hello, John!');
|
|
103
103
|
}
|
|
104
104
|
});
|
|
105
105
|
|
|
106
|
-
it('should retrieve raw prompt by id (three bracket)', () => {
|
|
107
|
-
const rawPrompt = promptService.
|
|
106
|
+
it('should retrieve raw prompt fragment by id (three bracket)', () => {
|
|
107
|
+
const rawPrompt = promptService.getRawPromptFragment('8');
|
|
108
108
|
expect(rawPrompt?.template).to.equal('Hello, {{{name}}}');
|
|
109
109
|
});
|
|
110
110
|
|
|
111
111
|
it('should correctly replace variables (three brackets)', async () => {
|
|
112
|
-
const formattedPrompt = await promptService.
|
|
112
|
+
const formattedPrompt = await promptService.getResolvedPromptFragment('8');
|
|
113
113
|
expect(formattedPrompt?.text).to.equal('Hello, Jane');
|
|
114
114
|
});
|
|
115
115
|
|
|
116
116
|
it('should ignore whitespace in variables (three bracket)', async () => {
|
|
117
|
-
promptService.
|
|
118
|
-
promptService.
|
|
119
|
-
promptService.
|
|
120
|
-
promptService.
|
|
117
|
+
promptService.addBuiltInPromptFragment({ id: '9', template: 'Hello, {{{name }}}' });
|
|
118
|
+
promptService.addBuiltInPromptFragment({ id: '10', template: 'Hello, {{{ name}}}' });
|
|
119
|
+
promptService.addBuiltInPromptFragment({ id: '11', template: 'Hello, {{{ name }}}' });
|
|
120
|
+
promptService.addBuiltInPromptFragment({ id: '12', template: 'Hello, {{{ name }}}' });
|
|
121
121
|
for (let i = 9; i <= 12; i++) {
|
|
122
|
-
const prompt = await promptService.
|
|
122
|
+
const prompt = await promptService.getResolvedPromptFragment(`${i}`, { name: 'John' });
|
|
123
123
|
expect(prompt?.text).to.equal('Hello, John');
|
|
124
124
|
}
|
|
125
125
|
});
|
|
126
126
|
|
|
127
127
|
it('should ignore invalid prompts with unmatched brackets', async () => {
|
|
128
|
-
promptService.
|
|
129
|
-
promptService.
|
|
130
|
-
promptService.
|
|
131
|
-
const prompt1 = await promptService.
|
|
128
|
+
promptService.addBuiltInPromptFragment({ id: '9', template: 'Hello, {{name' });
|
|
129
|
+
promptService.addBuiltInPromptFragment({ id: '10', template: 'Hello, {{{name' });
|
|
130
|
+
promptService.addBuiltInPromptFragment({ id: '11', template: 'Hello, name}}}}' });
|
|
131
|
+
const prompt1 = await promptService.getResolvedPromptFragment('9', { name: 'John' });
|
|
132
132
|
expect(prompt1?.text).to.equal('Hello, {{name'); // Not matching due to missing closing brackets
|
|
133
|
-
const prompt2 = await promptService.
|
|
133
|
+
const prompt2 = await promptService.getResolvedPromptFragment('10', { name: 'John' });
|
|
134
134
|
expect(prompt2?.text).to.equal('Hello, {{{name'); // Matches pattern due to valid three-start-two-end brackets
|
|
135
|
-
const prompt3 = await promptService.
|
|
135
|
+
const prompt3 = await promptService.getResolvedPromptFragment('11', { name: 'John' });
|
|
136
136
|
expect(prompt3?.text).to.equal('Hello, name}}}}'); // Extra closing bracket, does not match cleanly
|
|
137
137
|
});
|
|
138
138
|
|
|
139
139
|
it('should handle a mixture of two and three brackets correctly', async () => {
|
|
140
|
-
promptService.
|
|
141
|
-
promptService.
|
|
142
|
-
promptService.
|
|
143
|
-
promptService.
|
|
144
|
-
promptService.
|
|
145
|
-
promptService.
|
|
146
|
-
|
|
147
|
-
const prompt12 = await promptService.
|
|
140
|
+
promptService.addBuiltInPromptFragment({ id: '12', template: 'Hi, {{name}}}' }); // (invalid)
|
|
141
|
+
promptService.addBuiltInPromptFragment({ id: '13', template: 'Hello, {{{name}}' }); // (invalid)
|
|
142
|
+
promptService.addBuiltInPromptFragment({ id: '14', template: 'Greetings, {{{name}}}}' }); // (invalid)
|
|
143
|
+
promptService.addBuiltInPromptFragment({ id: '15', template: 'Bye, {{{{name}}}' }); // (invalid)
|
|
144
|
+
promptService.addBuiltInPromptFragment({ id: '16', template: 'Ciao, {{{{name}}}}' }); // (invalid)
|
|
145
|
+
promptService.addBuiltInPromptFragment({ id: '17', template: 'Hi, {{name}}! {{{name}}}' }); // Mixed valid patterns
|
|
146
|
+
|
|
147
|
+
const prompt12 = await promptService.getResolvedPromptFragment('12', { name: 'John' });
|
|
148
148
|
expect(prompt12?.text).to.equal('Hi, {{name}}}');
|
|
149
149
|
|
|
150
|
-
const prompt13 = await promptService.
|
|
150
|
+
const prompt13 = await promptService.getResolvedPromptFragment('13', { name: 'John' });
|
|
151
151
|
expect(prompt13?.text).to.equal('Hello, {{{name}}');
|
|
152
152
|
|
|
153
|
-
const prompt14 = await promptService.
|
|
153
|
+
const prompt14 = await promptService.getResolvedPromptFragment('14', { name: 'John' });
|
|
154
154
|
expect(prompt14?.text).to.equal('Greetings, {{{name}}}}');
|
|
155
155
|
|
|
156
|
-
const prompt15 = await promptService.
|
|
156
|
+
const prompt15 = await promptService.getResolvedPromptFragment('15', { name: 'John' });
|
|
157
157
|
expect(prompt15?.text).to.equal('Bye, {{{{name}}}');
|
|
158
158
|
|
|
159
|
-
const prompt16 = await promptService.
|
|
159
|
+
const prompt16 = await promptService.getResolvedPromptFragment('16', { name: 'John' });
|
|
160
160
|
expect(prompt16?.text).to.equal('Ciao, {{{{name}}}}');
|
|
161
161
|
|
|
162
|
-
const prompt17 = await promptService.
|
|
162
|
+
const prompt17 = await promptService.getResolvedPromptFragment('17', { name: 'John' });
|
|
163
163
|
expect(prompt17?.text).to.equal('Hi, John! John');
|
|
164
164
|
});
|
|
165
165
|
|
|
166
166
|
it('should strip single-line comments at the start of the template', () => {
|
|
167
|
-
promptService.
|
|
168
|
-
const prompt = promptService.
|
|
167
|
+
promptService.addBuiltInPromptFragment({ id: 'comment-basic', template: '{{!-- Comment --}}Hello, {{name}}!' });
|
|
168
|
+
const prompt = promptService.getPromptFragment('comment-basic');
|
|
169
169
|
expect(prompt?.template).to.equal('Hello, {{name}}!');
|
|
170
170
|
});
|
|
171
171
|
|
|
172
172
|
it('should remove line break after first-line comment', () => {
|
|
173
|
-
promptService.
|
|
174
|
-
const prompt = promptService.
|
|
173
|
+
promptService.addBuiltInPromptFragment({ id: 'comment-line-break', template: '{{!-- Comment --}}\nHello, {{name}}!' });
|
|
174
|
+
const prompt = promptService.getPromptFragment('comment-line-break');
|
|
175
175
|
expect(prompt?.template).to.equal('Hello, {{name}}!');
|
|
176
176
|
});
|
|
177
177
|
|
|
178
178
|
it('should strip multiline comments at the start of the template', () => {
|
|
179
|
-
promptService.
|
|
180
|
-
const prompt = promptService.
|
|
179
|
+
promptService.addBuiltInPromptFragment({ id: 'comment-multiline', template: '{{!--\nMultiline comment\n--}}\nGoodbye, {{name}}!' });
|
|
180
|
+
const prompt = promptService.getPromptFragment('comment-multiline');
|
|
181
181
|
expect(prompt?.template).to.equal('Goodbye, {{name}}!');
|
|
182
182
|
});
|
|
183
183
|
|
|
184
184
|
it('should not strip comments not in the first line', () => {
|
|
185
|
-
promptService.
|
|
186
|
-
const prompt = promptService.
|
|
185
|
+
promptService.addBuiltInPromptFragment({ id: 'comment-second-line', template: 'Hello, {{name}}!\n{{!-- Comment --}}' });
|
|
186
|
+
const prompt = promptService.getPromptFragment('comment-second-line');
|
|
187
187
|
expect(prompt?.template).to.equal('Hello, {{name}}!\n{{!-- Comment --}}');
|
|
188
188
|
});
|
|
189
189
|
|
|
190
190
|
it('should treat unclosed comments as regular text', () => {
|
|
191
|
-
promptService.
|
|
192
|
-
const prompt = promptService.
|
|
191
|
+
promptService.addBuiltInPromptFragment({ id: 'comment-unclosed', template: '{{!-- Unclosed comment' });
|
|
192
|
+
const prompt = promptService.getPromptFragment('comment-unclosed');
|
|
193
193
|
expect(prompt?.template).to.equal('{{!-- Unclosed comment');
|
|
194
194
|
});
|
|
195
195
|
|
|
196
196
|
it('should treat standalone closing delimiters as regular text', () => {
|
|
197
|
-
promptService.
|
|
198
|
-
const prompt = promptService.
|
|
197
|
+
promptService.addBuiltInPromptFragment({ id: 'comment-standalone', template: '--}} Hello, {{name}}!' });
|
|
198
|
+
const prompt = promptService.getPromptFragment('comment-standalone');
|
|
199
199
|
expect(prompt?.template).to.equal('--}} Hello, {{name}}!');
|
|
200
200
|
});
|
|
201
201
|
|
|
202
202
|
it('should handle nested comments and stop at the first closing tag', () => {
|
|
203
|
-
promptService.
|
|
204
|
-
const prompt = promptService.
|
|
203
|
+
promptService.addBuiltInPromptFragment({ id: 'nested-comment', template: '{{!-- {{!-- Nested comment --}} --}}text' });
|
|
204
|
+
const prompt = promptService.getPromptFragment('nested-comment');
|
|
205
205
|
expect(prompt?.template).to.equal('--}}text');
|
|
206
206
|
});
|
|
207
207
|
|
|
208
208
|
it('should handle templates with only comments', () => {
|
|
209
|
-
promptService.
|
|
210
|
-
const prompt = promptService.
|
|
209
|
+
promptService.addBuiltInPromptFragment({ id: 'comment-only', template: '{{!-- Only comments --}}' });
|
|
210
|
+
const prompt = promptService.getPromptFragment('comment-only');
|
|
211
211
|
expect(prompt?.template).to.equal('');
|
|
212
212
|
});
|
|
213
213
|
|
|
214
214
|
it('should handle mixed delimiters on the same line', () => {
|
|
215
|
-
promptService.
|
|
216
|
-
const prompt = promptService.
|
|
215
|
+
promptService.addBuiltInPromptFragment({ id: 'comment-mixed', template: '{{!-- Unclosed comment --}}' });
|
|
216
|
+
const prompt = promptService.getPromptFragment('comment-mixed');
|
|
217
217
|
expect(prompt?.template).to.equal('');
|
|
218
218
|
});
|
|
219
219
|
|
|
220
220
|
it('should resolve variables after stripping single-line comments', async () => {
|
|
221
|
-
promptService.
|
|
222
|
-
const prompt = await promptService.
|
|
221
|
+
promptService.addBuiltInPromptFragment({ id: 'comment-resolve', template: '{{!-- Comment --}}Hello, {{name}}!' });
|
|
222
|
+
const prompt = await promptService.getResolvedPromptFragment('comment-resolve', { name: 'John' });
|
|
223
223
|
expect(prompt?.text).to.equal('Hello, John!');
|
|
224
224
|
});
|
|
225
225
|
|
|
226
226
|
it('should resolve variables in multiline templates with comments', async () => {
|
|
227
|
-
promptService.
|
|
228
|
-
const prompt = await promptService.
|
|
227
|
+
promptService.addBuiltInPromptFragment({ id: 'comment-multiline-vars', template: '{{!--\nMultiline comment\n--}}\nHello, {{name}}!' });
|
|
228
|
+
const prompt = await promptService.getResolvedPromptFragment('comment-multiline-vars', { name: 'John' });
|
|
229
229
|
expect(prompt?.text).to.equal('Hello, John!');
|
|
230
230
|
});
|
|
231
231
|
|
|
232
232
|
it('should resolve variables with standalone closing delimiters', async () => {
|
|
233
|
-
promptService.
|
|
234
|
-
const prompt = await promptService.
|
|
233
|
+
promptService.addBuiltInPromptFragment({ id: 'comment-standalone-vars', template: '--}} Hello, {{name}}!' });
|
|
234
|
+
const prompt = await promptService.getResolvedPromptFragment('comment-standalone-vars', { name: 'John' });
|
|
235
235
|
expect(prompt?.text).to.equal('--}} Hello, John!');
|
|
236
236
|
});
|
|
237
237
|
|
|
238
238
|
it('should treat unclosed comments as text and resolve variables', async () => {
|
|
239
|
-
promptService.
|
|
240
|
-
const prompt = await promptService.
|
|
239
|
+
promptService.addBuiltInPromptFragment({ id: 'comment-unclosed-vars', template: '{{!-- Unclosed comment\nHello, {{name}}!' });
|
|
240
|
+
const prompt = await promptService.getResolvedPromptFragment('comment-unclosed-vars', { name: 'John' });
|
|
241
241
|
expect(prompt?.text).to.equal('{{!-- Unclosed comment\nHello, John!');
|
|
242
242
|
});
|
|
243
243
|
|
|
244
244
|
it('should handle templates with mixed comments and variables', async () => {
|
|
245
|
-
promptService.
|
|
246
|
-
|
|
245
|
+
promptService.addBuiltInPromptFragment(
|
|
246
|
+
{ id: 'comment-mixed-vars', template: '{{!-- Comment --}}Hi, {{name}}! {{!-- Another comment --}}' });
|
|
247
|
+
const prompt = await promptService.getResolvedPromptFragment('comment-mixed-vars', { name: 'John' });
|
|
247
248
|
expect(prompt?.text).to.equal('Hi, John! {{!-- Another comment --}}');
|
|
248
249
|
});
|
|
249
250
|
|
|
250
251
|
it('should return all variant IDs of a given prompt', () => {
|
|
251
|
-
promptService.
|
|
252
|
-
|
|
253
|
-
promptService.storePromptTemplate({
|
|
252
|
+
promptService.addBuiltInPromptFragment({
|
|
254
253
|
id: 'variant1',
|
|
255
254
|
template: 'Variant 1',
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
promptService.
|
|
255
|
+
}, 'systemPrompt'
|
|
256
|
+
);
|
|
257
|
+
promptService.addBuiltInPromptFragment({
|
|
259
258
|
id: 'variant2',
|
|
260
259
|
template: 'Variant 2',
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
promptService.
|
|
260
|
+
}, 'systemPrompt'
|
|
261
|
+
);
|
|
262
|
+
promptService.addBuiltInPromptFragment({
|
|
264
263
|
id: 'variant3',
|
|
265
264
|
template: 'Variant 3',
|
|
266
|
-
|
|
267
|
-
|
|
265
|
+
}, 'systemPrompt'
|
|
266
|
+
);
|
|
268
267
|
|
|
269
|
-
const variantIds = promptService.getVariantIds('
|
|
268
|
+
const variantIds = promptService.getVariantIds('systemPrompt');
|
|
270
269
|
expect(variantIds).to.deep.equal(['variant1', 'variant2', 'variant3']);
|
|
271
270
|
});
|
|
272
271
|
|
|
273
272
|
it('should return an empty array if no variants exist for a given prompt', () => {
|
|
274
|
-
promptService.
|
|
273
|
+
promptService.addBuiltInPromptFragment({ id: 'main', template: 'Main template' });
|
|
275
274
|
|
|
276
275
|
const variantIds = promptService.getVariantIds('main');
|
|
277
276
|
expect(variantIds).to.deep.equal([]);
|
|
@@ -283,25 +282,20 @@ describe('PromptService', () => {
|
|
|
283
282
|
});
|
|
284
283
|
|
|
285
284
|
it('should not influence prompts without variants when other prompts have variants', () => {
|
|
286
|
-
promptService.
|
|
287
|
-
promptService.
|
|
285
|
+
promptService.addBuiltInPromptFragment({ id: 'variant1', template: 'Variant 1' }, 'systemPromptWithVariants', true);
|
|
286
|
+
promptService.addBuiltInPromptFragment({ id: 'promptFragmentWithoutVariants', template: 'template without variants' });
|
|
288
287
|
|
|
289
|
-
promptService.
|
|
290
|
-
id: 'variant1',
|
|
291
|
-
template: 'Variant 1',
|
|
292
|
-
variantOf: 'mainWithVariants'
|
|
293
|
-
});
|
|
294
|
-
promptService.storePromptTemplate({
|
|
288
|
+
promptService.addBuiltInPromptFragment({
|
|
295
289
|
id: 'variant2',
|
|
296
290
|
template: 'Variant 2',
|
|
297
|
-
|
|
298
|
-
|
|
291
|
+
}, 'systemPromptWithVariants'
|
|
292
|
+
);
|
|
299
293
|
|
|
300
|
-
const
|
|
301
|
-
const
|
|
294
|
+
const systemPromptWithVariants = promptService.getVariantIds('systemPromptWithVariants');
|
|
295
|
+
const promptFragmentWithoutVariants = promptService.getVariantIds('promptFragmentWithoutVariants');
|
|
302
296
|
|
|
303
|
-
expect(
|
|
304
|
-
expect(
|
|
297
|
+
expect(systemPromptWithVariants).to.deep.equal(['variant1', 'variant2']);
|
|
298
|
+
expect(promptFragmentWithoutVariants).to.deep.equal([]);
|
|
305
299
|
});
|
|
306
300
|
|
|
307
301
|
it('should resolve function references within resolved variable replacements', async () => {
|
|
@@ -348,10 +342,10 @@ describe('PromptService', () => {
|
|
|
348
342
|
container.bind<AIVariableService>(AIVariableService).toConstantValue(variableService);
|
|
349
343
|
|
|
350
344
|
const testPromptService = container.get<PromptService>(PromptService);
|
|
351
|
-
testPromptService.
|
|
345
|
+
testPromptService.addBuiltInPromptFragment({ id: 'testPrompt', template: 'Template with fragment: {{fragment}}' });
|
|
352
346
|
|
|
353
347
|
// Get the resolved prompt
|
|
354
|
-
const resolvedPrompt = await testPromptService.
|
|
348
|
+
const resolvedPrompt = await testPromptService.getResolvedPromptFragment('testPrompt');
|
|
355
349
|
|
|
356
350
|
// Verify that the function was resolved
|
|
357
351
|
expect(resolvedPrompt).to.not.be.undefined;
|