genaicode 0.0.35 → 0.0.37

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.
Files changed (33) hide show
  1. package/README.md +3 -0
  2. package/package.json +3 -2
  3. package/src/ai-service/anthropic.js +45 -14
  4. package/src/ai-service/chat-gpt.js +34 -7
  5. package/src/ai-service/common.js +10 -1
  6. package/src/cli/cli-options.js +12 -0
  7. package/src/cli/cli-params.js +15 -0
  8. package/src/cli/validate-cli-params.js +20 -0
  9. package/src/files/read-files.js +8 -3
  10. package/src/files/read-files.test.js +1 -0
  11. package/src/main/codegen.test.js +1 -0
  12. package/src/prompt/function-calling.js +33 -440
  13. package/src/prompt/function-defs/ask-question.js +33 -0
  14. package/src/prompt/function-defs/codegen-summary.js +87 -0
  15. package/src/prompt/function-defs/create-directory.js +21 -0
  16. package/src/prompt/function-defs/create-file.js +26 -0
  17. package/src/prompt/function-defs/delete-file.js +21 -0
  18. package/src/prompt/function-defs/download-file.js +25 -0
  19. package/src/prompt/function-defs/explanation.js +17 -0
  20. package/src/prompt/function-defs/generate-image.js +51 -0
  21. package/src/prompt/function-defs/get-image-assets.js +21 -0
  22. package/src/prompt/function-defs/get-source-code.js +21 -0
  23. package/src/prompt/function-defs/imgly-remove-background.js +25 -0
  24. package/src/prompt/function-defs/move-file.js +25 -0
  25. package/src/prompt/function-defs/patch-file.js +39 -0
  26. package/src/prompt/function-defs/resize-image.js +36 -0
  27. package/src/prompt/function-defs/split-image.js +45 -0
  28. package/src/prompt/function-defs/update-file.js +26 -0
  29. package/src/prompt/prompt-service-ask-question.test.js +163 -0
  30. package/src/prompt/prompt-service.js +56 -8
  31. package/src/prompt/prompt-service.test.js +1 -0
  32. package/src/prompt/systemprompt.js +8 -1
  33. package/src/prompt/systemprompt.test.js +1 -0
@@ -1,448 +1,41 @@
1
- import { requireExplanations, temperature, cheap, vision } from '../cli/cli-params.js';
1
+ import { requireExplanations } from '../cli/cli-params.js';
2
+ import { getSourceCode } from './function-defs/get-source-code.js';
3
+ import { getImageAssets } from './function-defs/get-image-assets.js';
4
+ import { codegenSummary } from './function-defs/codegen-summary.js';
5
+ import { updateFile } from './function-defs/update-file.js';
6
+ import { patchFile } from './function-defs/patch-file.js';
7
+ import { createFile } from './function-defs/create-file.js';
8
+ import { deleteFile } from './function-defs/delete-file.js';
9
+ import { explanation } from './function-defs/explanation.js';
10
+ import { createDirectory } from './function-defs/create-directory.js';
11
+ import { moveFile } from './function-defs/move-file.js';
12
+ import { generateImage } from './function-defs/generate-image.js';
13
+ import { downloadFile } from './function-defs/download-file.js';
14
+ import { imglyRemoveBackground } from './function-defs/imgly-remove-background.js';
15
+ import { resizeImage } from './function-defs/resize-image.js';
16
+ import { splitImage } from './function-defs/split-image.js';
17
+ import { askQuestion } from './function-defs/ask-question.js';
2
18
 
3
19
  /**
4
20
  * Function definitions for function calling feature
5
21
  */
