langchain-ai / langchain-nextjs-template

LangChain + Next.js starter template
https://langchain-nextjs-template.vercel.app
MIT License
1.43k stars 306 forks source link

Source does not return in UTF-8 #20

Closed felipeotarola closed 8 months ago

felipeotarola commented 9 months ago

the text that are displayed as source is not rendered in UTF8 All of the rest of the text is correctly formatted,

image

I have added "Content-Type": "application/json; charset=utf-8", to the StreamingTextResponse in retrival/route but that didn't help,

Any ideas?

jacoblee93 commented 8 months ago

I think doing this on the frontend may fix it?

https://stackoverflow.com/a/40929309

AlexBSoft commented 8 months ago

To fix that at components/ChatWindow.tsx line 45 you need to replace atob(sourcesHeader) with (Buffer.from(sourcesHeader, 'base64')).toString('utf8')

The problem with atob function

jacoblee93 commented 8 months ago

Would you be up for opening a PR?

felipeotarola commented 8 months ago

@AlexBSoft Perfect, this was a nice solution, I build an entire function lto make it work :D.

function base64Decode(str:any) { return decodeURIComponent(Array.prototype.map.call(atob(str), function(c) { return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); }).join('')); }