Skip to content

Commit

Permalink
fix: move cache-fetch inside the retry-block.
Browse files Browse the repository at this point in the history
  • Loading branch information
asafkorem committed Oct 18, 2024
1 parent ec93a46 commit 24c6d76
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/actions/StepPerformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,29 @@ export class StepPerformer {

const cacheKey = this.generateCacheKey(step, previous, viewHierarchy);

if (this.cache.has(cacheKey)) {
const cachedCode = this.cache.get(cacheKey);
return this.codeEvaluator.evaluate(cachedCode, this.context);
}

const prompt = this.promptCreator.createPrompt(
step,
viewHierarchy,
isSnapshotImageAttached,
previous,
);

let code: string | undefined = undefined;

try {
const promptResult = await this.promptHandler.runPrompt(prompt, snapshot);
code = extractCodeBlock(promptResult);
if (this.cache.has(cacheKey)) {
code = this.cache.get(cacheKey);
} else {
const prompt = this.promptCreator.createPrompt(
step,
viewHierarchy,
isSnapshotImageAttached,
previous,
);

const promptResult = await this.promptHandler.runPrompt(prompt, snapshot);
code = extractCodeBlock(promptResult);

// Cache the result
this.cache.set(cacheKey, code);
this.saveCacheToFile();
this.cache.set(cacheKey, code);
this.saveCacheToFile();
}

if (!code) {
throw new Error('Failed to generate code from intent');
}

return await this.codeEvaluator.evaluate(code, this.context);
} catch (error) {
Expand Down

0 comments on commit 24c6d76

Please sign in to comment.