Open brianangulo opened 1 month ago
I just ran into this as well. There seems to be two issue with the nlbridge express middleware.
role
value assistant
is not recognized as valid in https://github.com/nlkitai/nlbridge/blob/c4f41bb5de0c66937e1a9473f78a725c02dce0df/packages/node/express/src/express/validators/chat/isValidConversationHistory.ts#L14. For now to get around this I added an express middleware before the nlbridge middleware with
router.post(
'/',
function (
req: Request<
unknown,
unknown,
{
payload: {
conversationHistory: {
role: 'ai' | 'assistant' | 'system' | 'user'
message: string | string[]
}[]
}
}
>,
_res: Response,
next: NextFunction
) {
req.body.payload = {
...req.body.payload,
conversationHistory: req.body.payload.conversationHistory.map((chat) => ({
...chat,
message: Array.isArray(chat.message) ? chat.message.join(' ') : chat.message,
role: chat.role === 'assistant' ? 'ai' : chat.role,
})),
}
next()
}
)
Unsure is this is still an issue, I ended up using my own custom adapter
Everything works fine the first request after connecting my express.js backend to your frontend as per your instructions. But whenever I enter input into the chatbox for the second time it fails due to server responding with 400.
Below is the response:
And here is the payload the front end is sending: