wuhp commited on
Commit
0c8f4b5
·
verified ·
1 Parent(s): a94ab0e

Update services/geminiService.ts

Browse files
Files changed (1) hide show
  1. services/geminiService.ts +11 -6
services/geminiService.ts CHANGED
@@ -664,7 +664,7 @@ export const generateCodeWithAgents = async (
664
  promptText: string,
665
  onStatusUpdate: (status: AgentStatus, log: string) => void,
666
  model: string = DEFAULT_MODEL
667
- ): Promise<{ code: string, evaluation?: any, initialPatches?: any }> => {
668
  const ai = getAiClient();
669
 
670
  const irRepresentation = JSON.stringify({ nodes, edges });
@@ -768,15 +768,20 @@ Return ONLY the final Python code. No markdown backticks.`;
768
  const evaluation = await evaluateCode(promptText, irRepresentation, finalCode, model);
769
 
770
  let initialPatches = null;
 
771
  if (evaluation.score < 90 && evaluation.improvement_tasks.length > 0) {
772
- onStatusUpdate('refiner', 'Applying automated improvements based on evaluation...');
773
- const patchResult = await generateCodePatches(finalCode, evaluation.improvement_tasks.join("\n"), model);
774
- finalCode = applyPatches(finalCode, patchResult.patches);
775
- initialPatches = patchResult;
 
 
 
 
776
  }
777
 
778
  onStatusUpdate('complete', 'Code generation complete!');
779
- return { code: finalCode, evaluation, initialPatches };
780
  } catch(e) {
781
  throw new Error("Polisher agent failed to generate code.");
782
  }
 
664
  promptText: string,
665
  onStatusUpdate: (status: AgentStatus, log: string) => void,
666
  model: string = DEFAULT_MODEL
667
+ ): Promise<{ code: string, evaluation?: any, initialPatches?: any, autoFixError?: string | null }> => {
668
  const ai = getAiClient();
669
 
670
  const irRepresentation = JSON.stringify({ nodes, edges });
 
768
  const evaluation = await evaluateCode(promptText, irRepresentation, finalCode, model);
769
 
770
  let initialPatches = null;
771
+ let autoFixError = null;
772
  if (evaluation.score < 90 && evaluation.improvement_tasks.length > 0) {
773
+ onStatusUpdate('patcher', 'Applying automated improvements based on evaluation...');
774
+ try {
775
+ const patchResult = await generateCodePatches(finalCode, evaluation.improvement_tasks.join("\n"), model);
776
+ finalCode = applyPatches(finalCode, patchResult.patches);
777
+ initialPatches = patchResult;
778
+ } catch(e: any) {
779
+ autoFixError = e.message || "Failed to generate or apply patches.";
780
+ }
781
  }
782
 
783
  onStatusUpdate('complete', 'Code generation complete!');
784
+ return { code: finalCode, evaluation, initialPatches, autoFixError };
785
  } catch(e) {
786
  throw new Error("Polisher agent failed to generate code.");
787
  }