Back
Version 0
5/31/2023
const { ChatOpenAI } = await import(
"https://esm.sh/langchain/chat_models/openai"
);
import {BufferMemory} = await import(
"https://esm.sh/langchain/memory"
)
const llm = new ChatOpenAI({
modelName: "gpt-3.5-turbo",
openAiApiKey: me.secrets.OPENAI_API_KEY,
temperature: 0,
});
const memory = new BufferMemory({
memoryKey: "chat_history"
});
const prompt = ChatPromptTemplate.fromPromptMessages([
SystemMessagePromptTemplate.fromTemplate(
`There are {vegetables}, {fruit} and {meat} sorts available for cooking, create a receipte given human input using some of these ingredients as a basis.
This is the existing menu {menu}, dishes must not include any ingredient already in the existing menu.`
),
HumanMessagePromptTemplate.fromTemplate("{prompt_content}"),
]);
const chain = new ConversationChain({ llm, memory, prompt });
const result = await chain.call({
vegetables: ["carrot", "potato", "tomato"].join(", "),
fruit: ["apple", "banana", "orange"].join(", "),
meat: ["chicken", "beef", "pork"].join(", "),
menu: ["chicken soup", "beef steak", "pork chop"].join(", "),
});
console.log({result})
Updated: October 23, 2023