fix(web): add prompt cache affinity to canvas agent (#74)
Co-authored-by: Tiantianr <260026737+Tiantianr@users.noreply.github.com>
This commit is contained in:
1 parent
c574e2d72e
commit
e37c1114b3
4 files changed
+64
-10
No files matched your search
@@ -0,0 +1,17 @@
|
||||
export const OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH = 64;
|
||||
|
||||
export function clampOpenAIPromptCacheKey(value?: string) {
|
||||
const key = value?.trim();
|
||||
if (!key) return undefined;
|
||||
return Array.from(key).slice(0, OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH).join("");
|
||||
}
|
||||
|
||||
export function canvasAgentPromptCacheKey(sessionId: string) {
|
||||
const value = sessionId.trim();
|
||||
return value ? clampOpenAIPromptCacheKey(`canvas-agent:${value}`) : undefined;
|
||||
}
|
||||
|
||||
export function withOpenAIPromptCacheKey<T extends Record<string, unknown>>(body: T, value?: string): T & { prompt_cache_key?: string } {
|
||||
const key = clampOpenAIPromptCacheKey(value);
|
||||
return key ? { ...body, prompt_cache_key: key } : body;
|
||||
}
|
||||
Reference in new issue
Block a user