langchainjs
langchainjs copied to clipboard
Network Error in `ConversationChain`
I'm getting the following axios
error when calling my ConversationChain
Error
"Error: Network Error\n at createError (webpack-internal:///(api)/./node_modules/langchain/dist/util/axios-fetch-adapter.js:316:19)\n at getResponse (webpack-internal:///(api)/./node_modules/langchain/dist/util/axios-fetch-adapter.js:197:16)\n at async fetchAdapter (webpack-internal:///(api)/./node_modules/langchain/dist/util/axios-fetch-adapter.js:174:18)"
Implementation
const history = messages.map(({ agent, message }) =>
agent === "ai" ? new AIChatMessage(message) : new HumanChatMessage(message)
);
const memory = new BufferMemory({
memoryKey: "history",
chatHistory: new ChatMessageHistory(history),
returnMessages: true,
});
const llm = new ChatOpenAI({
temperature: 0,
});
const prompt = ChatPromptTemplate.fromPromptMessages([
SystemMessagePromptTemplate.fromTemplate(
DEFAULT_PROMPT_TEMPLATE
),
new MessagesPlaceholder("history"),
HumanMessagePromptTemplate.fromTemplate("{message}"),
]);
const chain = new ConversationChain({
memory,
prompt,
llm,
});
try {
response.status(200).json({
success: true,
data: await chain.call({
message,
}),
agent: "ai",
});
} catch (error) {
console.log(error);
response.status(500).json({ success: false, error });
}