Public
Back
Version 4
10/23/2023
import { getModelBuilder } from "https://esm.town/v/webup/getModelBuilder";
export async function getMemoryBuilder(spec: {
type: "buffer" | "summary" | "vector";
provider?: "openai";
} = { type: "buffer" }, options = {}) {
const { cond, matches } = await import("npm:lodash-es");
const setup = cond([
[
matches({ type: "buffer" }),
async () => {
const { BufferMemory } = await import("npm:langchain/memory");
return new BufferMemory();
},
],
[
matches({ type: "summary", provider: "openai" }),
async () => {
const { ConversationSummaryMemory } = await import(
"npm:langchain/memory"
);
const builder = await getModelBuilder();
const llm = await builder();
return new ConversationSummaryMemory({ llm, ...options });
},
],
[
matches({ type: "vector", provider: "openai" }),
async () => {
const { VectorStoreRetrieverMemory } = await import(
"npm:langchain/memory"
);
const { MemoryVectorStore } = await import(
"npm:langchain/vectorstores/memory"
);
const builder = await getModelBuilder({
Updated: October 23, 2023