-
Notifications
You must be signed in to change notification settings - Fork 0
Move edit logic into open AI file #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 06-16-add_toggle_to_control_buggy_code_and_fixer_usage
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -53,12 +53,25 @@ export async function generateApp( | |||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
// Edit existing application using AI SDK | ||||||||||||||||||||||
// Helper function to merge updated files with existing files | ||||||||||||||||||||||
function mergeFiles(existingFiles: z.infer<typeof benchifyFileSchema>, updatedFiles: z.infer<typeof benchifyFileSchema>): z.infer<typeof benchifyFileSchema> { | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ Unique Path EnforcementThe output array should not contain duplicate file objects for the same
view all inputs Unit Tests// Unit Test for "Unique Path Enforcement": The output array should not contain duplicate file objects for the same `path`.
function benchify_s(s) {
return s.replace(/[^a-zA-Z0-9]/g, 'a');
}
it('benchify_s_exec_test_passing_0', () => {
const args = superjson.parse(
'{"json":[[[{"path":"H%AR_wU","content":"8ga"}],[{"path":"{&RFTuJ","content":"apply"}]]]}',
);
benchify_s(...args);
}); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ Update PrioritizationEnsure that the file objects in the output array give precedence to entries found in
view all inputs Stack Trace
|
||||||||||||||||||||||
const existingMap = new Map(existingFiles.map(file => [file.path, file])); | ||||||||||||||||||||||
|
||||||||||||||||||||||
// Apply updates | ||||||||||||||||||||||
updatedFiles.forEach(updatedFile => { | ||||||||||||||||||||||
existingMap.set(updatedFile.path, updatedFile); | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
|
||||||||||||||||||||||
return Array.from(existingMap.values()); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
// Edit existing application using AI SDK and merge results | ||||||||||||||||||||||
export async function editApp( | ||||||||||||||||||||||
existingFiles: z.infer<typeof benchifyFileSchema>, | ||||||||||||||||||||||
editInstruction: string, | ||||||||||||||||||||||
): Promise<Array<{ path: string; content: string }>> { | ||||||||||||||||||||||
): Promise<z.infer<typeof benchifyFileSchema>> { | ||||||||||||||||||||||
console.log("Editing app with instruction: ", editInstruction); | ||||||||||||||||||||||
console.log('Existing files:', existingFiles.map(f => ({ path: f.path, contentLength: f.content.length }))); | ||||||||||||||||||||||
|
||||||||||||||||||||||
try { | ||||||||||||||||||||||
const { elementStream } = streamObject({ | ||||||||||||||||||||||
|
@@ -81,11 +94,60 @@ export async function editApp( | |||||||||||||||||||||
throw new Error("Failed to generate updated files - received empty response"); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
console.log("Generated updated files: ", updatedFiles); | ||||||||||||||||||||||
console.log("Generated updated files: ", updatedFiles.map(f => ({ path: f.path, contentLength: f.content.length }))); | ||||||||||||||||||||||
|
||||||||||||||||||||||
// Merge the updated files with the existing files | ||||||||||||||||||||||
const mergedFiles = mergeFiles(existingFiles, updatedFiles); | ||||||||||||||||||||||
console.log('Final merged files:', mergedFiles.map(f => ({ path: f.path, contentLength: f.content.length }))); | ||||||||||||||||||||||
|
||||||||||||||||||||||
return updatedFiles; | ||||||||||||||||||||||
return mergedFiles; | ||||||||||||||||||||||
} catch (error) { | ||||||||||||||||||||||
console.error('Error editing app:', error); | ||||||||||||||||||||||
throw error; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
// Main function to handle both generation and editing | ||||||||||||||||||||||
export async function processAppRequest( | ||||||||||||||||||||||
description: string, | ||||||||||||||||||||||
existingFiles?: z.infer<typeof benchifyFileSchema>, | ||||||||||||||||||||||
editInstruction?: string, | ||||||||||||||||||||||
useBuggyCode: boolean = false | ||||||||||||||||||||||
): Promise<z.infer<typeof benchifyFileSchema>> { | ||||||||||||||||||||||
// Determine if this is an edit request or new generation | ||||||||||||||||||||||
if (existingFiles && editInstruction) { | ||||||||||||||||||||||
// Edit existing code (including error fixes) | ||||||||||||||||||||||
console.log('📝 Processing edit request...'); | ||||||||||||||||||||||
return await editApp(existingFiles, editInstruction); | ||||||||||||||||||||||
} else { | ||||||||||||||||||||||
// Generate new app | ||||||||||||||||||||||
console.log('🆕 Processing new generation request...'); | ||||||||||||||||||||||
if (useBuggyCode) { | ||||||||||||||||||||||
console.log('🐛 Using buggy code as requested'); | ||||||||||||||||||||||
// Return the buggy code in the expected format | ||||||||||||||||||||||
return [ | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
path: "src/App.tsx", | ||||||||||||||||||||||
content: `import React from 'react'; | ||||||||||||||||||||||
|
||||||||||||||||||||||
const App = () => { | ||||||||||||||||||||||
const message = "Hello World; // Missing closing quote | ||||||||||||||||||||||
const title = 'Welcome to my app'; | ||||||||||||||||||||||
|
||||||||||||||||||||||
return ( | ||||||||||||||||||||||
<div> | ||||||||||||||||||||||
<h1>{title}</h1> | ||||||||||||||||||||||
<p>{message}</p> | ||||||||||||||||||||||
</div> | ||||||||||||||||||||||
); | ||||||||||||||||||||||
}; | ||||||||||||||||||||||
|
||||||||||||||||||||||
export default App;` | ||||||||||||||||||||||
} | ||||||||||||||||||||||
]; | ||||||||||||||||||||||
} else { | ||||||||||||||||||||||
console.log('🤖 Calling AI to generate app...'); | ||||||||||||||||||||||
return await generateApp(description); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Output Schema Compliance
Ensure that the output array of the
mergeFiles
function conforms to thebenchifyFileSchema
.superjson.parse('{"json":[[[{"path":"pSqGaaaaa"...
view full inputview all inputs
The property-based test has passed. The
mergeFiles
function has successfully merged the provided existing and updated files, and the resulting array conforms to thebenchifyFileSchema
, ensuring that each file has 'path' and 'content' as strings. The test has validated the function's behavior with the given input arrays.Unit Tests