Skip to content

Commit 19affcf

Browse files
fix(data): Regenerated the missing responses from the cache for cas 2 using new fetch action of cache.mjs
1 parent dacfd8f commit 19affcf

5 files changed

Lines changed: 72 additions & 391 deletions

File tree

app/cached-inference-engine.mjs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export default class CachedInferenceEngine extends InferenceEngine {
44
constructor(config = {}) {
55
super(config)
66
this.cache = {}
7+
this.cacheUrl = null
78
}
89

910
async loadCache(url) {
@@ -26,9 +27,24 @@ export default class CachedInferenceEngine extends InferenceEngine {
2627
ret = await response.json()
2728
}
2829
this.cache = ret
30+
this.cacheUrl = url
2931
return ret
3032
}
3133

34+
async saveCache() {
35+
const url = this.cacheUrl
36+
const isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null
37+
const urlStr = typeof url === 'string' ? url : url.href
38+
if (isNode) {
39+
if (!urlStr.startsWith('http:') && !urlStr.startsWith('https:')) {
40+
const { writeFileSync } = await import('node:fs')
41+
const { fileURLToPath } = await import('node:url')
42+
const filePath = urlStr.startsWith('file:') ? fileURLToPath(urlStr) : urlStr
43+
writeFileSync(filePath, JSON.stringify(this.cache))
44+
}
45+
}
46+
}
47+
3248
getCache() {
3349
return this.cache
3450
}
@@ -58,7 +74,7 @@ export default class CachedInferenceEngine extends InferenceEngine {
5874

5975
getCachedResponse(prompt) {
6076
let key = CachedInferenceEngine.hash(`${this.model}-${prompt}`)
61-
console.log(key, prompt)
77+
// console.log(key, prompt)
6278
return this.cache[key] ?? null
6379
}
6480

0 commit comments

Comments
 (0)