genaicode 0.3.0 → 0.4.2
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 +24 -7
- package/dist/ai-service/ai-studio.js +58 -9
- package/dist/ai-service/ai-studio.js.map +1 -1
- package/dist/ai-service/anthropic.js +1 -0
- package/dist/ai-service/anthropic.js.map +1 -1
- package/dist/ai-service/chat-gpt.js +4 -2
- package/dist/ai-service/chat-gpt.js.map +1 -1
- package/dist/ai-service/common.d.ts +13 -4
- package/dist/ai-service/common.js +4 -3
- package/dist/ai-service/common.js.map +1 -1
- package/dist/ai-service/common.test.js +3 -3
- package/dist/ai-service/common.test.js.map +1 -1
- package/dist/ai-service/unescape-function-call.d.ts +7 -0
- package/dist/ai-service/unescape-function-call.js +59 -0
- package/dist/ai-service/unescape-function-call.js.map +1 -0
- package/dist/ai-service/unescape-function-call.test.d.ts +1 -0
- package/dist/ai-service/unescape-function-call.test.js +18 -0
- package/dist/ai-service/unescape-function-call.test.js.map +1 -0
- package/dist/ai-service/vertex-ai-claude.js +7 -1
- package/dist/ai-service/vertex-ai-claude.js.map +1 -1
- package/dist/ai-service/vertex-ai.d.ts +0 -1
- package/dist/ai-service/vertex-ai.js +64 -14
- package/dist/ai-service/vertex-ai.js.map +1 -1
- package/dist/cli/cli-options.js +22 -2
- package/dist/cli/cli-options.js.map +1 -1
- package/dist/cli/cli-params.d.ts +6 -2
- package/dist/cli/cli-params.js +14 -10
- package/dist/cli/cli-params.js.map +1 -1
- package/dist/cli/validate-cli-params.js +11 -2
- package/dist/cli/validate-cli-params.js.map +1 -1
- package/dist/files/cache-file.d.ts +3 -0
- package/dist/files/cache-file.js +36 -0
- package/dist/files/cache-file.js.map +1 -0
- package/dist/files/read-files.d.ts +4 -1
- package/dist/files/read-files.js +5 -3
- package/dist/files/read-files.js.map +1 -1
- package/dist/files/read-files.test.js +1 -0
- package/dist/files/read-files.test.js.map +1 -1
- package/dist/files/update-files.js +1 -4
- package/dist/files/update-files.js.map +1 -1
- package/dist/main/codegen-types.d.ts +3 -4
- package/dist/main/codegen.js +17 -4
- package/dist/main/codegen.js.map +1 -1
- package/dist/main/codegen.test.d.ts +1 -0
- package/dist/main/codegen.test.js +22 -8
- package/dist/main/codegen.test.js.map +1 -1
- package/dist/main/common/content-bus-types.d.ts +5 -0
- package/dist/main/common/content-bus-types.js +4 -0
- package/dist/main/common/content-bus-types.js.map +1 -1
- package/dist/main/common/content-bus.d.ts +7 -6
- package/dist/main/common/content-bus.js +25 -11
- package/dist/main/common/content-bus.js.map +1 -1
- package/dist/main/common/cost-collector.d.ts +10 -14
- package/dist/main/common/cost-collector.js +83 -17
- package/dist/main/common/cost-collector.js.map +1 -1
- package/dist/main/interactive/codegen-interactive.test.d.ts +1 -0
- package/dist/main/interactive/codegen-interactive.test.js +3 -1
- package/dist/main/interactive/codegen-interactive.test.js.map +1 -1
- package/dist/main/interactive/codegen-worker.js +5 -2
- package/dist/main/interactive/codegen-worker.js.map +1 -1
- package/dist/main/interactive/error-handling.d.ts +0 -3
- package/dist/main/interactive/error-handling.js +0 -6
- package/dist/main/interactive/error-handling.js.map +1 -1
- package/dist/main/ui/backend/api.js +15 -3
- package/dist/main/ui/backend/api.js.map +1 -1
- package/dist/main/ui/backend/server.js +9 -6
- package/dist/main/ui/backend/server.js.map +1 -1
- package/dist/main/ui/backend/service.d.ts +4 -2
- package/dist/main/ui/backend/service.js +14 -8
- package/dist/main/ui/backend/service.js.map +1 -1
- package/dist/main/ui/frontend/assets/index-Dicb_1yw.js +779 -0
- package/dist/main/ui/frontend/index.html +1 -1
- package/dist/prompt/ai-service-fallback.js +5 -0
- package/dist/prompt/ai-service-fallback.js.map +1 -1
- package/dist/prompt/function-calling-validate.js +70 -4
- package/dist/prompt/function-calling-validate.js.map +1 -1
- package/dist/prompt/function-calling.js +11 -3
- package/dist/prompt/function-calling.js.map +1 -1
- package/dist/prompt/function-defs/ask-question-reflect.d.ts +20 -0
- package/dist/prompt/function-defs/ask-question-reflect.js +21 -0
- package/dist/prompt/function-defs/ask-question-reflect.js.map +1 -0
- package/dist/prompt/function-defs/ask-question.d.ts +22 -11
- package/dist/prompt/function-defs/ask-question.js +42 -11
- package/dist/prompt/function-defs/ask-question.js.map +1 -1
- package/dist/prompt/function-defs/codegen-summary.d.ts +3 -3
- package/dist/prompt/function-defs/codegen-summary.js +4 -4
- package/dist/prompt/function-defs/codegen-summary.js.map +1 -1
- package/dist/prompt/function-defs/optimize-context.d.ts +16 -11
- package/dist/prompt/function-defs/optimize-context.js +16 -11
- package/dist/prompt/function-defs/optimize-context.js.map +1 -1
- package/dist/prompt/function-defs/read-history.d.ts +13 -0
- package/dist/prompt/function-defs/read-history.js +14 -0
- package/dist/prompt/function-defs/read-history.js.map +1 -0
- package/dist/prompt/function-defs/set-summaries.d.ts +31 -0
- package/dist/prompt/function-defs/set-summaries.js +32 -0
- package/dist/prompt/function-defs/set-summaries.js.map +1 -0
- package/dist/prompt/function-defs/update-history.d.ts +21 -0
- package/dist/prompt/function-defs/update-history.js +22 -0
- package/dist/prompt/function-defs/update-history.js.map +1 -0
- package/dist/prompt/limits.js +2 -2
- package/dist/prompt/limits.test.js +3 -3
- package/dist/prompt/prompt-codegen.js +25 -13
- package/dist/prompt/prompt-codegen.js.map +1 -1
- package/dist/prompt/prompt-codegen.test.js +1 -1
- package/dist/prompt/prompt-codegen.test.js.map +1 -1
- package/dist/prompt/prompt-service-ask-question.test.d.ts +1 -0
- package/dist/prompt/prompt-service-ask-question.test.js +75 -9
- package/dist/prompt/prompt-service-ask-question.test.js.map +1 -1
- package/dist/prompt/prompt-service.d.ts +0 -17
- package/dist/prompt/prompt-service.js +47 -21
- package/dist/prompt/prompt-service.js.map +1 -1
- package/dist/prompt/prompt-service.test.d.ts +1 -0
- package/dist/prompt/prompt-service.test.js +41 -31
- package/dist/prompt/prompt-service.test.js.map +1 -1
- package/dist/prompt/steps/step-ask-question-handlers.d.ts +10 -0
- package/dist/prompt/steps/step-ask-question-handlers.js +265 -0
- package/dist/prompt/steps/step-ask-question-handlers.js.map +1 -0
- package/dist/prompt/steps/step-ask-question-reflect.d.ts +4 -0
- package/dist/prompt/steps/step-ask-question-reflect.js +48 -0
- package/dist/prompt/steps/step-ask-question-reflect.js.map +1 -0
- package/dist/prompt/steps/step-ask-question-types.d.ts +53 -0
- package/dist/prompt/steps/step-ask-question-types.js +2 -0
- package/dist/prompt/steps/step-ask-question-types.js.map +1 -0
- package/dist/prompt/steps/step-ask-question.d.ts +2 -2
- package/dist/prompt/steps/step-ask-question.js +65 -82
- package/dist/prompt/steps/step-ask-question.js.map +1 -1
- package/dist/prompt/steps/step-context-optimization.d.ts +1 -3
- package/dist/prompt/steps/step-context-optimization.js +120 -73
- package/dist/prompt/steps/step-context-optimization.js.map +1 -1
- package/dist/prompt/steps/step-generate-summary.d.ts +3 -0
- package/dist/prompt/steps/step-generate-summary.js +41 -0
- package/dist/prompt/steps/step-generate-summary.js.map +1 -0
- package/dist/prompt/steps/step-history-update.d.ts +5 -0
- package/dist/prompt/steps/step-history-update.js +54 -0
- package/dist/prompt/steps/step-history-update.js.map +1 -0
- package/dist/prompt/steps/step-summarization.d.ts +8 -0
- package/dist/prompt/steps/step-summarization.js +75 -0
- package/dist/prompt/steps/step-summarization.js.map +1 -0
- package/dist/prompt/steps/step-validate-recover.d.ts +2 -13
- package/dist/prompt/steps/step-validate-recover.js +3 -3
- package/dist/prompt/steps/step-validate-recover.js.map +1 -1
- package/dist/prompt/steps/step-verify-patch.d.ts +1 -2
- package/dist/prompt/steps/step-verify-patch.js +3 -10
- package/dist/prompt/steps/step-verify-patch.js.map +1 -1
- package/dist/prompt/steps/steps-types.d.ts +12 -0
- package/dist/prompt/steps/steps-utils.d.ts +7 -0
- package/dist/prompt/steps/steps-utils.js +11 -0
- package/dist/prompt/steps/steps-utils.js.map +1 -0
- package/dist/prompt/systemprompt.js +124 -12
- package/dist/prompt/systemprompt.js.map +1 -1
- package/dist/prompt/systemprompt.test.js +4 -4
- package/dist/prompt/systemprompt.test.js.map +1 -1
- package/package.json +6 -2
- package/dist/main/ui/frontend/assets/index-D9wcaSJU.js +0 -598
|
@@ -3,101 +3,140 @@ import { getSourceCode } from '../../files/read-files.js';
|
|
|
3
3
|
import { functionDefs } from '../function-calling.js';
|
|
4
4
|
import { StepResult } from './steps-types.js';
|
|
5
5
|
import { estimateTokenCount } from '../token-estimator.js';
|
|
6
|
+
import { getSummary } from './step-summarization.js';
|
|
7
|
+
import { validateAndRecoverSingleResult } from './step-validate-recover.js';
|
|
8
|
+
import { getSourceCodeResponse } from './steps-utils.js';
|
|
6
9
|
const OPTIMIZATION_PROMPT = `You're correct, we need to optimize the context for code generation. Please perform the following tasks and respond by calling the \`optimizeContext\` function with the appropriate arguments:
|
|
7
10
|
|
|
8
|
-
1. **
|
|
9
|
-
- For each file listed below, provide a **brief one-sentence summary** of its content.
|
|
10
|
-
- The summary should accurately reflect the main purpose or functionality of the file.
|
|
11
|
-
- **Use only the content provided**; do not infer or assume additional information.
|
|
12
|
-
|
|
13
|
-
2. **Relevance Rating**:
|
|
11
|
+
1. **Relevance and Token Cost Evaluation**:
|
|
14
12
|
- Rate the **relevance** of each file to the user's prompt on a scale from **0 to 1**, using the following guidelines:
|
|
15
|
-
- **0.0 – 0.
|
|
16
|
-
- **0.3 – 0.
|
|
17
|
-
- **0.
|
|
13
|
+
- **0.0 – 0.3 (Not Relevant)**: The file has no apparent connection to the user's prompt.
|
|
14
|
+
- **0.3 – 0.7 (Somewhat Relevant)**: The file has minor or indirect relevance to the prompt.
|
|
15
|
+
- **0.7 – 0.9 (Moderately Relevant)**: The file is related and could contribute to addressing the prompt.
|
|
18
16
|
- **0.9 – 1.0 (Highly Relevant)**: The file is directly related and is important for addressing the prompt.
|
|
19
17
|
- **Evaluation Criteria**:
|
|
20
18
|
- **Keyword Matching**: Does the file contain keywords or topics mentioned in the user's prompt?
|
|
21
19
|
- **Functional Alignment**: Does the file implement features or functionalities requested by the user?
|
|
22
20
|
- **Dependency**: Is the file a dependency of other relevant modules?
|
|
21
|
+
- Prioritize files with higher relevance scores, but be mindful of the total token count.
|
|
22
|
+
- Consider the cost of adding more tokens; prioritize files where the relevance justifies the token usage.
|
|
23
|
+
|
|
24
|
+
2. **Token-Aware Optimization**:
|
|
25
|
+
- Aim to optimize the context: less relevant files with higher token count should not be added to the context
|
|
26
|
+
- Do not add irrelevant files to context
|
|
27
|
+
- The goal is to have as much as possible of high relevancy files in the context while keeping the total token count reasonably low
|
|
23
28
|
|
|
24
29
|
3. **Function Call Response**:
|
|
25
30
|
- Respond by **calling the \`optimizeContext\` function**.
|
|
26
31
|
- The function should have the following parameters:
|
|
27
32
|
- \`"userPrompt"\`: The user's original prompt.
|
|
28
33
|
- \`"optimizedContext"\`: An array of objects, each containing:
|
|
29
|
-
- \`"path"\`: The file path.
|
|
30
|
-
- \`"
|
|
31
|
-
- \`"
|
|
34
|
+
- \`"path"\`: The absolute file path.
|
|
35
|
+
- \`"relevance"\`: The calculated relevance score (0 to 1).
|
|
36
|
+
- \`"tokenCount"\`: The token count for the file.
|
|
37
|
+
- \`"totalTokenCount"\`: The estimated total token count for the context.
|
|
32
38
|
|
|
33
39
|
**Important Guidelines**:
|
|
34
|
-
|
|
35
|
-
- **Do not
|
|
36
|
-
- **
|
|
40
|
+
- **Only include files that are mentioned in \`getSourceCode\` function responses**. **Do not add any other files**.
|
|
41
|
+
- **Do not infer or guess additional files**.
|
|
42
|
+
- **Evaluate each file individually** based on the criteria above.
|
|
37
43
|
- **Avoid assumptions or hallucinations**; stick strictly to the provided data.
|
|
38
44
|
- Ensure the **function call is properly formatted** and **valid**.
|
|
39
45
|
- **Provide the response in valid JSON format**.
|
|
40
46
|
- **Do not include any extra text** outside of the function call.
|
|
41
|
-
- **Ensure the JSON is properly formatted** and **does not contain strings representing JSON** (i.e., do not stringify the JSON).
|
|
47
|
+
- **Ensure the JSON is properly formatted** and **does not contain strings representing JSON** (i.e., do not stringify the JSON, do not wrap strings into quotes).
|
|
48
|
+
- **Do not return files which are not relevant to the user prompt. Use relevance rating to judge that**
|
|
42
49
|
|
|
43
|
-
**Example Function Call**:
|
|
50
|
+
**Example of valid Function Call**:
|
|
44
51
|
|
|
45
52
|
\`\`\`json
|
|
46
53
|
{
|
|
47
54
|
"function": "optimizeContext",
|
|
48
55
|
"arguments": {
|
|
56
|
+
"userPrompt": "Please review the helper modules.",
|
|
57
|
+
"totalTokenCount": 800,
|
|
49
58
|
"optimizedContext": [
|
|
50
59
|
{
|
|
51
|
-
"path": "src/utils/helpers.js",
|
|
52
|
-
"
|
|
53
|
-
"
|
|
60
|
+
"path": "/home/src/utils/helpers.js",
|
|
61
|
+
"relevance": 0.9,
|
|
62
|
+
"tokenCount": 500
|
|
54
63
|
},
|
|
55
64
|
{
|
|
56
|
-
"path": "src/
|
|
57
|
-
"
|
|
58
|
-
"
|
|
65
|
+
"path": "/home/src/utils/math.js",
|
|
66
|
+
"relevance": 0.8,
|
|
67
|
+
"tokenCount": 300
|
|
59
68
|
}
|
|
60
69
|
]
|
|
61
70
|
}
|
|
62
71
|
}
|
|
63
72
|
\`\`\`
|
|
64
73
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
Now could you please analyze the source code and return me the optimized context?
|
|
75
|
+
`;
|
|
76
|
+
const BATCH_SIZE = 100;
|
|
77
|
+
const MAX_TOTAL_TOKENS = 10000;
|
|
78
|
+
export async function executeStepContextOptimization(generateContentFn, prompt, options) {
|
|
79
|
+
const fullSourceCode = getSourceCode({ forceAll: true }, options);
|
|
80
|
+
const sourceCodeResponse = getSourceCodeResponse(prompt);
|
|
81
|
+
if (!sourceCodeResponse || !sourceCodeResponse.content) {
|
|
82
|
+
console.warn('Could not find source code response, something is wrong, but lets continue anyway.');
|
|
83
|
+
return StepResult.CONTINUE;
|
|
84
|
+
}
|
|
85
|
+
const sourceCode = JSON.parse(sourceCodeResponse.content);
|
|
86
|
+
const sourceCodeEntries = Object.entries(sourceCode);
|
|
87
|
+
// Lets remove source code from the context, because we will be providing it below, so lets not duplicate (and save some tokens)
|
|
88
|
+
const sourceCodeResponseContent = sourceCodeResponse.content;
|
|
89
|
+
sourceCodeResponse.content = '{}';
|
|
80
90
|
try {
|
|
81
91
|
putSystemMessage('Context optimization is starting');
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
92
|
+
const totalFiles = sourceCodeEntries.length;
|
|
93
|
+
const batchCount = Math.ceil(totalFiles / BATCH_SIZE);
|
|
94
|
+
const optimizedContext = new Set();
|
|
95
|
+
for (let batchIndex = 0; batchIndex < batchCount; batchIndex++) {
|
|
96
|
+
const start = batchIndex * BATCH_SIZE;
|
|
97
|
+
const end = Math.min((batchIndex + 1) * BATCH_SIZE, totalFiles);
|
|
98
|
+
const batchSourceCode = Object.fromEntries(sourceCodeEntries.filter(([path], index) => optimizedContext.has(path) || (index >= start && index <= end)));
|
|
99
|
+
const optimizationPrompt = [
|
|
100
|
+
...prompt,
|
|
101
|
+
{
|
|
102
|
+
type: 'assistant',
|
|
103
|
+
text: 'Thank you for describing the task, I have noticed you have provided a very large context for your question. The amount of source code is very big in particular. Can we do something about it?',
|
|
104
|
+
functionCalls: [
|
|
105
|
+
{ id: 'get_batch_source', name: 'getSourceCode', args: { filePaths: Object.keys(batchSourceCode) } },
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
type: 'user',
|
|
110
|
+
text: OPTIMIZATION_PROMPT,
|
|
111
|
+
functionResponses: [
|
|
112
|
+
{ call_id: 'get_batch_source', name: 'getSourceCode', content: JSON.stringify(batchSourceCode) },
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
];
|
|
116
|
+
const request = [optimizationPrompt, functionDefs, 'optimizeContext', 0.2, true, options];
|
|
117
|
+
let result = await generateContentFn(...request);
|
|
118
|
+
result = await validateAndRecoverSingleResult(request, result, generateContentFn);
|
|
119
|
+
const batchOptimized = parseOptimizationResult(result);
|
|
120
|
+
if (!batchOptimized) {
|
|
121
|
+
putSystemMessage(`Warning: Context optimization failed to produce useful summaries for batch ${batchIndex + 1}. We need to abort.`);
|
|
122
|
+
return StepResult.BREAK;
|
|
123
|
+
}
|
|
124
|
+
optimizedContext.clear();
|
|
125
|
+
batchOptimized.forEach((path) => optimizedContext.add(path));
|
|
126
|
+
}
|
|
127
|
+
if (optimizedContext.size === 0) {
|
|
128
|
+
// Restore the original context
|
|
129
|
+
sourceCodeResponse.content = sourceCodeResponseContent;
|
|
130
|
+
putSystemMessage('Warning: Context optimization failed to produce useful summaries for all batches. Proceeding with current context.');
|
|
86
131
|
return StepResult.CONTINUE;
|
|
87
132
|
}
|
|
88
|
-
const tokensBefore = estimateTokenCount(JSON.stringify(
|
|
89
|
-
putSystemMessage('Context optimization in progress.',
|
|
90
|
-
const optimizedSourceCode = optimizeSourceCode(sourceCode,
|
|
133
|
+
const tokensBefore = estimateTokenCount(JSON.stringify(fullSourceCode));
|
|
134
|
+
putSystemMessage('Context optimization in progress.', Array.from(optimizedContext));
|
|
135
|
+
const optimizedSourceCode = optimizeSourceCode(sourceCode, fullSourceCode, Array.from(optimizedContext));
|
|
91
136
|
const tokensAfter = estimateTokenCount(JSON.stringify(optimizedSourceCode));
|
|
92
137
|
const percentageReduced = ((tokensBefore - tokensAfter) / tokensBefore) * 100;
|
|
93
138
|
// Update the getSourceCode function response in the prompt
|
|
94
|
-
|
|
95
|
-
if (getSourceCodeResponse && getSourceCodeResponse.functionResponses) {
|
|
96
|
-
const sourceCodeResponseIndex = getSourceCodeResponse.functionResponses.findIndex((resp) => resp.name === 'getSourceCode');
|
|
97
|
-
if (sourceCodeResponseIndex !== -1) {
|
|
98
|
-
getSourceCodeResponse.functionResponses[sourceCodeResponseIndex].content = JSON.stringify(optimizedSourceCode);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
139
|
+
sourceCodeResponse.content = JSON.stringify(optimizedSourceCode);
|
|
101
140
|
putSystemMessage('Context optimization completed successfully.', {
|
|
102
141
|
tokensBefore,
|
|
103
142
|
tokensAfter,
|
|
@@ -106,39 +145,47 @@ export async function executeStepContextOptimization(generateContentFn, prompt,
|
|
|
106
145
|
return StepResult.CONTINUE;
|
|
107
146
|
}
|
|
108
147
|
catch (error) {
|
|
109
|
-
putSystemMessage('
|
|
148
|
+
putSystemMessage('Error: Context optimization failed. This is unexpected.');
|
|
110
149
|
console.error('Context optimization error:', error);
|
|
111
|
-
return StepResult.
|
|
150
|
+
return StepResult.BREAK;
|
|
112
151
|
}
|
|
113
152
|
}
|
|
114
|
-
function parseOptimizationResult(
|
|
115
|
-
const
|
|
116
|
-
if (!
|
|
153
|
+
function parseOptimizationResult(calls) {
|
|
154
|
+
const optimizeCall = calls.find((call) => call.name === 'optimizeContext');
|
|
155
|
+
if (!optimizeCall || !optimizeCall.args || !optimizeCall.args.optimizedContext) {
|
|
117
156
|
return null;
|
|
118
157
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
158
|
+
let totalTokens = 0;
|
|
159
|
+
const result = [];
|
|
160
|
+
for (const item of optimizeCall.args.optimizedContext.sort((a, b) => (a.relevance > b.relevance ? -1 : 1))) {
|
|
161
|
+
if (item.relevance < 0.5) {
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
totalTokens += item.tokenCount;
|
|
165
|
+
result.push(item.filePath);
|
|
166
|
+
if (totalTokens > MAX_TOTAL_TOKENS && item.relevance < 0.7) {
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
125
169
|
}
|
|
170
|
+
return result;
|
|
126
171
|
}
|
|
127
|
-
function optimizeSourceCode(sourceCode, fullSourceCode,
|
|
172
|
+
function optimizeSourceCode(sourceCode, fullSourceCode, optimizedContext) {
|
|
128
173
|
const optimizedSourceCode = {};
|
|
129
|
-
for (const [path
|
|
130
|
-
const
|
|
131
|
-
|
|
174
|
+
for (const [path] of Object.entries(sourceCode)) {
|
|
175
|
+
const isContext = optimizedContext.includes(path);
|
|
176
|
+
const summary = getSummary(path);
|
|
177
|
+
if (isContext) {
|
|
132
178
|
optimizedSourceCode[path] = {
|
|
133
|
-
|
|
134
|
-
|
|
179
|
+
content: ('content' in fullSourceCode[path] ? fullSourceCode[path]?.content : undefined) ?? null,
|
|
180
|
+
...summary,
|
|
135
181
|
};
|
|
136
182
|
}
|
|
137
183
|
else {
|
|
138
|
-
optimizedSourceCode[path] =
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
184
|
+
optimizedSourceCode[path] = summary
|
|
185
|
+
? { ...summary }
|
|
186
|
+
: {
|
|
187
|
+
content: null,
|
|
188
|
+
};
|
|
142
189
|
}
|
|
143
190
|
}
|
|
144
191
|
return optimizedSourceCode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"step-context-optimization.js","sourceRoot":"","sources":["../../../src/prompt/steps/step-context-optimization.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAiB,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"step-context-optimization.js","sourceRoot":"","sources":["../../../src/prompt/steps/step-context-optimization.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAiB,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,C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MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAE3B,IAAI,WAAW,GAAG,gBAAgB,IAAI,IAAI,CAAC,SAAS,GAAG,GAAG,EAAE,CAAC;YAC3D,MAAM;QACR,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,kBAAkB,CACzB,UAAyB,EACzB,cAA6B,EAC7B,gBAA0B;IAE1B,MAAM,mBAAmB,GAAkB,EAAE,CAAC;IAE9C,KAAK,MAAM,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAChD,MAAM,SAAS,GAAG,gBAAgB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAClD,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,SAAS,EAAE,CAAC;YACd,mBAAmB,CAAC,IAAI,CAAC,GAAG;gBAC1B,OAAO,EAAE,CAAC,SAAS,IAAI,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,IAAI;gBAChG,GAAG,OAAO;aACX,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,mBAAmB,CAAC,IAAI,CAAC,GAAG,OAAO;gBACjC,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE;gBAChB,CAAC,CAAC;oBACE,OAAO,EAAE,IAAI;iBACd,CAAC;QACR,CAAC;IACH,CAAC;IAED,OAAO,mBAAmB,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { GenerateContentFunction, PromptItem } from '../../ai-service/common.js';
|
|
2
|
+
import { CodegenOptions } from '../../main/codegen-types.js';
|
|
3
|
+
export declare function executeStepGenerateSummary(generateContentFn: GenerateContentFunction, prompt: PromptItem[], options: CodegenOptions): Promise<void>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { putSystemMessage } from '../../main/common/content-bus.js';
|
|
2
|
+
import { functionDefs } from '../function-calling.js';
|
|
3
|
+
import { ChatMessageFlags } from '../../main/common/content-bus-types.js';
|
|
4
|
+
export async function executeStepGenerateSummary(generateContentFn, prompt, options) {
|
|
5
|
+
if (!options.conversationSummaryEnabled) {
|
|
6
|
+
console.log("Not generating conversation summary because it's disabled in options.");
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const summaryRequest = [
|
|
10
|
+
[
|
|
11
|
+
...prompt,
|
|
12
|
+
{ type: 'assistant', text: 'Thank you for explaining the task.' },
|
|
13
|
+
{
|
|
14
|
+
type: 'user',
|
|
15
|
+
text: `Now please summarize our conversation, I want maximum 1 sentence of maximum 10 words explaning the conversation.`,
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
functionDefs,
|
|
19
|
+
'explanation',
|
|
20
|
+
0.3, // Use a lower temperature for more focused summaries
|
|
21
|
+
true, // Use cheap model by default for summaries
|
|
22
|
+
options,
|
|
23
|
+
];
|
|
24
|
+
try {
|
|
25
|
+
const summaryResult = await generateContentFn(...summaryRequest);
|
|
26
|
+
const summaryExplanation = summaryResult.find((call) => call.name === 'explanation');
|
|
27
|
+
if (summaryExplanation && summaryExplanation.args && typeof summaryExplanation.args.text === 'string') {
|
|
28
|
+
const conversationSummary = summaryExplanation.args.text;
|
|
29
|
+
putSystemMessage('Generated conversation summary', conversationSummary, [ChatMessageFlags.CONVERSATION_SUMMARY]);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
throw new Error('Failed to generate summary: unexpected response format');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
console.error('Error generating conversation summary:', error);
|
|
37
|
+
putSystemMessage('Failed to generate conversation summary.');
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=step-generate-summary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step-generate-summary.js","sourceRoot":"","sources":["../../../src/prompt/steps/step-generate-summary.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAE1E,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,iBAA0C,EAC1C,MAAoB,EACpB,OAAuB;IAEvB,IAAI,CAAC,OAAO,CAAC,0BAA0B,EAAE,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,uEAAuE,CAAC,CAAC;QACrF,OAAO;IACT,CAAC;IAED,MAAM,cAAc,GAAwB;QAC1C;YACE,GAAG,MAAM;YACT,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,oCAAoC,EAAE;YACjE;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,kHAAkH;aACzH;SACF;QACD,YAAY;QACZ,aAAa;QACb,GAAG,EAAE,qDAAqD;QAC1D,IAAI,EAAE,2CAA2C;QACjD,OAAO;KACR,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,aAAa,GAAG,MAAM,iBAAiB,CAAC,GAAG,cAAc,CAAC,CAAC;QACjE,MAAM,kBAAkB,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,aAAa,CAAC,CAAC;QAErF,IAAI,kBAAkB,IAAI,kBAAkB,CAAC,IAAI,IAAI,OAAO,kBAAkB,CAAC,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACtG,MAAM,mBAAmB,GAAG,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC;YACzD,gBAAgB,CAAC,gCAAgC,EAAE,mBAAmB,EAAE,CAAC,gBAAgB,CAAC,oBAAoB,CAAC,CAAC,CAAC;QACnH,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;QAC5E,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,wCAAwC,EAAE,KAAK,CAAC,CAAC;QAC/D,gBAAgB,CAAC,0CAA0C,CAAC,CAAC;QAC7D,OAAO;IACT,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { GenerateContentFunction, PromptItem } from '../../ai-service/common.js';
|
|
2
|
+
import { CodegenOptions } from '../../main/codegen-types.js';
|
|
3
|
+
import { StepResult } from './steps-types.js';
|
|
4
|
+
export declare function executeStepHistoryUpdate(generateContentFn: GenerateContentFunction, prompt: PromptItem[], options: CodegenOptions): Promise<StepResult>;
|
|
5
|
+
export declare function getCurrentHistory(): string;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { readCache, writeCache } from '../../files/cache-file.js';
|
|
2
|
+
import { putSystemMessage } from '../../main/common/content-bus.js';
|
|
3
|
+
import { functionDefs } from '../function-calling.js';
|
|
4
|
+
import { StepResult } from './steps-types.js';
|
|
5
|
+
import { validateAndRecoverSingleResult } from './step-validate-recover.js';
|
|
6
|
+
export async function executeStepHistoryUpdate(generateContentFn, prompt, options) {
|
|
7
|
+
const currentHistory = getCurrentHistory();
|
|
8
|
+
const optimizationPrompt = [
|
|
9
|
+
...prompt,
|
|
10
|
+
{
|
|
11
|
+
type: 'assistant',
|
|
12
|
+
text: 'There you go, code generation is complete. Can I update my history?',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
type: 'user',
|
|
16
|
+
text: `Yes, please update your history.
|
|
17
|
+
|
|
18
|
+
- The current date: **${new Date().toISOString()}**.
|
|
19
|
+
- **Limits**:
|
|
20
|
+
- Up to 250 words for the conversation summary.
|
|
21
|
+
- Up to 500 words for the new history.
|
|
22
|
+
- **Compression Priority**: Include as much key information as possible, even if readability and style are sacrificed.
|
|
23
|
+
- **Content**: Combine crucial information from your current history and our recent conversation.
|
|
24
|
+
- **Output**: Use the function call \`updateHistory\` with \`recentConversationSummary\` and \`newHistoryContent\`.
|
|
25
|
+
|
|
26
|
+
**Instructions**:
|
|
27
|
+
|
|
28
|
+
1. **Compress Aggressively**: Use abbreviations, remove unnecessary words, and focus on key terms and facts.
|
|
29
|
+
2. **Retain All Key Points**: Ensure no important information from the current history or conversation is omitted.
|
|
30
|
+
3. **Ignore Readability**: It's acceptable if the result is less readable, as long as it contains more information.
|
|
31
|
+
4. **Use Compact Formats**: Consider lists, bullet points, or other formats that allow for dense information packing.
|
|
32
|
+
5. **Write for LLM**: Human will not be reading the history content directly, it must be useful for LLM.
|
|
33
|
+
|
|
34
|
+
**Current history**:
|
|
35
|
+
\`\`\`
|
|
36
|
+
${currentHistory}
|
|
37
|
+
\`\`\`
|
|
38
|
+
`,
|
|
39
|
+
},
|
|
40
|
+
];
|
|
41
|
+
const request = [optimizationPrompt, functionDefs, 'updateHistory', 1, true, options];
|
|
42
|
+
let result = await generateContentFn(...request);
|
|
43
|
+
result = await validateAndRecoverSingleResult(request, result, generateContentFn);
|
|
44
|
+
const { newHistoryContent, recentConversationSummary } = result.find((call) => call.name === 'updateHistory')?.args ?? {};
|
|
45
|
+
if (newHistoryContent) {
|
|
46
|
+
putSystemMessage('History updated', { newHistoryContent, recentConversationSummary });
|
|
47
|
+
writeCache('history', newHistoryContent);
|
|
48
|
+
}
|
|
49
|
+
return StepResult.CONTINUE;
|
|
50
|
+
}
|
|
51
|
+
export function getCurrentHistory() {
|
|
52
|
+
return readCache('history', 'The user just started using GenAIcode for their project.');
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=step-history-update.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step-history-update.js","sourceRoot":"","sources":["../../../src/prompt/steps/step-history-update.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,2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,UAAU,CAAC,QAAQ,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,OAAO,SAAS,CAAC,SAAS,EAAE,0DAA0D,CAAC,CAAC;AAC1F,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { GenerateContentFunction } from '../../ai-service/common.js';
|
|
2
|
+
import { CodegenOptions } from '../../main/codegen-types.js';
|
|
3
|
+
import { SourceCodeMap } from '../../files/read-files.js';
|
|
4
|
+
export declare function summarizeSourceCode(generateContentFn: GenerateContentFunction, sourceCode: SourceCodeMap, options: CodegenOptions): Promise<void>;
|
|
5
|
+
export declare function getSummary(filePath: string): {
|
|
6
|
+
summary: string;
|
|
7
|
+
tokenCount: number;
|
|
8
|
+
} | undefined;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { functionDefs } from '../function-calling.js';
|
|
2
|
+
import { md5, readCache, writeCache } from '../../files/cache-file.js';
|
|
3
|
+
import { putSystemMessage } from '../../main/common/content-bus.js';
|
|
4
|
+
import { estimateTokenCount } from '../token-estimator.js';
|
|
5
|
+
import { validateAndRecoverSingleResult } from './step-validate-recover.js';
|
|
6
|
+
const BATCH_SIZE = 50;
|
|
7
|
+
const MAX_SUMMARY_TOKENS = 15;
|
|
8
|
+
const CACHE_VERSION = 'v2';
|
|
9
|
+
const SUMMARIZATION_PROMPT = `Your role is to summarize content of files in ${MAX_SUMMARY_TOKENS} tokens or fewer.
|
|
10
|
+
Focus on the main purpose or functionality.
|
|
11
|
+
Provide your response using the \`setSummaries\` function.
|
|
12
|
+
The length of summary should be max ${MAX_SUMMARY_TOKENS} tokens.
|
|
13
|
+
The file path must be absolute, exactly the same as you receive in the \`getSourceCode\` function responses.
|
|
14
|
+
`;
|
|
15
|
+
const summaryCache = readCache('summaries', { _version: CACHE_VERSION });
|
|
16
|
+
export async function summarizeSourceCode(generateContentFn, sourceCode, options) {
|
|
17
|
+
const items = Object.entries(sourceCode).map(([path, file]) => ({
|
|
18
|
+
path,
|
|
19
|
+
content: 'content' in file ? file.content : null,
|
|
20
|
+
}));
|
|
21
|
+
await summarizeBatch(generateContentFn, items, options);
|
|
22
|
+
}
|
|
23
|
+
async function summarizeBatch(generateContentFn, items, options) {
|
|
24
|
+
const uncachedItems = items.filter((item) => summaryCache._version !== CACHE_VERSION ||
|
|
25
|
+
!summaryCache[item.path] ||
|
|
26
|
+
summaryCache[item.path].checksum !== md5(item.content ?? ''));
|
|
27
|
+
if (uncachedItems.length === 0) {
|
|
28
|
+
putSystemMessage('Summarization of the source code was skipped.');
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
putSystemMessage('Summarization of the source code is starting.', { files: uncachedItems.map((item) => item.path) });
|
|
32
|
+
for (let i = 0; i < uncachedItems.length; i += BATCH_SIZE) {
|
|
33
|
+
const batch = uncachedItems.slice(i, i + BATCH_SIZE);
|
|
34
|
+
const summarizationPrompt = [
|
|
35
|
+
{ type: 'systemPrompt', systemPrompt: SUMMARIZATION_PROMPT },
|
|
36
|
+
{ type: 'user', text: 'Hello, I would like to ask you to summarize my codebase' },
|
|
37
|
+
{
|
|
38
|
+
type: 'assistant',
|
|
39
|
+
text: 'Sure, could you please provide the source code? Once you provide it, I will be able to perform the analysis, and provide you with the summaries using `setSummaries` function call.',
|
|
40
|
+
functionCalls: [{ name: 'getSourceCode', id: 'get_source_code' }],
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
type: 'user',
|
|
44
|
+
text: 'Ok, this is the source code, and now please summarize the source code.',
|
|
45
|
+
functionResponses: [{ name: 'getSourceCode', call_id: 'get_source_code', content: JSON.stringify(batch) }],
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
const request = [summarizationPrompt, functionDefs, 'setSummaries', 0.2, true, options];
|
|
49
|
+
let result = await generateContentFn(...request);
|
|
50
|
+
result = await validateAndRecoverSingleResult(request, result, generateContentFn);
|
|
51
|
+
const batchSummaries = parseSummarizationResult(result);
|
|
52
|
+
batchSummaries.forEach((file) => {
|
|
53
|
+
const content = items.find((item) => item.path === file.filePath)?.content ?? '';
|
|
54
|
+
summaryCache[file.filePath] = {
|
|
55
|
+
tokenCount: estimateTokenCount(content),
|
|
56
|
+
summary: file.summary,
|
|
57
|
+
checksum: md5(content),
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
summaryCache._version = CACHE_VERSION;
|
|
62
|
+
writeCache('summaries', summaryCache);
|
|
63
|
+
putSystemMessage('Summarization of the source code is finished.');
|
|
64
|
+
}
|
|
65
|
+
function parseSummarizationResult(result) {
|
|
66
|
+
if (!Array.isArray(result) || result.length === 0 || !result[0].args || !Array.isArray(result[0].args.summaries)) {
|
|
67
|
+
throw new Error('Invalid summarization result');
|
|
68
|
+
}
|
|
69
|
+
return result[0].args.summaries;
|
|
70
|
+
}
|
|
71
|
+
export function getSummary(filePath) {
|
|
72
|
+
const summary = summaryCache[filePath];
|
|
73
|
+
return summary ? { summary: summary.summary, tokenCount: summary.tokenCount } : undefined;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=step-summarization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step-summarization.js","sourceRoot":"","sources":["../../../src/prompt/steps/step-summarization.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,8BAA8B,EAAE,MAAM,4BAA4B,CAAC;AAE5E,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAM,aAAa,GAAG,IAAI,CAAC;AAE3B,MAAM,oBAAoB,GAAG,iDAAiD,kBAA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AI,CAAC,QAAQ,CAAC,GAAG;gBAC5B,UAAU,EAAE,kBAAkB,CAAC,OAAO,CAAC;gBACvC,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC;aACvB,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED,YAAY,CAAC,QAAQ,GAAG,aAAa,CAAC;IAEtC,UAAU,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;IAEtC,gBAAgB,CAAC,+CAA+C,CAAC,CAAC;AACpE,CAAC;AAED,SAAS,wBAAwB,CAAC,MAAsB;IACtD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;QACjH,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAClD,CAAC;IACD,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,QAAgB;IACzC,MAAM,OAAO,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;IACvC,OAAO,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAC5F,CAAC"}
|
|
@@ -1,13 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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[]>;
|
|
1
|
+
import { FunctionCall, GenerateContentFunction, GenerateContentArgs } from '../../ai-service/common.js';
|
|
2
|
+
export declare function validateAndRecoverSingleResult([prompt, functionDefs, requiredFunctionName, temperature, cheap, options]: GenerateContentArgs, result: FunctionCall[], generateContentFn: GenerateContentFunction): Promise<FunctionCall[]>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import assert from 'node:assert';
|
|
2
2
|
import { validateFunctionCall } from '../function-calling-validate.js';
|
|
3
|
-
export async function validateAndRecoverSingleResult([prompt, functionDefs, requiredFunctionName, temperature, cheap, options], result,
|
|
4
|
-
if (result.length > 1) {
|
|
3
|
+
export async function validateAndRecoverSingleResult([prompt, functionDefs, requiredFunctionName, temperature, cheap, options], result, generateContentFn) {
|
|
4
|
+
if (result.length > 1 || !requiredFunctionName) {
|
|
5
5
|
// quite unexpected
|
|
6
6
|
return result;
|
|
7
7
|
}
|
|
@@ -18,7 +18,7 @@ export async function validateAndRecoverSingleResult([prompt, functionDefs, requ
|
|
|
18
18
|
}
|
|
19
19
|
prompt.push({ type: 'assistant', functionCalls: [call] }, {
|
|
20
20
|
type: 'user',
|
|
21
|
-
text:
|
|
21
|
+
text: 'Function call was invalid, please analyze the error and respond with corrected function call.',
|
|
22
22
|
functionResponses: [
|
|
23
23
|
{
|
|
24
24
|
name: call.name,
|
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"step-validate-rec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AAC,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC;oBACnE,OAAO,EAAE,IAAI;iBACd;aACF;SACF,CACF,CAAC;QAEF,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;QACpC,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,CAAC,GAAG,CAAC,iCAAiC,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"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { PromptItem, FunctionDef, FunctionCall, GenerateContentFunction } from '../../ai-service/common.js';
|
|
2
|
-
import { PromptMessages } from '../prompt-service.js';
|
|
3
2
|
import { CodegenOptions } from '../../main/codegen-types.js';
|
|
4
3
|
export declare function executeStepVerifyPatch({ filePath, patch }: {
|
|
5
4
|
filePath: string;
|
|
6
5
|
patch: string;
|
|
7
|
-
}, generateContentFn: GenerateContentFunction, prompt: PromptItem[], functionDefs: FunctionDef[], temperature: number, cheap: boolean,
|
|
6
|
+
}, generateContentFn: GenerateContentFunction, prompt: PromptItem[], functionDefs: FunctionDef[], temperature: number, cheap: boolean, options: CodegenOptions): Promise<FunctionCall[]>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import * as diff from 'diff';
|
|
3
3
|
import { validateAndRecoverSingleResult } from './step-validate-recover.js';
|
|
4
|
-
export async function executeStepVerifyPatch({ filePath, patch }, generateContentFn, prompt, functionDefs, temperature, cheap,
|
|
4
|
+
export async function executeStepVerifyPatch({ filePath, patch }, generateContentFn, prompt, functionDefs, temperature, cheap, options) {
|
|
5
5
|
console.log('Verification of patch for file:', filePath);
|
|
6
6
|
let updatedContent = false;
|
|
7
7
|
const currentContent = fs.readFileSync(filePath, 'utf-8');
|
|
@@ -14,16 +14,9 @@ export async function executeStepVerifyPatch({ filePath, patch }, generateConten
|
|
|
14
14
|
if (!updatedContent) {
|
|
15
15
|
console.log(`Patch could not be applied for ${filePath}. Retrying without patchFile function.`);
|
|
16
16
|
// Rerun content generation without patchFile function
|
|
17
|
-
const partialRequest = [
|
|
18
|
-
prompt,
|
|
19
|
-
functionDefs,
|
|
20
|
-
'updateFile',
|
|
21
|
-
temperature,
|
|
22
|
-
cheap,
|
|
23
|
-
options,
|
|
24
|
-
];
|
|
17
|
+
const partialRequest = [prompt, functionDefs, 'updateFile', temperature, cheap, options];
|
|
25
18
|
let partialResult = await generateContentFn(...partialRequest);
|
|
26
|
-
partialResult = await validateAndRecoverSingleResult(partialRequest, partialResult,
|
|
19
|
+
partialResult = await validateAndRecoverSingleResult(partialRequest, partialResult, generateContentFn);
|
|
27
20
|
const getSourceCodeCall = partialResult.find((call) => call.name === 'getSourceCode');
|
|
28
21
|
if (getSourceCodeCall) {
|
|
29
22
|
throw new Error('Unexpected getSourceCode: ' + JSON.stringify(getSourceCodeCall));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"step-verify-patch.js","sourceRoot":"","sources":["../../../src/prompt/steps/step-verify-patch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"step-verify-patch.js","sourceRoot":"","sources":["../../../src/prompt/steps/step-verify-patch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAQ7B,OAAO,EAAE,8BAA8B,EAAE,MAAM,4BAA4B,CAAC;AAG5E,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,EAAE,QAAQ,EAAE,KAAK,EAAuC,EACxD,iBAA0C,EAC1C,MAAoB,EACpB,YAA2B,EAC3B,WAAmB,EACnB,KAAc,EACd,OAAuB;IAEvB,OAAO,CAAC,GAAG,CAAC,iCAAiC,EAAE,QAAQ,CAAC,CAAC;IAEzD,IAAI,cAAc,GAAqB,KAAK,CAAC;IAC7C,MAAM,cAAc,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAE1D,IAAI,CAAC;QACH,cAAc,GAAG,IAAI,CAAC,UAAU,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IAC1D,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,GAAG,CAAC,2BAA2B,EAAE,CAAC,CAAC,CAAC;IAC9C,CAAC;IAED,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,OAAO,CAAC,GAAG,CAAC,kCAAkC,QAAQ,wCAAwC,CAAC,CAAC;QAEhG,sDAAsD;QACtD,MAAM,cAAc,GAAwB,CAAC,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QAC9G,IAAI,aAAa,GAAG,MAAM,iBAAiB,CAAC,GAAG,cAAc,CAAC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