Skip to content

Commit

Permalink
Use LLM cache for pre-defined prompts
Browse files Browse the repository at this point in the history
Signed-off-by: Jay Wang <jay@zijie.wang>
  • Loading branch information
xiaohk committed Mar 1, 2024
1 parent 3fd55ff commit a0a9d59
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions public/data/farsight-cache.json

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion src/components/article-page/article-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,23 @@ export class FarsightArticlePage extends LitElement {
}
const prompt = promptMap[this.selectedPrompt] as string;
this.promptpadContainerElement.overridePrompt(prompt);

this.initData();
}

// ===== Custom Methods ======
initData = async () => {};
initData = async () => {
// Load the LLM response cache to make generation faster
const cacheData = (await (
await fetch(`${import.meta.env.BASE_URL}data/farsight-cache.json`)
).json()) as Record<string, string>;

for (const key in cacheData) {
if (localStorage.getItem(key) === null) {
localStorage.setItem(key, cacheData[key]);
}
}
};

// ===== Event Methods ======
/**
Expand Down
2 changes: 2 additions & 0 deletions src/components/container-lite/container-lite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,8 @@ export class FarsightContainerLite extends LitElement {
console.log('Skip text gen API call (prompt summary, cached, lite)');
}

this.summary = response;

window.setTimeout(
() => {
this.generateUseCases(response);
Expand Down
4 changes: 1 addition & 3 deletions src/components/harm-panel/envision-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,7 @@ export class EnvisionTree {
() => {
this.addAutoHarms(nodeData, response);
},
DEV_MODE
? d3.randomInt(800, 2000)()
: config.layout.treeLayout.animationDuration
DEV_MODE ? d3.randomInt(800, 3000)() : d3.randomInt(800, 3000)()
);
} else {
const message: TextGenWorkerMessage = {
Expand Down

0 comments on commit a0a9d59

Please sign in to comment.