A cache that uses Momento as the backing store. See https://gomomento.com.
const cache = new MomentoCache({
client: new CacheClient({
configuration: Configurations.Laptop.v1(),
credentialProvider: CredentialProvider.fromEnvironmentVariable({
environmentVariableName: "MOMENTO_API_KEY",
}),
defaultTtlSeconds: 60 * 60 * 24, // Cache TTL set to 24 hours.
}),
cacheName: "langchain",
});
// Initialize the OpenAI model with Momento cache for caching responses
const model = new ChatOpenAI({
model: "gpt-4o-mini",
cache,
});
await model.invoke("How are you today?");
const cachedValues = await cache.lookup("How are you today?", "llmKey");