UNPKG

@nomyx/assistant

Version:

A powerful assistant library and cli for your AI projects. works with Vertex AI (Claude and Gemini)

30 lines (24 loc) 826 B
import { ProviderResponse } from '../../../types/chat'; import { OpenRouterCacheKey } from './types'; export class OpenRouterCache { private cache: Map<string, ProviderResponse> = new Map(); set(key: OpenRouterCacheKey, value: ProviderResponse): void { this.cache.set(this.stringifyKey(key), value); } get(key: OpenRouterCacheKey): ProviderResponse | undefined { return this.cache.get(this.stringifyKey(key)); } has(key: OpenRouterCacheKey): boolean { return this.cache.has(this.stringifyKey(key)); } clear(): void { this.cache.clear(); } private stringifyKey(key: OpenRouterCacheKey): 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) }); } }