6
22
  export const functionDefs = [
7
- {
8
- name: 'getSourceCode',
9
- description:
10
- 'This function returns source code of the application in Map format, where absolute file path is the key, and the value is an object, where one of the properties may be the content of the file. Some keys may not provide content. This function can be called only once during the conversation, and only if suggested by the user.',
11
- parameters: {
12
- type: 'object',
13
- properties: {
14
- filePaths: {
15
- type: 'array',
16
- description: 'An array of absolute paths of files that should be used to provided context.',
17
- items: {
18
- type: 'string',
19
- },
20
- },
21
- },
22
- required: [],
23
- },
24
- },
25
- {
26
- name: 'getImageAssets',
27
- description:
28
- 'This function returns a map of application image assets. This map contains absolute file path, and basic metadata information. It does not contain contents. Contents must be requested using dedicated tool.',
29
- parameters: {
30
- type: 'object',
31
- properties: {
32
- filePaths: {
33
- type: 'array',
34
- description: 'An array of absolute paths of files that should be used to provided context.',
35
- items: {
36
- type: 'string',
37
- },
38
- },
39
- },
40
- required: [],
41
- },
42
- },
43
- {
44
- name: 'codegenSummary',
45
- description:
46
- 'This function is called with a summary of proposed updates.' +
47
- 'Summary is a data structure(object) which contains:\n' +
48
- '- `fileUpdates`: list of proposed file updates that will be subject to subsequent code generation request\n' +
49
- '- `contextPaths`: list of file paths that make sense to use as a context for code generation requests.' +
50
- '- `explanation`: general explanation of planned code generation updates\n' +
51
- 'It is crticially important to adhere to the schema of parameters',
52
- parameters: {
53
- type: 'object',
54
- properties: {
55
- contextPaths: {
56
- type: 'array',
57
- description:
58
- 'An array of absolute paths of files that should be used to provide context for the following updates. Context files could be for example the dependencies, or files that depend on one of the files that we want to update in the next step.',
59
- items: {
60
- type: 'string',
61
- },
62
- },
63
- fileUpdates: {
64
- type: 'array',
65
- description: 'An array of proposed file updates, each update is an object with several properties.',
66
- items: {
67
- type: 'object',
68
- description:
69
- 'Proposed update of a file. The update is an object which contains properties like file path, update tool name, and few other important properties.',
70
- properties: {
71
- path: { type: 'string', description: 'An absolute path of the project file that will be updated' },
72
- updateToolName: {
73
- type: 'string',
74
- enum: [
75
- 'createFile',
76
- 'updateFile',
77
- 'patchFile',
78
- 'deleteFile',
79
- 'createDirectory',
80
- 'moveFile',
81
- 'generateImage',
82
- 'downloadFile',
83
- 'splitImage',
84
- 'resizeImage',
85
- 'imglyRemoveBackground',
86
- ],
87
- description: 'A name of the tool that will be used to perform the update.',
88
- },
89
- temperature: {
90
- type: 'number',
91
- description:
92
- 'Temperature parameter that will be used for LLM request. The value is adjusted to the characteristic of the update. If there is a need for a more creative solution, the value should be lower, but stil within [0.0, 2.0] range. The default value is: ' +
93
- temperature,
94
- },
95
- cheap: {
96
- type: 'boolean',
97
- description:
98
- 'true value means that the prompt will be executed with cheaper model, which work faster, but provides lower quality results, so please use it only in situation when lower quality results are acceptable for the prompt. The default value is: ' +
99
- !!cheap,
100
- },
101
- prompt: {
102
- type: 'string',
103
- description:
104
- 'Prompt that will be passed to the model request together with the tool request. It summarizes the planned changes for this particular file, so it should be detailed enough for the model to generate necessary changes.',
105
- },
106
- contextImageAssets: {
107
- type: 'array',
108
- description:
109
- 'A list of of absolute image asset paths that should be included to the context of LLM request.' +
110
- 'This parameter must be used if there is a need to analyze an image.',
111
- items: { type: 'string' },
112
- },
113
- },
114
- required: ['path', 'updateToolName', ...(vision ? ['contextImageAssets'] : [])],
115
- },
116
- },
117
- explanation: {
118
- type: 'string',
119
- description: 'Explanation of planned changes or explanation of reasoning for no code changes',
120
- },
121
- },
122
- required: ['fileUpdates', 'contextPaths'],
123
- },
124
- },
125
- {
126
- name: 'updateFile',
127
- description:
128
- 'Update a file with new content. The file must already exists in the application source code. The function should be called only if there is a need to actually change something.',
129
- parameters: {
130
- type: 'object',
131
- properties: {
132
- filePath: {
133
- type: 'string',
134
- description: 'The file path to update.',
135
- },
136
- newContent: {
137
- type: 'string',
138
- description: 'The content to update the file with. Must not be empty.',
139
- },
140
- explanation: {
141
- type: 'string',
142
- description: 'The explanation of the reasoning behind the suggested code changes for this file',
143
- },
144
- },
145
- required: ['filePath', 'newContent'],
146
- },
147
- },
148
- {
149
- name: 'patchFile',
150
- description:
151
- 'Partially update a file content. The file must already exists in the application source code. The function should be called only if there is a need to actually change something.',
152
- parameters: {
153
- type: 'object',
154
- properties: {
155
- filePath: {
156
- type: 'string',
157
- description: 'The file path to patch.',
158
- },
159
- patch: {
160
- type: 'string',
161
- description: `Modification to the file expressed in patch format. Example patch:
162
-
163
- \`\`\`
164
- Index: filename.js
165
- ===================================================================
166
- --- filename.js
167
- +++ filename.js
168
- @@ -1,2 +1,3 @@
169
- line1
170
- +line3
171
- line2
172
- \
173
- \`\`\`
174
- `,
175
- },
176
- explanation: {
177
- type: 'string',
178
- description: 'The explanation of the reasoning behind the suggested code changes for this file',
179
- },
180
- },
181
- required: ['filePath', 'patch'],
182
- },
183
- },
184
- {
185
- name: 'createFile',
186
- description:
187
- 'Create a new file with specified content. The file will be created inside of project folder structure. This tool should not be used of creation if image files.',
188
- parameters: {
189
- type: 'object',
190
- properties: {
191
- filePath: {
192
- type: 'string',
193
- description: 'Path of the file that will be created, it must not be empty.',
194
- },
195
- newContent: {
196
- type: 'string',
197
- description: 'Content of the file that will be created, it must no be empty.',
198
- },
199
- explanation: {
200
- type: 'string',
201
- description: 'The explanation of the reasoning behind creating this file',
202
- },
203
- },
204
- required: ['filePath', 'newContent'],
205
- },
206
- },
207
- {
208
- name: 'deleteFile',
209
- description: 'Delete a specified file from the application source code.',
210
- parameters: {
211
- type: 'object',
212
- properties: {
213
- filePath: {
214
- type: 'string',
215
- description: 'The file path to delete.',
216
- },
217
- explanation: {
218
- type: 'string',
219
- description: 'The explanation of the reasoning behind deleting this file',
220
- },
221
- },
222
- required: ['filePath'],
223
- },
224
- },
225
- {
226
- name: 'explanation',
227
- description: 'Explain the reasoning behind the suggested code changes or reasoning for lack of code changes',
228
- parameters: {
229
- type: 'object',
230
- properties: {
231
- text: {
232
- type: 'string',
233
- description: 'The explanation text',
234
- },
235
- },
236
- required: ['text'],
237
- },
238
- },
239
- {
240
- name: 'createDirectory',
241
- description: 'Create a new directory',
242
- parameters: {
243
- type: 'object',
244
- properties: {
245
- filePath: {
246
- type: 'string',
247
- description: 'The directory path to create.',
248
- },
249
- explanation: {
250
- type: 'string',
251
- description: 'The explanation of the reasoning behind creating this directory',
252
- },
253
- },
254
- required: ['filePath'],
255
- },
256
- },
257
- {
258
- name: 'moveFile',
259
- description: 'Move a file from one location to another',
260
- parameters: {
261
- type: 'object',
262
- properties: {
263
- source: {
264
- type: 'string',
265
- description: 'The current file path.',
266
- },
267
- destination: {
268
- type: 'string',
269
- description: 'The new file path.',
270
- },
271
- explanation: {
272
- type: 'string',
273
- description: 'The explanation of the reasoning behind moving this file',
274
- },
275
- },
276
- required: ['source', 'destination'],
277
- },
278
- },
279
- {
280
- name: 'generateImage',
281
- description: 'Generate an image using AI service and save it as a file.',
282
- parameters: {
283
- type: 'object',
284
- properties: {
285
- prompt: {
286
- type: 'string',
287
- description:
288
- 'The prompt that will be used to generate the image. This prompt must be detailed, it will be used by image generation model.',
289
- },
290
- filePath: {
291
- type: 'string',
292
- description: 'The file path to save the generated image.',
293
- },
294
- contextImagePath: {
295
- type: 'string',
296
- description:
297
- 'Path to a image file that will be used as a context for image generation. It is useful if there is a need to edit an image with genAI.',
298
- },
299
- size: {
300
- type: 'object',
301
- properties: {
302
- width: {
303
- type: 'number',
304
- description: 'width of the image',
305
- },
306
- height: {
307
- type: 'number',
308
- description: 'height of the image',
309
- },
310
- },
311
- required: ['width', 'height'],
312
- description: 'The size of the image to generate.',
313
- },
314
- cheap: {
315
- type: 'boolean',
316
- description:
317
- 'true value means that the prompt will be executed with cheaper model, which work faster, but provides lower quality results, so please use it only in situation when lower quality results are acceptable for the prompt.',
318
- },
319
- explanation: {
320
- type: 'string',
321
- description: 'The explanation of the reasoning behind generating this image',
322
- },
323
- },
324
- required: ['prompt', 'filePath', 'size', 'cheap'],
325
- },
326
- },
327
- {
328
- name: 'downloadFile',
329
- description: 'Download file from url, and save to file',
330
- parameters: {
331
- type: 'object',
332
- properties: {
333
- filePath: {
334
- type: 'string',
335
- description: 'The file path to save the downloaded file.',
336
- },
337
- downloadUrl: {
338
- type: 'string',
339
- description: 'The url of the file that will be used for downloading.',
340
- },
341
- explanation: {
342
- type: 'string',
343
- description: 'The reasoning behind downloading this image.',
344
- },
345
- },
346
- required: ['filePath', 'downloadUrl'],
347
- },
348
- },
349
- {
350
- name: 'imglyRemoveBackground',
351
- description: 'Removes background from an image using @imgly/background-removal-node',
352
- parameters: {
353
- type: 'object',
354
- properties: {
355
- inputFilePath: {
356
- type: 'string',
357
- description: 'The file path of the input image.',
358
- },
359
- outputFilePath: {
360
- type: 'string',
361
- description: 'The file path to save the output image with removed background.',
362
- },
363
- explanation: {
364
- type: 'string',
365
- description: 'The explanation of the reasoning behind removing the background from this image',
366
- },
367
- },
368
- required: ['inputFilePath', 'outputFilePath'],
369
- },
370
- },
371
- {
372
- name: 'resizeImage',
373
- description: 'Resize image to the desired size',
374
- parameters: {
375
- type: 'object',
376
- properties: {
377
- filePath: {
378
- type: 'string',
379
- description: 'The file path of the image.',
380
- },
381
- size: {
382
- type: 'object',
383
- properties: {
384
- width: {
385
- type: 'number',
386
- description: 'width of the image',
387
- },
388
- height: {
389
- type: 'number',
390
- description: 'height of the image',
391
- },
392
- },
393
- required: ['width', 'height'],
394
- description: 'The size of the image to generate.',
395
- },
396
- explanation: {
397
- type: 'string',
398
- description: 'The explanation of the reasoning behind removing the background from this image',
399
- },
400
- },
401
- required: ['filePath', 'size'],
402
- },
403
- },
404
- {
405
- name: 'splitImage',
406
- description: 'Split an image into multiple parts and save them as separate files.',
407
- parameters: {
408
- type: 'object',
409
- properties: {
410
- inputFilePath: {
411
- type: 'string',
412
- description: 'The file path of the input image to be split.',
413
- },
414
- parts: {
415
- type: 'array',
416
- items: {
417
- type: 'object',
418
- properties: {
419
- rect: {
420
- type: 'object',
421
- properties: {
422
- x: { type: 'number', description: 'The x-coordinate of the top-left corner of the rectangle.' },
423
- y: { type: 'number', description: 'The y-coordinate of the top-left corner of the rectangle.' },
424
- width: { type: 'number', description: 'The width of the rectangle.' },
425
- height: { type: 'number', description: 'The height of the rectangle.' },
426
- },
427
- required: ['x', 'y', 'width', 'height'],
428
- },
429
- outputFilePath: {
430
- type: 'string',
431
- description: 'The file path to save the extracted part of the image.',
432
- },
433
- },
434
- required: ['rect', 'outputFilePath'],
435
- },
436
- description: 'An array of parts to extract from the image, each with a rectangle and output file path.',
437
- },
438
- explanation: {
439
- type: 'string',
440
- description: 'The explanation of the reasoning behind splitting this image',
441
- },
442
- },
443
- required: ['inputFilePath', 'parts'],
444
- },
445
- },
23
+ getSourceCode,
24
+ getImageAssets,
25
+ codegenSummary,
26
+ updateFile,
27
+ patchFile,
28
+ createFile,
29
+ deleteFile,
30
+ explanation,
31
+ createDirectory,
32
+ moveFile,
33
+ generateImage,
34
+ downloadFile,
35
+ imglyRemoveBackground,
36
+ resizeImage,
37
+ splitImage,
38
+ askQuestion,
446
39
  ].map((fd) => {
447
40
  if (requireExplanations && fd.parameters.properties.explanation && !fd.parameters.required.includes('explanation')) {
448
41
  fd.parameters.required.push('explanation');
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Function definition for askQuestion
3
+ */
4
+ export const askQuestion = {
5
+ name: 'askQuestion',
6
+ description:
7
+ 'If there is a need ask a question to the user to gather more information or clarification. Alternatively this function can be called also if there is no need to prompt the user with any question.',
8
+ parameters: {
9
+ type: 'object',
10
+ properties: {
11
+ content: {
12
+ type: 'string',
13
+ description:
14
+ 'The message you want to display to the user, it can be either a question or a confirmation/ackoweledgment in case there is no intention to prompt the user.',
15
+ },
16
+ shouldPrompt: {
17
+ type: 'boolean',
18
+ description: 'Set to true if the intention is to get response from the user.',
19
+ },
20
+ promptNecessity: {
21
+ type: 'number',
22
+ minimum: 0,
23
+ maximum: 100,
24
+ description: 'How strong is the need to prompt the user? Higher value indicates a stronger need.',
25
+ },
26
+ stopCodegen: {
27
+ type: 'boolean',
28
+ description: 'If set to true, it will break the code generation process without error.',
29
+ },
30
+ },
31
+ required: ['content', 'shouldPrompt', 'promptNecessity', 'stopCodegen'],
32
+ },
33
+ };
@@ -0,0 +1,87 @@
1
+ import { temperature, cheap, vision } from '../../cli/cli-params.js';
2
+
3
+ /**
4
+ * Function definition for codegenSummary
5
+ */
6
+ export const codegenSummary = {
7
+ name: 'codegenSummary',
8
+ description:
9
+ 'This function is called with a summary of proposed updates.' +
10
+ 'Summary is a data structure(object) which contains:\n' +
11
+ '- `fileUpdates`: list of proposed file updates that will be subject to subsequent code generation request\n' +
12
+ '- `contextPaths`: list of file paths that make sense to use as a context for code generation requests.' +
13
+ '- `explanation`: general explanation of planned code generation updates\n' +
14
+ 'It is crticially important to adhere to the schema of parameters',
15
+ parameters: {
16
+ type: 'object',
17
+ properties: {
18
+ contextPaths: {
19
+ type: 'array',
20
+ description:
21
+ 'An array of absolute paths of files that should be used to provide context for the following updates. Context files could be for example the dependencies, or files that depend on one of the files that we want to update in the next step.',
22
+ items: {
23
+ type: 'string',
24
+ },
25
+ },
26
+ fileUpdates: {
27
+ type: 'array',
28
+ description: 'An array of proposed file updates, each update is an object with several properties.',
29
+ items: {
30
+ type: 'object',
31
+ description:
32
+ 'Proposed update of a file. The update is an object which contains properties like file path, update tool name, and few other important properties.',
33
+ properties: {
34
+ path: { type: 'string', description: 'An absolute path of the project file that will be updated' },
35
+ updateToolName: {
36
+ type: 'string',
37
+ enum: [
38
+ 'createFile',
39
+ 'updateFile',
40
+ 'patchFile',
41
+ 'deleteFile',
42
+ 'createDirectory',
43
+ 'moveFile',
44
+ 'generateImage',
45
+ 'downloadFile',
46
+ 'splitImage',
47
+ 'resizeImage',
48
+ 'imglyRemoveBackground',
49
+ ],
50
+ description: 'A name of the tool that will be used to perform the update.',
51
+ },
52
+ temperature: {
53
+ type: 'number',
54
+ description:
55
+ 'Temperature parameter that will be used for LLM request. The value is adjusted to the characteristic of the update. If there is a need for a more creative solution, the value should be lower, but stil within [0.0, 2.0] range. The default value is: ' +
56
+ temperature,
57
+ },
58
+ cheap: {
59
+ type: 'boolean',
60
+ description:
61
+ 'true value means that the prompt will be executed with cheaper model, which work faster, but provides lower quality results, so please use it only in situation when lower quality results are acceptable for the prompt. The default value is: ' +
62
+ !!cheap,
63
+ },
64
+ prompt: {
65
+ type: 'string',
66
+ description:
67
+ 'Prompt that will be passed to the model request together with the tool request. It summarizes the planned changes for this particular file, so it should be detailed enough for the model to generate necessary changes.',
68
+ },
69
+ contextImageAssets: {
70
+ type: 'array',
71
+ description:
72
+ 'A list of of absolute image asset paths that should be included to the context of LLM request.' +
73
+ 'This parameter must be used if there is a need to analyze an image.',
74
+ items: { type: 'string' },
75
+ },
76
+ },
77
+ required: ['path', 'updateToolName', ...(vision ? ['contextImageAssets'] : [])],
78
+ },
79
+ },
80
+ explanation: {
81
+ type: 'string',
82
+ description: 'Explanation of planned changes or explanation of reasoning for no code changes',
83
+ },
84
+ },
85
+ required: ['fileUpdates', 'contextPaths'],
86
+ },
87
+ };
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Function definition for createDirectory
3
+ */
4
+ export const createDirectory = {
5
+ name: 'createDirectory',
6
+ description: 'Create a new directory',
7
+ parameters: {
8
+ type: 'object',
9
+ properties: {
10
+ filePath: {
11
+ type: 'string',
12
+ description: 'The directory path to create.',
13
+ },
14
+ explanation: {
15
+ type: 'string',
16
+ description: 'The explanation of the reasoning behind creating this directory',
17
+ },
18
+ },
19
+ required: ['filePath'],
20
+ },
21
+ };
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Function definition for createFile
3
+ */
4
+ export const createFile = {
5
+ name: 'createFile',
6
+ description:
7
+ 'Create a new file with specified content. The file will be created inside of project folder structure. This tool should not be used of creation if image files.',
8
+ parameters: {
9
+ type: 'object',
10
+ properties: {
11
+ filePath: {
12
+ type: 'string',
13
+ description: 'Path of the file that will be created, it must not be empty.',
14
+ },
15
+ newContent: {
16
+ type: 'string',
17
+ description: 'Content of the file that will be created, it must no be empty.',
18
+ },
19
+ explanation: {
20
+ type: 'string',
21
+ description: 'The explanation of the reasoning behind creating this file',
22
+ },
23
+ },
24
+ required: ['filePath', 'newContent'],
25
+ },
26
+ };
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Function definition for deleteFile
3
+ */
4
+ export const deleteFile = {
5
+ name: 'deleteFile',
6
+ description: 'Delete a specified file from the application source code.',
7
+ parameters: {
8
+ type: 'object',
9
+ properties: {
10
+ filePath: {
11
+ type: 'string',
12
+ description: 'The file path to delete.',
13
+ },
14
+ explanation: {
15
+ type: 'string',
16
+ description: 'The explanation of the reasoning behind deleting this file',
17
+ },
18
+ },
19
+ required: ['filePath'],
20
+ },
21
+ };