@nomyx/assistant
Version:
A powerful assistant library and cli for your AI projects. works with Vertex AI (Claude and Gemini)
30 lines (24 loc) • 802 B
text/typescript
import { ProviderResponse } from '../../../types/chat';
import { VertexCacheKey } from './types';
export class VertexCache {
private cache: Map<string, ProviderResponse> = new Map();
set(key: VertexCacheKey, value: ProviderResponse): void {
this.cache.set(this.stringifyKey(key), value);
}
get(key: VertexCacheKey): ProviderResponse | undefined {
return this.cache.get(this.stringifyKey(key));
}
has(key: VertexCacheKey): boolean {
return this.cache.has(this.stringifyKey(key));
}
clear(): void {
this.cache.clear();
}
private stringifyKey(key: VertexCacheKey): string {
return JSON.stringify({
messages: key.messages.map(m => ({ role: m.role, content: m.content })),
options: key.options,
tools: key.tools?.map(t => t.name)
});
}
}