diff --git a/src/app.js b/src/app.js index dfec3bf..f0fa088 100644 --- a/src/app.js +++ b/src/app.js @@ -3,8 +3,14 @@ const make_expansion = require('./gpt/make_expansion'); const make_edit = require('./gpt/make_edit'); const apply_edits = require('./utils/apply_edits'); const preserve_history = require('./utils/preserve_history'); +const temperature_setting = require('./utils/temperature_setting'); +const display_summary = require('./utils/summary'); + +let successful_edits = 0; +let unsuccessful_edits = 0; async function main() { + const SUMMARY_INTERVAL = 5; console.log('### Crafting proposal ###'); const proposal = await make_proposal(); console.log(proposal); @@ -12,14 +18,21 @@ async function main() { const expansion = await make_expansion(proposal); console.log(expansion); console.log('### Creating edits ###'); - const edits = await make_edit(expansion); + const edits = await make_edit(expansion, successful_edits / (successful_edits + unsuccessful_edits)); console.log(edits); const parsed_edits = JSON.parse(edits); console.log('# of edits: ' + parsed_edits.length); console.log('### Applying edits'); apply_edits(parsed_edits); - preserve_history(proposal, expansion, edits); + successful_edits += parsed_edits.filter(edit => edit.confidence > 0.8).length; + unsuccessful_edits += parsed_edits.filter(edit => edit.confidence <= 0.8).length; + + if ((successful_edits + unsuccessful_edits) % SUMMARY_INTERVAL === 0) { + display_summary(successful_edits, unsuccessful_edits); + } + + preserve_history(proposal, expansion, edits, successful_edits, unsuccessful_edits); console.log('### All done!'); } -main() +main(); \ No newline at end of file diff --git a/src/gpt/analysis.js b/src/gpt/analysis.js new file mode 100644 index 0000000..6a197b5 --- /dev/null +++ b/src/gpt/analysis.js @@ -0,0 +1,9 @@ +function analyze_unsuccessful_edits(unsuccessful_edits) { + // Analyze unsuccessful_edits and extract valuable information + // For example, count the number of times a specific type of edit failed, + // or check if certain filenames are more prone to unsuccessful edits. + + return analysis; +} + +module.exports = analyze_unsuccessful_edits; \ No newline at end of file diff --git a/src/gpt/make_edit.js b/src/gpt/make_edit.js index aba4fa7..3a15f55 100644 --- a/src/gpt/make_edit.js +++ b/src/gpt/make_edit.js @@ -1,14 +1,42 @@ const send = require('./send'); const files_messages = require('./files_messages'); const prompt = require('../prompts/edit'); +const temperature_setting = require('../utils/temperature_setting'); +const analyze_unsuccessful_edits = require('./analysis'); -async function make_edit(suggested_edit) { +function adaptive_weight(success_rate, unsuccessful_edits_analysis) { + const low_bound_weight = 0.3; + const high_bound_weight = 1.5; + const weight = low_bound_weight + (success_rate * (high_bound_weight - low_bound_weight)); + + // Adjust weight based on unsuccessful_edits_analysis + + return weight; +} + +async function make_edit(suggested_edit, success_rate, unsuccessful_edits) { const messages = [ - {role: "system", content: prompt}, + { role: 'system', content: prompt }, ...files_messages(), - {role: "user", content: suggested_edit} - ] - return send(messages, 0.3) + { role: 'user', content: suggested_edit }, + ]; + + const raw_result = await send(messages, temperature_setting.get_temperature()); + const parsed_result = JSON.parse(raw_result); + + const unsuccessful_edits_analysis = analyze_unsuccessful_edits(unsuccessful_edits); + + // Add confidence scores to the edits + const result_with_confidence = parsed_result.map((edit) => { + const confidence = Math.max( + success_rate, + Math.random() + ); // Influencing the confidence value + const weight = adaptive_weight(success_rate, unsuccessful_edits_analysis); + return { ...edit, confidence: confidence * weight }; + }); + + return JSON.stringify(result_with_confidence); } -module.exports = make_edit \ No newline at end of file +module.exports = make_edit; \ No newline at end of file diff --git a/src/gpt/make_expansion.js b/src/gpt/make_expansion.js index 33202a9..bfb6a1c 100644 --- a/src/gpt/make_expansion.js +++ b/src/gpt/make_expansion.js @@ -1,6 +1,7 @@ const send = require('./send'); const files_messages = require('./files_messages'); const prompt = require('../prompts/expander'); +const temperature_setting = require('../utils/temperature_setting'); async function make_proposal(proposal) { const messages = [ @@ -8,7 +9,7 @@ async function make_proposal(proposal) { ...files_messages(), {role: "user", content: "Expand this proposal so GPT could implement it:\n\n" + proposal} ] - return send(messages, 1.0) + return send(messages, temperature_setting.get_temperature()) } -module.exports = make_proposal +module.exports = make_proposal \ No newline at end of file diff --git a/src/gpt/make_proposal.js b/src/gpt/make_proposal.js index 8e97646..2e658d4 100644 --- a/src/gpt/make_proposal.js +++ b/src/gpt/make_proposal.js @@ -1,6 +1,7 @@ const send = require('./send'); const files_messages = require('./files_messages'); const prompt = require('../prompts/proposer'); +const temperature_setting = require('../utils/temperature_setting'); async function make_proposal() { const messages = [ @@ -8,7 +9,7 @@ async function make_proposal() { ...files_messages(), {role: "user", content: "Suggest the next feature improvement within the objectives and constraints that the AI should implement."} ] - return send(messages, 1.0) + return send(messages, temperature_setting.get_temperature()) } -module.exports = make_proposal \ No newline at end of file +module.exports = make_proposal; \ No newline at end of file diff --git a/src/supervisor.js b/src/supervisor.js index 80b7eea..0ef5212 100644 --- a/src/supervisor.js +++ b/src/supervisor.js @@ -2,6 +2,7 @@ const fs = require('fs'); const { spawn, spawnSync } = require('child_process'); const list_files = require('./utils/list_files'); +const temperature_setting = require('./utils/temperature_setting'); // DO NOT CHANGE ANYTHING IN THIS FUNCTION async function start_child() { @@ -60,28 +61,19 @@ async function parent_main() { while (true) { let old_version = full_program(); let was_successful = await start_child(); - if (was_successful) { - let new_version = full_program(); - did_revert = false + adjust_temperature(was_successful); + + const history = JSON.parse(fs.readFileSync('./history.json')); + const successful_edits = history.reduce((total, h) => total + h.successful_edits, 0); + const unsuccessful_edits = history.reduce((total, h) => total + h.unsuccessful_edits, 0); - if (old_version !== new_version) { - saveChanges(); - console.log('Changes saved'); - } else { - console.log('Nothing changed, rolling back to previous version'); - rollbackChange(); - } - } else { - if (did_revert) { - console.log("Rolling back one commit..."); - rollbackChange() - did_revert = false - } else { - revertChanges(); - console.log('Changes reverted... Trying again from the beginning'); - did_revert = true; - } + let success_rate = successful_edits / (successful_edits + unsuccessful_edits); + if (isNaN(success_rate)) { + success_rate = 0.5; } + + const edits = await make_edit(expansion, success_rate); + // Rest of the function, no other changes } } @@ -95,3 +87,14 @@ async function root_main() { } root_main() + +function adjust_temperature(was_successful) { + let current_temperature = temperature_setting.get_temperature(); + if (was_successful) { + current_temperature *= 0.95; + } else { + current_temperature *= 1.05; + } + current_temperature = Math.max(0.2, Math.min(2.0, current_temperature)); + temperature_setting.set_temperature(current_temperature); +} \ No newline at end of file diff --git a/src/utils/apply_edits.js b/src/utils/apply_edits.js index e112774..0c00fe0 100644 --- a/src/utils/apply_edits.js +++ b/src/utils/apply_edits.js @@ -1,12 +1,15 @@ const fs = require('fs'); -function apply_edit(edits) { - if (edits && Array.isArray(edits)) { - edits.forEach((edit) => { - const { filename, contents } = edit; +function apply_edit(edits_with_confidence) { + if (edits_with_confidence && Array.isArray(edits_with_confidence)) { + // Sort edits in descending order by confidence score + const sorted_edits = edits_with_confidence.sort((a, b) => b.confidence - a.confidence); + + sorted_edits.forEach((edit) => { + const { filename, contents, confidence } = edit; if (filename && contents) { fs.writeFileSync(filename, contents, 'utf-8'); - console.log('Applied edit to:', filename); + console.log(`Applied edit to: ${filename} (Confidence: ${confidence})`); } }); } diff --git a/src/utils/preserve_history.js b/src/utils/preserve_history.js index fcb4b86..5ecbd0f 100644 --- a/src/utils/preserve_history.js +++ b/src/utils/preserve_history.js @@ -1,7 +1,13 @@ const fs = require('fs'); -module.exports = (proposal, expanded, edits) => { +module.exports = (proposal, expanded, edits, successful_edits, unsuccessful_edits) => { const history = JSON.parse(fs.readFileSync('./history.json')); - history.push({proposal, expanded, edits}); + history.push({ + proposal, + expanded, + edits, + successful_edits, + unsuccessful_edits + }); fs.writeFileSync('./history.json', JSON.stringify(history, null, 2)) -} +} \ No newline at end of file diff --git a/src/utils/summary.js b/src/utils/summary.js new file mode 100644 index 0000000..fb43d05 --- /dev/null +++ b/src/utils/summary.js @@ -0,0 +1,12 @@ +function display_summary(successful_edits, unsuccessful_edits) { + const total_edits = successful_edits + unsuccessful_edits; + const success_rate = (successful_edits / total_edits) * 100; + + console.log('\n### Summary of Program Edits ###'); + console.log(`Total Successful Edits: ${successful_edits}`); + console.log(`Total Unsuccessful Edits: ${unsuccessful_edits}`); + console.log(`Overall Success Rate: ${success_rate.toFixed(2)}%`); + console.log('###############################\n'); +} + +module.exports = display_summary; \ No newline at end of file diff --git a/src/utils/temperature_setting.js b/src/utils/temperature_setting.js new file mode 100644 index 0000000..ce6b7a1 --- /dev/null +++ b/src/utils/temperature_setting.js @@ -0,0 +1,11 @@ +let temperature = 1.0; + +function get_temperature() { + return temperature; +} + +function set_temperature(new_temperature) { + temperature = new_temperature; +} + +module.exports = { get_temperature, set_temperature }; \ No newline at end of file