-
Notifications
You must be signed in to change notification settings - Fork 2
feat: implement cache on getPrompt and getPromptById methods #86
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
Changes from 1 commit
b3828dd
e2706f0
15c1428
9625e9f
bbe697e
fc9888a
0460dc4
3dab603
f1902e7
b03d76d
d2b3b53
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 | ||||
---|---|---|---|---|---|---|
|
@@ -340,10 +340,14 @@ export class SharedCache { | |||||
return SharedCache.instance; | ||||||
} | ||||||
|
||||||
public getPromptCacheKey(id: string, name: string, version: number): string { | ||||||
public getPromptCacheKey( | ||||||
id?: string, | ||||||
name?: string, | ||||||
version?: number | ||||||
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. When handling only optional params in js it's recommended to use an object because it's not great ux to do: instance.getPromptCacheKey(undefined, undefined, version)
// vs
instance.getPromptCacheKey({ version }) 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. now I understand why auto-complete suggested a object thx |
||||||
): string { | ||||||
if (id) { | ||||||
return id; | ||||||
} else if (name && version) { | ||||||
} else if (name && (version || version === 0)) { | ||||||
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. There is actually a way to do that explicitly:
Suggested change
|
||||||
return `${name}:${version}`; | ||||||
} else if (name) { | ||||||
return name; | ||||||
|
@@ -357,8 +361,12 @@ export class SharedCache { | |||||
|
||||||
public putPrompt(prompt: Prompt): void { | ||||||
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. Same here |
||||||
this.put(prompt.id, prompt); | ||||||
this.put(prompt.name, prompt.id); | ||||||
this.put(`${prompt.name}-${prompt.version}`, prompt.id); | ||||||
this.put(prompt.name, prompt); | ||||||
this.put(`${prompt.name}:${prompt.version}`, prompt); | ||||||
} | ||||||
|
||||||
public getCache(): Map<string, any> { | ||||||
return this.cache; | ||||||
} | ||||||
|
||||||
public get(key: string): any { | ||||||
|
@@ -2226,6 +2234,8 @@ export class API { | |||||
this.cache.putPrompt(prompt); | ||||||
return prompt; | ||||||
} catch (error) { | ||||||
console.log('key: ', this.cache.getPromptCacheKey(id, name, version)); | ||||||
console.log('cachedPrompt: ', cachedPrompt); | ||||||
return cachedPrompt; | ||||||
} | ||||||
} | ||||||
|
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.
Now that the cache is not prompt only, let's not leak that business logic in the cache layer.