Skip to content

Instantly share code, notes, and snippets.

@Juraj-Sulimanovic
Created April 5, 2024 10:36
Show Gist options
  • Save Juraj-Sulimanovic/bb05efc313c3b836cf9c52065b1219ef to your computer and use it in GitHub Desktop.
Save Juraj-Sulimanovic/bb05efc313c3b836cf9c52065b1219ef to your computer and use it in GitHub Desktop.
try {
const response = await fetch('/api/chat', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
question,
history,
}),
});
const data = await response.json();
setMessageState((state) => ({
...state,
messages: [
...state.messages,
{
type: 'apiMessage',
message: data.text,
sourceDocs: data.sourceDocuments,
},
],
history: [...state.history, [question, data.text]],
}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment