genaicode 0.0.37 → 0.2.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/README.md +3 -1
- package/bin/genaicode-dev.js +11 -0
- package/bin/genaicode.cjs +15 -1
- package/dist/ai-service/ai-studio.d.ts +6 -0
- package/dist/ai-service/ai-studio.js +135 -0
- package/dist/ai-service/ai-studio.js.map +1 -0
- package/dist/ai-service/anthropic.d.ts +6 -0
- package/dist/ai-service/anthropic.js +135 -0
- package/dist/ai-service/anthropic.js.map +1 -0
- package/dist/ai-service/chat-gpt.d.ts +5 -0
- package/dist/ai-service/chat-gpt.js +132 -0
- package/dist/ai-service/chat-gpt.js.map +1 -0
- package/dist/ai-service/common.d.ts +58 -0
- package/dist/ai-service/common.js +38 -0
- package/dist/ai-service/common.js.map +1 -0
- package/dist/ai-service/common.test.d.ts +1 -0
- package/dist/ai-service/common.test.js +85 -0
- package/dist/ai-service/common.test.js.map +1 -0
- package/dist/ai-service/dall-e.d.ts +14 -0
- package/dist/ai-service/dall-e.js +48 -0
- package/dist/ai-service/dall-e.js.map +1 -0
- package/dist/ai-service/vertex-ai-claude.d.ts +5 -0
- package/dist/ai-service/vertex-ai-claude.js +94 -0
- package/dist/ai-service/vertex-ai-claude.js.map +1 -0
- package/dist/ai-service/vertex-ai-imagen.d.ts +14 -0
- package/dist/ai-service/vertex-ai-imagen.js +77 -0
- package/dist/ai-service/vertex-ai-imagen.js.map +1 -0
- package/dist/ai-service/vertex-ai.d.ts +7 -0
- package/dist/ai-service/vertex-ai.js +142 -0
- package/dist/ai-service/vertex-ai.js.map +1 -0
- package/dist/cli/cli-options.d.ts +10 -0
- package/dist/cli/cli-options.js +124 -0
- package/dist/cli/cli-options.js.map +1 -0
- package/dist/cli/cli-options.test.d.ts +1 -0
- package/dist/cli/cli-options.test.js +34 -0
- package/dist/cli/cli-options.test.js.map +1 -0
- package/dist/cli/cli-params.d.ts +30 -0
- package/dist/cli/cli-params.js +109 -0
- package/dist/cli/cli-params.js.map +1 -0
- package/dist/cli/cli-params.test.d.ts +1 -0
- package/dist/cli/cli-params.test.js +38 -0
- package/dist/cli/cli-params.test.js.map +1 -0
- package/dist/cli/service-autodetect.d.ts +2 -0
- package/dist/cli/service-autodetect.js +17 -0
- package/dist/cli/service-autodetect.js.map +1 -0
- package/dist/cli/service-autodetect.test.d.ts +1 -0
- package/dist/cli/service-autodetect.test.js +38 -0
- package/dist/cli/service-autodetect.test.js.map +1 -0
- package/dist/cli/validate-cli-params.d.ts +18 -0
- package/dist/cli/validate-cli-params.js +129 -0
- package/dist/cli/validate-cli-params.js.map +1 -0
- package/dist/cli/validate-cli-params.test.d.ts +1 -0
- package/dist/cli/validate-cli-params.test.js +106 -0
- package/dist/cli/validate-cli-params.test.js.map +1 -0
- package/dist/files/file-utils.d.ts +2 -0
- package/dist/files/file-utils.js +7 -0
- package/dist/files/file-utils.js.map +1 -0
- package/dist/files/file-utils.test.d.ts +1 -0
- package/dist/files/file-utils.test.js +18 -0
- package/dist/files/file-utils.test.js.map +1 -0
- package/dist/files/find-files.d.ts +8 -0
- package/dist/files/find-files.js +76 -0
- package/dist/files/find-files.js.map +1 -0
- package/dist/files/read-files.d.ts +18 -0
- package/dist/files/read-files.js +66 -0
- package/dist/files/read-files.js.map +1 -0
- package/dist/files/read-files.test.d.ts +1 -0
- package/dist/files/read-files.test.js +88 -0
- package/dist/files/read-files.test.js.map +1 -0
- package/dist/files/temp-buffer.d.ts +2 -0
- package/dist/files/temp-buffer.js +12 -0
- package/dist/files/temp-buffer.js.map +1 -0
- package/dist/files/update-files.d.ts +6 -0
- package/dist/files/update-files.js +197 -0
- package/dist/files/update-files.js.map +1 -0
- package/dist/images/ensure-alpha.d.ts +1 -0
- package/dist/images/ensure-alpha.js +5 -0
- package/dist/images/ensure-alpha.js.map +1 -0
- package/dist/images/imgly-remove-background.d.ts +2 -0
- package/dist/images/imgly-remove-background.js +21 -0
- package/dist/images/imgly-remove-background.js.map +1 -0
- package/dist/images/resize-image.d.ts +19 -0
- package/dist/images/resize-image.js +22 -0
- package/dist/images/resize-image.js.map +1 -0
- package/dist/images/split-image.d.ts +18 -0
- package/dist/images/split-image.js +25 -0
- package/dist/images/split-image.js.map +1 -0
- package/dist/main/codegen-interactive-utils.d.ts +8 -0
- package/dist/main/codegen-interactive-utils.js +148 -0
- package/dist/main/codegen-interactive-utils.js.map +1 -0
- package/dist/main/codegen-interactive.d.ts +2 -0
- package/dist/main/codegen-interactive.js +68 -0
- package/dist/main/codegen-interactive.js.map +1 -0
- package/dist/main/codegen-types.d.ts +28 -0
- package/dist/main/codegen-types.js +2 -0
- package/dist/main/codegen-types.js.map +1 -0
- package/dist/main/codegen.d.ts +4 -0
- package/dist/main/codegen.js +164 -0
- package/dist/main/codegen.js.map +1 -0
- package/dist/main/codegen.test.d.ts +2 -0
- package/dist/main/codegen.test.js +273 -0
- package/dist/main/codegen.test.js.map +1 -0
- package/dist/main/config-lib.d.ts +16 -0
- package/dist/main/config-lib.js +28 -0
- package/dist/main/config-lib.js.map +1 -0
- package/dist/main/config-lib.test.d.ts +1 -0
- package/dist/main/config-lib.test.js +64 -0
- package/dist/main/config-lib.test.js.map +1 -0
- package/dist/main/config.d.ts +6 -0
- package/{src → dist}/main/config.js +28 -22
- package/dist/main/config.js.map +1 -0
- package/dist/main/interactive/codegen-interactive.d.ts +2 -0
- package/dist/main/interactive/codegen-interactive.js +55 -0
- package/dist/main/interactive/codegen-interactive.js.map +1 -0
- package/dist/main/interactive/codegen-interactive.test.d.ts +4 -0
- package/dist/main/interactive/codegen-interactive.test.js +77 -0
- package/dist/main/interactive/codegen-interactive.test.js.map +1 -0
- package/dist/main/interactive/codegen-worker.d.ts +3 -0
- package/dist/main/interactive/codegen-worker.js +47 -0
- package/dist/main/interactive/codegen-worker.js.map +1 -0
- package/dist/main/interactive/common.d.ts +5 -0
- package/dist/main/interactive/common.js +51 -0
- package/dist/main/interactive/common.js.map +1 -0
- package/dist/main/interactive/configure.d.ts +2 -0
- package/dist/main/interactive/configure.js +99 -0
- package/dist/main/interactive/configure.js.map +1 -0
- package/dist/main/interactive/error-handling.d.ts +4 -0
- package/dist/main/interactive/error-handling.js +49 -0
- package/dist/main/interactive/error-handling.js.map +1 -0
- package/dist/main/interactive/help.d.ts +1 -0
- package/dist/main/interactive/help.js +22 -0
- package/dist/main/interactive/help.js.map +1 -0
- package/dist/main/interactive/process-comments.d.ts +2 -0
- package/dist/main/interactive/process-comments.js +39 -0
- package/dist/main/interactive/process-comments.js.map +1 -0
- package/dist/main/interactive/select-ai-service.d.ts +2 -0
- package/dist/main/interactive/select-ai-service.js +27 -0
- package/dist/main/interactive/select-ai-service.js.map +1 -0
- package/dist/main/interactive/task-file.d.ts +2 -0
- package/dist/main/interactive/task-file.js +28 -0
- package/dist/main/interactive/task-file.js.map +1 -0
- package/dist/main/interactive/text-prompt.d.ts +2 -0
- package/dist/main/interactive/text-prompt.js +18 -0
- package/dist/main/interactive/text-prompt.js.map +1 -0
- package/dist/main/interactive/user-interrupt.d.ts +1 -0
- package/dist/main/interactive/user-interrupt.js +36 -0
- package/dist/main/interactive/user-interrupt.js.map +1 -0
- package/dist/main/interactive/worker-script.d.ts +1 -0
- package/dist/main/interactive/worker-script.js +24 -0
- package/dist/main/interactive/worker-script.js.map +1 -0
- package/dist/main/interactive/worker.d.ts +2 -0
- package/dist/main/interactive/worker.js +55 -0
- package/dist/main/interactive/worker.js.map +1 -0
- package/dist/prompt/function-calling-validate.d.ts +3 -0
- package/dist/prompt/function-calling-validate.js +33 -0
- package/dist/prompt/function-calling-validate.js.map +1 -0
- package/dist/prompt/function-calling.d.ts +5 -0
- package/{src → dist}/prompt/function-calling.js +25 -24
- package/dist/prompt/function-calling.js.map +1 -0
- package/dist/prompt/function-defs/ask-question.d.ts +65 -0
- package/dist/prompt/function-defs/ask-question.js +67 -0
- package/dist/prompt/function-defs/ask-question.js.map +1 -0
- package/dist/prompt/function-defs/codegen-summary.d.ts +63 -0
- package/dist/prompt/function-defs/codegen-summary.js +80 -0
- package/dist/prompt/function-defs/codegen-summary.js.map +1 -0
- package/dist/prompt/function-defs/create-directory.d.ts +21 -0
- package/dist/prompt/function-defs/create-directory.js +22 -0
- package/dist/prompt/function-defs/create-directory.js.map +1 -0
- package/dist/prompt/function-defs/create-file.d.ts +25 -0
- package/dist/prompt/function-defs/create-file.js +26 -0
- package/dist/prompt/function-defs/create-file.js.map +1 -0
- package/dist/prompt/function-defs/delete-file.d.ts +21 -0
- package/dist/prompt/function-defs/delete-file.js +22 -0
- package/dist/prompt/function-defs/delete-file.js.map +1 -0
- package/dist/prompt/function-defs/download-file.d.ts +25 -0
- package/dist/prompt/function-defs/download-file.js +26 -0
- package/dist/prompt/function-defs/download-file.js.map +1 -0
- package/dist/prompt/function-defs/explanation.d.ts +17 -0
- package/dist/prompt/function-defs/explanation.js +18 -0
- package/dist/prompt/function-defs/explanation.js.map +1 -0
- package/dist/prompt/function-defs/generate-image.d.ts +41 -0
- package/dist/prompt/function-defs/generate-image.js +42 -0
- package/dist/prompt/function-defs/generate-image.js.map +1 -0
- package/dist/prompt/function-defs/get-image-assets.d.ts +20 -0
- package/dist/prompt/function-defs/get-image-assets.js +21 -0
- package/dist/prompt/function-defs/get-image-assets.js.map +1 -0
- package/dist/prompt/function-defs/get-source-code.d.ts +20 -0
- package/dist/prompt/function-defs/get-source-code.js +21 -0
- package/dist/prompt/function-defs/get-source-code.js.map +1 -0
- package/dist/prompt/function-defs/imgly-remove-background.d.ts +25 -0
- package/dist/prompt/function-defs/imgly-remove-background.js +26 -0
- package/dist/prompt/function-defs/imgly-remove-background.js.map +1 -0
- package/dist/prompt/function-defs/move-file.d.ts +25 -0
- package/dist/prompt/function-defs/move-file.js +26 -0
- package/dist/prompt/function-defs/move-file.js.map +1 -0
- package/dist/prompt/function-defs/patch-file.d.ts +25 -0
- package/dist/prompt/function-defs/patch-file.js +39 -0
- package/dist/prompt/function-defs/patch-file.js.map +1 -0
- package/dist/prompt/function-defs/resize-image.d.ts +36 -0
- package/dist/prompt/function-defs/resize-image.js +37 -0
- package/dist/prompt/function-defs/resize-image.js.map +1 -0
- package/dist/prompt/function-defs/split-image.d.ts +57 -0
- package/dist/prompt/function-defs/split-image.js +46 -0
- package/dist/prompt/function-defs/split-image.js.map +1 -0
- package/dist/prompt/function-defs/update-file.d.ts +25 -0
- package/dist/prompt/function-defs/update-file.js +26 -0
- package/dist/prompt/function-defs/update-file.js.map +1 -0
- package/dist/prompt/limits.d.ts +3 -0
- package/dist/prompt/limits.js +19 -0
- package/dist/prompt/limits.js.map +1 -0
- package/dist/prompt/limits.test.d.ts +1 -0
- package/dist/prompt/limits.test.js +35 -0
- package/dist/prompt/limits.test.js.map +1 -0
- package/dist/prompt/prompt-codegen.d.ts +9 -0
- package/dist/prompt/prompt-codegen.js +90 -0
- package/dist/prompt/prompt-codegen.js.map +1 -0
- package/dist/prompt/prompt-codegen.test.d.ts +1 -0
- package/dist/prompt/prompt-codegen.test.js +98 -0
- package/dist/prompt/prompt-codegen.test.js.map +1 -0
- package/dist/prompt/prompt-consts.d.ts +1 -0
- package/{src → dist}/prompt/prompt-consts.js +1 -0
- package/dist/prompt/prompt-consts.js.map +1 -0
- package/dist/prompt/prompt-service-ask-question.test.d.ts +3 -0
- package/dist/prompt/prompt-service-ask-question.test.js +142 -0
- package/dist/prompt/prompt-service-ask-question.test.js.map +1 -0
- package/dist/prompt/prompt-service.d.ts +28 -0
- package/dist/prompt/prompt-service.js +163 -0
- package/dist/prompt/prompt-service.js.map +1 -0
- package/dist/prompt/prompt-service.test.d.ts +1 -0
- package/dist/prompt/prompt-service.test.js +531 -0
- package/dist/prompt/prompt-service.test.js.map +1 -0
- package/dist/prompt/steps/step-ask-question.d.ts +6 -0
- package/dist/prompt/steps/step-ask-question.js +82 -0
- package/dist/prompt/steps/step-ask-question.js.map +1 -0
- package/dist/prompt/steps/step-generate-image.d.ts +2 -0
- package/dist/prompt/steps/step-generate-image.js +29 -0
- package/dist/prompt/steps/step-generate-image.js.map +1 -0
- package/dist/prompt/steps/step-validate-recover.d.ts +13 -0
- package/dist/prompt/steps/step-validate-recover.js +51 -0
- package/dist/prompt/steps/step-validate-recover.js.map +1 -0
- package/dist/prompt/steps/step-verify-patch.d.ts +7 -0
- package/dist/prompt/steps/step-verify-patch.js +41 -0
- package/dist/prompt/steps/step-verify-patch.js.map +1 -0
- package/dist/prompt/steps/steps-types.d.ts +4 -0
- package/dist/prompt/steps/steps-types.js +6 -0
- package/dist/prompt/steps/steps-types.js.map +1 -0
- package/dist/prompt/systemprompt.d.ts +3 -0
- package/dist/prompt/systemprompt.js +47 -0
- package/dist/prompt/systemprompt.js.map +1 -0
- package/dist/prompt/systemprompt.test.d.ts +3 -0
- package/dist/prompt/systemprompt.test.js +46 -0
- package/dist/prompt/systemprompt.test.js.map +1 -0
- package/package.json +15 -5
- package/bin/genaicode.js +0 -5
- package/bin/vertex-monkey-patch.cjs +0 -33
- package/src/ai-service/anthropic.js +0 -126
- package/src/ai-service/chat-gpt.js +0 -126
- package/src/ai-service/common.js +0 -49
- package/src/ai-service/common.test.js +0 -107
- package/src/ai-service/dall-e.js +0 -50
- package/src/ai-service/vertex-ai-claude.js +0 -99
- package/src/ai-service/vertex-ai-imagen.js +0 -78
- package/src/ai-service/vertex-ai.js +0 -156
- package/src/cli/cli-options.js +0 -132
- package/src/cli/cli-options.test.js +0 -50
- package/src/cli/cli-params.js +0 -114
- package/src/cli/cli-params.test.js +0 -43
- package/src/cli/service-autodetect.js +0 -11
- package/src/cli/service-autodetect.test.js +0 -43
- package/src/cli/validate-cli-params.js +0 -137
- package/src/cli/validate-cli-params.test.js +0 -134
- package/src/files/file-utils.js +0 -7
- package/src/files/file-utils.test.js +0 -21
- package/src/files/find-files.js +0 -86
- package/src/files/read-files.js +0 -65
- package/src/files/read-files.test.js +0 -103
- package/src/files/temp-buffer.js +0 -13
- package/src/files/update-files.js +0 -205
- package/src/images/ensure-alpha.js +0 -5
- package/src/images/imgly-remove-background.js +0 -23
- package/src/images/resize-image.js +0 -23
- package/src/images/split-image.js +0 -26
- package/src/main/codegen.js +0 -120
- package/src/main/codegen.test.js +0 -335
- package/src/main/config-lib.js +0 -33
- package/src/main/config-lib.test.js +0 -80
- package/src/prompt/function-calling-validate.js +0 -25
- package/src/prompt/function-defs/ask-question.js +0 -33
- package/src/prompt/function-defs/codegen-summary.js +0 -87
- package/src/prompt/function-defs/create-directory.js +0 -21
- package/src/prompt/function-defs/create-file.js +0 -26
- package/src/prompt/function-defs/delete-file.js +0 -21
- package/src/prompt/function-defs/download-file.js +0 -25
- package/src/prompt/function-defs/explanation.js +0 -17
- package/src/prompt/function-defs/generate-image.js +0 -51
- package/src/prompt/function-defs/get-image-assets.js +0 -21
- package/src/prompt/function-defs/get-source-code.js +0 -21
- package/src/prompt/function-defs/imgly-remove-background.js +0 -25
- package/src/prompt/function-defs/move-file.js +0 -25
- package/src/prompt/function-defs/patch-file.js +0 -39
- package/src/prompt/function-defs/resize-image.js +0 -36
- package/src/prompt/function-defs/split-image.js +0 -45
- package/src/prompt/function-defs/update-file.js +0 -26
- package/src/prompt/limits.js +0 -23
- package/src/prompt/limits.test.js +0 -40
- package/src/prompt/prompt-codegen.js +0 -106
- package/src/prompt/prompt-codegen.test.js +0 -116
- package/src/prompt/prompt-service-ask-question.test.js +0 -163
- package/src/prompt/prompt-service.js +0 -335
- package/src/prompt/prompt-service.test.js +0 -602
- package/src/prompt/systemprompt.js +0 -39
- package/src/prompt/systemprompt.test.js +0 -64
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step-ask-question.js","sourceRoot":"","sources":["../../../src/prompt/steps/step-ask-question.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,iBAO4B,EAC5B,MAAo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C;oBAC7D,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;gBACjC,CAAC;gBACD,IAAI,eAAe,CAAC,IAAI,EAAE,kBAAkB,CAAC,aAAa,EAAE,CAAC;oBAC3D,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;gBAC/B,CAAC;YACH,CAAC;YAED,MAAM,CAAC,IAAI,CACT,EAAE,IAAI,EAAE,WAAW,EAAE,aAAa,EAAE,CAAC,eAAe,CAAC,EAAE,EACvD;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,UAAU;gBAChB,iBAAiB,EAAE;oBACjB;wBACE,IAAI,EAAE,aAAa;wBACnB,OAAO,EAAE,eAAe,CAAC,EAAE;wBAC3B,OAAO,EACL,oBAAoB,IAAI,UAAU,KAAK,oCAAoC;4BACzE,CAAC,CAAC,QAAQ,CAAC,iBAAiB,CAAC,eAAe,CAAC,IAAK,CAAC,mBAAoB,CAAC;4BACxE,CAAC,CAAC,SAAS;qBAChB;iBACF;aACF,CACF,CAAC;YACF,OAAO,CAAC,GAAG,CAAC,2BAA2B,EAAE,UAAU,CAAC,CAAC;QACvD,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,oEAAoE,CAAC,CAAC;YAClF,MAAM;QACR,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC,QAAQ,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
export async function executeStepGenerateImage(generateImageFn, generateImageCall) {
|
|
3
|
+
assert(!!generateImageFn, 'Image generation requested, but an image generation service was not provided');
|
|
4
|
+
console.log('Processing image generation request:', generateImageCall.args);
|
|
5
|
+
try {
|
|
6
|
+
const { prompt: imagePrompt, filePath, contextImagePath, width, height, cheap, } = generateImageCall.args;
|
|
7
|
+
const generatedImageUrl = await generateImageFn(imagePrompt, contextImagePath, { width, height }, cheap === true);
|
|
8
|
+
// Add a downloadFile call to the result to ensure the generated image is tracked
|
|
9
|
+
return {
|
|
10
|
+
name: 'downloadFile',
|
|
11
|
+
args: {
|
|
12
|
+
filePath: filePath,
|
|
13
|
+
downloadUrl: generatedImageUrl,
|
|
14
|
+
explanation: `Downloading generated image`,
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
console.error('Error generating image:', error);
|
|
20
|
+
// Add an explanation about the failed image generation
|
|
21
|
+
return {
|
|
22
|
+
name: 'explanation',
|
|
23
|
+
args: {
|
|
24
|
+
text: `Failed to generate image: ${error.message}`,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=step-generate-image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step-generate-image.js","sourceRoot":"","sources":["../../../src/prompt/steps/step-generate-image.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAGjC,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,eAAsC,EACtC,iBAA+B;IAE/B,MAAM,CAAC,CAAC,CAAC,eAAe,EAAE,8EAA8E,CAAC,CAAC;IAE1G,OAAO,CAAC,GAAG,CAAC,sCAAsC,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAE5E,IAAI,CAAC;QACH,MAAM,EACJ,MAAM,EAAE,WAAW,EACnB,QAAQ,EACR,gBAAgB,EAChB,KAAK,EACL,MAAM,EACN,KAAK,GACN,GAAG,iBAAiB,CAAC,IAOrB,CAAC;QACF,MAAM,iBAAiB,GAAG,MAAM,eAAe,CAAC,WAAW,EAAE,gBAAgB,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,KAAK,KAAK,IAAI,CAAC,CAAC;QAElH,iFAAiF;QACjF,OAAO;YACL,IAAI,EAAE,cAAc;YACpB,IAAI,EAAE;gBACJ,QAAQ,EAAE,QAAQ;gBAClB,WAAW,EAAE,iBAAiB;gBAC9B,WAAW,EAAE,6BAA6B;aAC3C;SACF,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;QAChD,uDAAuD;QACvD,OAAO;YACL,IAAI,EAAE,aAAa;YACnB,IAAI,EAAE;gBACJ,IAAI,EAAE,6BAA8B,KAAe,CAAC,OAAO,EAAE;aAC9D;SACF,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PromptItem, FunctionDef, FunctionCall, GenerateContentFunction } from '../../ai-service/common.js';
|
|
2
|
+
import { CodegenOptions } from '../../main/codegen-types.js';
|
|
3
|
+
export declare function validateAndRecoverSingleResult([prompt, functionDefs, requiredFunctionName, temperature, cheap, options]: [
|
|
4
|
+
PromptItem[],
|
|
5
|
+
FunctionDef[],
|
|
6
|
+
string,
|
|
7
|
+
number,
|
|
8
|
+
boolean,
|
|
9
|
+
CodegenOptions
|
|
10
|
+
], result: FunctionCall[], messages: {
|
|
11
|
+
invalidFunctionCall: string;
|
|
12
|
+
partialPromptTemplate: (path: string) => string;
|
|
13
|
+
}, generateContentFn: GenerateContentFunction): Promise<FunctionCall[]>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
import { validateFunctionCall } from '../function-calling-validate.js';
|
|
3
|
+
export async function validateAndRecoverSingleResult([prompt, functionDefs, requiredFunctionName, temperature, cheap, options], result, messages, generateContentFn) {
|
|
4
|
+
if (result.length > 1) {
|
|
5
|
+
// quite unexpected
|
|
6
|
+
return result;
|
|
7
|
+
}
|
|
8
|
+
let call = result[0];
|
|
9
|
+
const validatorError = validateFunctionCall(call, requiredFunctionName);
|
|
10
|
+
if (validatorError) {
|
|
11
|
+
console.log('Invalid function call', call, validatorError);
|
|
12
|
+
if (!call) {
|
|
13
|
+
call = { name: requiredFunctionName };
|
|
14
|
+
if (requiredFunctionName === 'patchFile') {
|
|
15
|
+
console.log('Switching patchFile to updateFile');
|
|
16
|
+
requiredFunctionName = 'updateFile';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
prompt.push({ type: 'assistant', functionCalls: [call] }, {
|
|
20
|
+
type: 'user',
|
|
21
|
+
text: messages.invalidFunctionCall,
|
|
22
|
+
functionResponses: [
|
|
23
|
+
{
|
|
24
|
+
name: call.name,
|
|
25
|
+
call_id: call.id,
|
|
26
|
+
content: JSON.stringify({ args: call.args, error: validatorError }),
|
|
27
|
+
isError: true,
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
});
|
|
31
|
+
console.log('Trying to recover...');
|
|
32
|
+
if (cheap) {
|
|
33
|
+
console.log('Disabling --cheap for recovery.');
|
|
34
|
+
}
|
|
35
|
+
result = await generateContentFn(prompt, functionDefs, requiredFunctionName, temperature, false, options);
|
|
36
|
+
console.log('Recover result:', result);
|
|
37
|
+
if (result?.length === 1) {
|
|
38
|
+
const recoveryError = validateFunctionCall(result[0], requiredFunctionName);
|
|
39
|
+
assert(!recoveryError, 'Recovery failed');
|
|
40
|
+
console.log('Recovery was successful');
|
|
41
|
+
}
|
|
42
|
+
else if (result?.length === 0) {
|
|
43
|
+
throw new Error('Did not receive any function calls unexpectedly.');
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
console.log('Unexpected number of function calls', result);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=step-validate-recover.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step-validate-recover.js","sourceRoot":"","sources":["../../../src/prompt/steps/step-validate-recover.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAGvE,MAAM,CAAC,KAAK,UAAU,8BAA8B,CAClD,CAAC,MAAM,EA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iC,CAAC,CAAC;QACjD,CAAC;QACD,MAAM,GAAG,MAAM,iBAAiB,CAAC,MAAM,EAAE,YAAY,EAAE,oBAAoB,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QAC1G,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC;QAEvC,IAAI,MAAM,EAAE,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,MAAM,aAAa,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC;YAC5E,MAAM,CAAC,CAAC,aAAa,EAAE,iBAAiB,CAAC,CAAC;YAC1C,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;QACzC,CAAC;aAAM,IAAI,MAAM,EAAE,MAAM,KAAK,CAAC,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;QACtE,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,qCAAqC,EAAE,MAAM,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PromptItem, FunctionDef, FunctionCall, GenerateContentFunction } from '../../ai-service/common.js';
|
|
2
|
+
import { PromptMessages } from '../prompt-service.js';
|
|
3
|
+
import { CodegenOptions } from '../../main/codegen-types.js';
|
|
4
|
+
export declare function executeStepVerifyPatch({ filePath, patch }: {
|
|
5
|
+
filePath: string;
|
|
6
|
+
patch: string;
|
|
7
|
+
}, generateContentFn: GenerateContentFunction, prompt: PromptItem[], functionDefs: FunctionDef[], temperature: number, cheap: boolean, messages: PromptMessages, options: CodegenOptions): Promise<FunctionCall[]>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import * as diff from 'diff';
|
|
3
|
+
import { validateAndRecoverSingleResult } from './step-validate-recover.js';
|
|
4
|
+
export async function executeStepVerifyPatch({ filePath, patch }, generateContentFn, prompt, functionDefs, temperature, cheap, messages, options) {
|
|
5
|
+
console.log('Verification of patch for file:', filePath);
|
|
6
|
+
let updatedContent = false;
|
|
7
|
+
const currentContent = fs.readFileSync(filePath, 'utf-8');
|
|
8
|
+
try {
|
|
9
|
+
updatedContent = diff.applyPatch(currentContent, patch);
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
console.log('Error when applying patch', e);
|
|
13
|
+
}
|
|
14
|
+
if (!updatedContent) {
|
|
15
|
+
console.log(`Patch could not be applied for ${filePath}. Retrying without patchFile function.`);
|
|
16
|
+
// Rerun content generation without patchFile function
|
|
17
|
+
const partialRequest = [
|
|
18
|
+
prompt,
|
|
19
|
+
functionDefs,
|
|
20
|
+
'updateFile',
|
|
21
|
+
temperature,
|
|
22
|
+
cheap,
|
|
23
|
+
options,
|
|
24
|
+
];
|
|
25
|
+
let partialResult = await generateContentFn(...partialRequest);
|
|
26
|
+
partialResult = await validateAndRecoverSingleResult(partialRequest, partialResult, messages, generateContentFn);
|
|
27
|
+
const getSourceCodeCall = partialResult.find((call) => call.name === 'getSourceCode');
|
|
28
|
+
if (getSourceCodeCall) {
|
|
29
|
+
throw new Error('Unexpected getSourceCode: ' + JSON.stringify(getSourceCodeCall));
|
|
30
|
+
}
|
|
31
|
+
if (partialResult.find((call) => call.name === 'patchFile')) {
|
|
32
|
+
throw new Error('Unexpected patchFile in retry response');
|
|
33
|
+
}
|
|
34
|
+
return partialResult;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
console.log('Patch verified successfully');
|
|
38
|
+
return [{ name: 'patchFile', args: { filePath, patch } }];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=step-verify-patch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step-verify-patch.js","sourceRoot":"","sources":["../../../src/prompt/steps/step-verify-patch.ts"],"names":[],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AiB,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,4BAA4B,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC,CAAC;QACpF,CAAC;QACD,IAAI,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,WAAW,CAAC,EAAE,CAAC;YAC5D,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;QAC5D,CAAC;QAED,OAAO,aAAa,CAAC;IACvB,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;QAC3C,OAAO,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;IAC5D,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"steps-types.js","sourceRoot":"","sources":["../../../src/prompt/steps/steps-types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,UAGX;AAHD,WAAY,UAAU;IACpB,mDAAQ,CAAA;IACR,6CAAK,CAAA;AACP,CAAC,EAHW,UAAU,KAAV,UAAU,QAGrB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { CODEGEN_TRIGGER } from './prompt-consts.js';
|
|
2
|
+
import { verifySystemPromptLimit } from './limits.js';
|
|
3
|
+
import { rcConfig } from '../main/config.js';
|
|
4
|
+
/** Generates a system prompt */
|
|
5
|
+
export function getSystemPrompt({ verbose, askQuestion, interactive }) {
|
|
6
|
+
console.log('Generate system prompt');
|
|
7
|
+
let systemPrompt = `
|
|
8
|
+
You are a code generation assistant. I want you to help me generate code for my ideas in my application source code.
|
|
9
|
+
|
|
10
|
+
You can generate new code, or modify the existing one. You will receive instructions on what is the goal of requested code modification.
|
|
11
|
+
|
|
12
|
+
Instructions will be passed to you either directly via message, with a file, or using the ${CODEGEN_TRIGGER} comment in the code.
|
|
13
|
+
|
|
14
|
+
You should parse my application source code and then suggest changes using appropriate tools.
|
|
15
|
+
|
|
16
|
+
The root directory of my application is \`${rcConfig.rootDir}\` and you should limit the changes only to this path.
|
|
17
|
+
|
|
18
|
+
Additional suggestions, or corners cases to think about:
|
|
19
|
+
- When suggesting changes always use absolute file paths, exactly as you have been provided. Modified paths will cause errors and we want to avoid that.
|
|
20
|
+
- Always aim to return working code
|
|
21
|
+
- Do not leave out commented out fragments like "// ... (keep other existing functions)"
|
|
22
|
+
- For large files prefer to use \`patchFile\` function
|
|
23
|
+
- Suggest user to split large files if it makes sense for current task
|
|
24
|
+
- At the start of conversation the user will express what you are allowed to do (for example: create files, move files, generate images etc.). At the start of conversation you should ensure you have necessary allowances for the current task.
|
|
25
|
+
- Consider failing the task with explanation if instructions are not clear enough, or something feels completely wrong.
|
|
26
|
+
- Do not produce unnecessary code, ensure the code you generate will be used once all changes are done.
|
|
27
|
+
- Always ask for sufficient context paths in codegen summary, ask for files in context that is needed to completed the task
|
|
28
|
+
|
|
29
|
+
`;
|
|
30
|
+
if (askQuestion && interactive) {
|
|
31
|
+
systemPrompt +=
|
|
32
|
+
'\nYou have the ability to ask the user a question at the beginning of the conversation if you need more information or clarification. ' +
|
|
33
|
+
'Use this feature wisely to gather any crucial information that would help you better understand the task or provide more accurate code generation.\n' +
|
|
34
|
+
"To ask a question, use the 'askQuestion' function. This function allows you to:" +
|
|
35
|
+
`- inform the user about your thoughts regarding the task
|
|
36
|
+
- ask questions, and give suggestions to the user regarding the task
|
|
37
|
+
- request access to content of files if they are not provided in the conversation so far, but are important for the task
|
|
38
|
+
- request enablement of permissions for operations that were restricted on the start of conversation, but are important for completion of the task`;
|
|
39
|
+
}
|
|
40
|
+
if (verbose) {
|
|
41
|
+
console.log('System prompt:');
|
|
42
|
+
console.log(systemPrompt);
|
|
43
|
+
}
|
|
44
|
+
verifySystemPromptLimit(systemPrompt);
|
|
45
|
+
return systemPrompt;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=systemprompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"systemprompt.js","sourceRoot":"","sources":["../../src/prompt/systemprompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAG7C,gCAAgC;AAChC,MAAM,UAAU,eAAe,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAkB;IACnF,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;IAEtC,IAAI,YAAY,GAAG;;;;;8FAKyE,eAAe;;;;8CAI/D,QAAQ,CAAC,OAAO;;;;;;;;;;;;;GAa3D,CAAC;IAEF,IAAI,WAAW,IAAI,WAAW,EAAE,CAAC;QAC/B,YAAY;YACV,wIAAwI;gBACxI,sJAAsJ;gBACtJ,iFAAiF;gBACjF;;;yJAGmJ,CAAC;IACxJ,CAAC;IAED,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QAC9B,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAC5B,CAAC;IAED,uBAAuB,CAAC,YAAY,CAAC,CAAC;IAEtC,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
2
|
+
import { getSystemPrompt } from './systemprompt.js';
|
|
3
|
+
import '../cli/cli-params.js';
|
|
4
|
+
import '../files/find-files.js';
|
|
5
|
+
import '../main/config.js';
|
|
6
|
+
vi.mock('../cli/cli-params.js', () => ({
|
|
7
|
+
requireExplanations: false,
|
|
8
|
+
considerAllFiles: false,
|
|
9
|
+
dependencyTree: false,
|
|
10
|
+
explicitPrompt: false,
|
|
11
|
+
allowFileCreate: false,
|
|
12
|
+
allowFileDelete: false,
|
|
13
|
+
allowDirectoryCreate: false,
|
|
14
|
+
allowFileMove: false,
|
|
15
|
+
verbosePrompt: false,
|
|
16
|
+
askQuestion: false,
|
|
17
|
+
}));
|
|
18
|
+
vi.mock('../files/find-files.js', () => ({
|
|
19
|
+
getSourceFiles: vi.fn(),
|
|
20
|
+
}));
|
|
21
|
+
vi.mock('../main/config.js', () => ({
|
|
22
|
+
rcConfig: { rootDir: '/mocked/root/dir' },
|
|
23
|
+
}));
|
|
24
|
+
describe('getSystemPrompt', () => {
|
|
25
|
+
beforeEach(() => {
|
|
26
|
+
vi.clearAllMocks();
|
|
27
|
+
});
|
|
28
|
+
it('generates correct system prompt', () => {
|
|
29
|
+
const systemPrompt = getSystemPrompt({ aiService: 'vertex-ai' });
|
|
30
|
+
expect(systemPrompt).toContain('You are a code generation assistant. I want you to help me generate code for my ideas in my application source code.');
|
|
31
|
+
expect(systemPrompt).toContain('You can generate new code, or modify the existing one.');
|
|
32
|
+
expect(systemPrompt).toContain('Instructions will be passed to you either directly via message, with a file, or using the ' +
|
|
33
|
+
'@' +
|
|
34
|
+
'CODEGEN comment in the code.');
|
|
35
|
+
expect(systemPrompt).toContain('The root directory of my application is `/mocked/root/dir` and you should limit the changes only to this path.');
|
|
36
|
+
expect(systemPrompt).toContain('When suggesting changes always use absolute file paths');
|
|
37
|
+
});
|
|
38
|
+
it('verifies system prompt limit', () => {
|
|
39
|
+
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
|
|
40
|
+
getSystemPrompt({ aiService: 'vertex-ai', verbose: true });
|
|
41
|
+
expect(consoleSpy).toHaveBeenCalledWith('System prompt:');
|
|
42
|
+
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('You are a code generation assistant. I want you to help me generate code for my ideas'));
|
|
43
|
+
consoleSpy.mockRestore();
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=systemprompt.test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AAC;QAEjE,MAAM,CAAC,YAAY,CAAC,CAAC,SAAS,CAC5B,sHAAsH,CACvH,CAAC;QACF,MAAM,CAAC,YAAY,CAAC,CAAC,SAAS,CAAC,wDAAwD,CAAC,CAAC;QACzF,MAAM,CAAC,YAAY,CAAC,CAAC,SAAS,CAC5B,4FAA4F;YAC1F,GAAG;YACH,8BAA8B,CACjC,CAAC;QACF,MAAM,CAAC,YAAY,CAAC,CAAC,SAAS,CAC5B,gHAAgH,CACjH,CAAC;QACF,MAAM,CAAC,YAAY,CAAC,CAAC,SAAS,CAAC,wDAAwD,CAAC,CAAC;IAC3F,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8BAA8B,EAAE,GAAG,EAAE;QACtC,MAAM,UAAU,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QAEzE,eAAe,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QAE3D,MAAM,CAAC,UAAU,CAAC,CAAC,oBAAoB,CAAC,gBAAgB,CAAC,CAAC;QAC1D,MAAM,CAAC,UAAU,CAAC,CAAC,oBAAoB,CACrC,MAAM,CAAC,gBAAgB,CAAC,uFAAuF,CAAC,CACjH,CAAC;QAEF,UAAU,CAAC,WAAW,EAAE,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "genaicode",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"author": "Grzegorz Tańczyk",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -19,17 +19,19 @@
|
|
|
19
19
|
"license": "Apache-2.0",
|
|
20
20
|
"files": [
|
|
21
21
|
"bin",
|
|
22
|
-
"
|
|
22
|
+
"dist",
|
|
23
23
|
"media",
|
|
24
24
|
"README.md",
|
|
25
25
|
"LICENSE"
|
|
26
26
|
],
|
|
27
27
|
"scripts": {
|
|
28
|
-
"lint": "eslint . --ext js --report-unused-disable-directives --max-warnings 0",
|
|
28
|
+
"lint": "eslint . --ext js,ts --report-unused-disable-directives --max-warnings 0",
|
|
29
29
|
"test": "vitest",
|
|
30
30
|
"coverage": "vitest run --coverage",
|
|
31
31
|
"prepare": "husky install",
|
|
32
|
-
"
|
|
32
|
+
"type-check": "tsc --noEmit",
|
|
33
|
+
"build": "tsc",
|
|
34
|
+
"prepublishOnly": "npm run build"
|
|
33
35
|
},
|
|
34
36
|
"devDependencies": {
|
|
35
37
|
"@typescript-eslint/eslint-plugin": "^7.17.0",
|
|
@@ -40,17 +42,25 @@
|
|
|
40
42
|
"husky": "^9.1.1",
|
|
41
43
|
"lint-staged": "^15.2.7",
|
|
42
44
|
"prettier": "^3.1.0",
|
|
45
|
+
"ts-node": "^10.9.2",
|
|
46
|
+
"typescript": "^5.0.0",
|
|
43
47
|
"vitest": "^2.0.4"
|
|
44
48
|
},
|
|
45
49
|
"dependencies": {
|
|
46
50
|
"@anthropic-ai/sdk": "^0.26.1",
|
|
47
51
|
"@anthropic-ai/vertex-sdk": "^0.4.1",
|
|
48
52
|
"@google-cloud/aiplatform": "^3.25.0",
|
|
49
|
-
"@google-cloud/vertexai": "^1.
|
|
53
|
+
"@google-cloud/vertexai": "^1.6.0",
|
|
54
|
+
"@google/generative-ai": "^0.17.1",
|
|
50
55
|
"@imgly/background-removal-node": "^1.4.5",
|
|
56
|
+
"@inquirer/prompts": "^5.3.8",
|
|
57
|
+
"@types/diff": "^5.2.1",
|
|
58
|
+
"@types/mime-types": "^2.1.4",
|
|
59
|
+
"@types/node": "^18.0.0",
|
|
51
60
|
"diff": "^5.2.0",
|
|
52
61
|
"glob-regex": "^0.3.2",
|
|
53
62
|
"image-size": "^1.1.1",
|
|
63
|
+
"inquirer-file-selector": "^0.4.0",
|
|
54
64
|
"jsonschema": "^1.4.1",
|
|
55
65
|
"mime-types": "^2.1.35",
|
|
56
66
|
"openai": "^4.52.7",
|
package/bin/genaicode.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
|
|
5
|
-
// Add node version check
|
|
6
|
-
const pkg = require('../package.json');
|
|
7
|
-
const pleaseUpgradeNode = require('please-upgrade-node');
|
|
8
|
-
pleaseUpgradeNode(pkg);
|
|
9
|
-
|
|
10
|
-
const MONKEY_PATCH_FILE = '@google-cloud/vertexai/build/src/functions/generate_content.js';
|
|
11
|
-
const MONKEY_PATCH_TOOL_CONFIG = `// MONKEY PATCH TOOL_CONFIG`;
|
|
12
|
-
|
|
13
|
-
console.log('Apply vertex monkey patch');
|
|
14
|
-
const path = require.resolve(MONKEY_PATCH_FILE);
|
|
15
|
-
const content = fs.readFileSync(path, 'utf-8');
|
|
16
|
-
|
|
17
|
-
if (!content) {
|
|
18
|
-
console.log('Could not find file:', path);
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (content.includes(MONKEY_PATCH_TOOL_CONFIG)) {
|
|
23
|
-
console.log('Patch already applied');
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const newContent = content.replaceAll(
|
|
28
|
-
'data: generateContentRequest,',
|
|
29
|
-
`// MONKEY PATCH TOOL_CONFIG
|
|
30
|
-
data: {...generateContentRequest,tool_config: {function_calling_config: { mode: request.toolConfig?.functionCallingConfig?.mode, allowed_function_names: request.toolConfig?.functionCallingConfig.allowedFunctionNames }}},`,
|
|
31
|
-
);
|
|
32
|
-
fs.writeFileSync(path, newContent, 'utf-8');
|
|
33
|
-
console.log('Vertex monkey patch applied');
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import Anthropic from '@anthropic-ai/sdk';
|
|
2
|
-
import { printTokenUsageAndCost, processFunctionCalls } from './common.js';
|
|
3
|
-
import { disableCache } from '../cli/cli-params.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* This function generates content using the Anthropic Claude model.
|
|
7
|
-
*/
|
|
8
|
-
export async function generateContent(prompt, functionDefs, requiredFunctionName, temperature, cheap = false) {
|
|
9
|
-
const anthropic = new Anthropic({
|
|
10
|
-
defaultHeaders: {
|
|
11
|
-
'anthropic-beta': 'max-tokens-3-5-sonnet-2024-07-15' + (!disableCache ? ',prompt-caching-2024-07-31' : ''),
|
|
12
|
-
},
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
const messages = prompt
|
|
16
|
-
.filter((item) => item.type !== 'systemPrompt')
|
|
17
|
-
.map((item) => {
|
|
18
|
-
if (item.type === 'user') {
|
|
19
|
-
return {
|
|
20
|
-
role: 'user',
|
|
21
|
-
content: [
|
|
22
|
-
...(item.functionResponses ?? []).map((response) => ({
|
|
23
|
-
tool_use_id: response.call_id ?? response.name,
|
|
24
|
-
content: response.content,
|
|
25
|
-
type: 'tool_result',
|
|
26
|
-
is_error: response.isError === true,
|
|
27
|
-
})),
|
|
28
|
-
...(item.images ?? []).map((image) => ({
|
|
29
|
-
type: 'image',
|
|
30
|
-
source: {
|
|
31
|
-
type: 'base64',
|
|
32
|
-
media_type: image.mediaType,
|
|
33
|
-
data: image.base64url,
|
|
34
|
-
},
|
|
35
|
-
})),
|
|
36
|
-
{
|
|
37
|
-
type: 'text',
|
|
38
|
-
text: item.text,
|
|
39
|
-
...(item.cache && !disableCache ? { cache_control: { type: 'ephemeral' } } : {}),
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
};
|
|
43
|
-
} else if (item.type === 'assistant') {
|
|
44
|
-
return {
|
|
45
|
-
role: 'assistant',
|
|
46
|
-
content: [
|
|
47
|
-
...(item.text ? [{ type: 'text', text: item.text }] : []),
|
|
48
|
-
...item.functionCalls.map((call) => ({
|
|
49
|
-
id: call.id ?? call.name,
|
|
50
|
-
name: call.name,
|
|
51
|
-
input: call.args ?? {},
|
|
52
|
-
type: 'tool_use',
|
|
53
|
-
})),
|
|
54
|
-
],
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
const model = cheap ? 'claude-3-haiku-20240307' : 'claude-3-5-sonnet-20240620';
|
|
60
|
-
console.log(`Using Anthropic model: ${model}`);
|
|
61
|
-
|
|
62
|
-
let retryCount = 0;
|
|
63
|
-
let response;
|
|
64
|
-
while (retryCount < 3) {
|
|
65
|
-
try {
|
|
66
|
-
response = await anthropic.beta.promptCaching.messages.create({
|
|
67
|
-
model: model,
|
|
68
|
-
system: prompt.find((item) => item.type === 'systemPrompt').systemPrompt,
|
|
69
|
-
messages,
|
|
70
|
-
tools: functionDefs.map((fd) => ({
|
|
71
|
-
name: fd.name,
|
|
72
|
-
description: fd.description,
|
|
73
|
-
input_schema: fd.parameters,
|
|
74
|
-
})),
|
|
75
|
-
tool_choice: requiredFunctionName ? { type: 'tool', name: requiredFunctionName } : { type: 'any' },
|
|
76
|
-
max_tokens: cheap ? 4096 : 8192,
|
|
77
|
-
temperature: temperature,
|
|
78
|
-
});
|
|
79
|
-
break; // Exit loop if successful
|
|
80
|
-
} catch (error) {
|
|
81
|
-
if (error.headers?.['retry-after']) {
|
|
82
|
-
let retryAfter;
|
|
83
|
-
if (error.headers['retry-after'] === '0') {
|
|
84
|
-
retryAfter = (new Date(error.headers['anthropic-ratelimit-tokens-reset']).getTime() - Date.now()) / 1000;
|
|
85
|
-
} else {
|
|
86
|
-
retryAfter = Math.max(parseInt(error.headers['retry-after'], 10), 10);
|
|
87
|
-
}
|
|
88
|
-
console.log(`Rate limited. Retrying after ${retryAfter} seconds. Attempt ${retryCount + 1} of 3.`);
|
|
89
|
-
await new Promise((resolve) => setTimeout(resolve, retryAfter * 1000));
|
|
90
|
-
retryCount++;
|
|
91
|
-
} else {
|
|
92
|
-
console.error('An error occurred:', error);
|
|
93
|
-
throw error; // Re-throw the error if it's not a rate limit error
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (retryCount === 3) {
|
|
99
|
-
console.error('Failed to complete request after 3 attempts due to rate limiting.');
|
|
100
|
-
throw new Error('Rate limit exceeded. Operation aborted.');
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Print token usage for Anthropic
|
|
104
|
-
const usage = {
|
|
105
|
-
cacheCreateTokens: response.usage.cache_creation_input_tokens,
|
|
106
|
-
cacheReadTokens: response.usage.cache_read_input_tokens,
|
|
107
|
-
inputTokens: response.usage.input_tokens,
|
|
108
|
-
outputTokens: response.usage.output_tokens,
|
|
109
|
-
totalTokens: response.usage.input_tokens + response.usage.output_tokens,
|
|
110
|
-
};
|
|
111
|
-
printTokenUsageAndCost(usage, 3 / 1000 / 1000, 15 / 1000 / 1000);
|
|
112
|
-
|
|
113
|
-
const responseMessages = response.content.filter((item) => item.type !== 'tool_use');
|
|
114
|
-
if (responseMessages.length > 0) {
|
|
115
|
-
console.log('Response messages', responseMessages);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const functionCalls = response.content
|
|
119
|
-
.filter((item) => item.type === 'tool_use')
|
|
120
|
-
.map((item) => ({
|
|
121
|
-
name: item.name,
|
|
122
|
-
args: item.input,
|
|
123
|
-
}));
|
|
124
|
-
|
|
125
|
-
return processFunctionCalls(functionCalls);
|
|
126
|
-
}
|