Skip to content

Commit

Permalink
Implement multi-turn conversations for Ray Assistant (ray-project#42750)
Browse files Browse the repository at this point in the history
* Implement multi-turn conversations for Ray Assistant

* Update assistant.js
  • Loading branch information
pcmoritz authored Jan 31, 2024
1 parent 8544cdd commit 2e3f11f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions doc/source/_static/js/assistant.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ chatPopupDiv.innerHTML = `
© Copyright 2023, The Ray Team.
</div>
`
chatPopupDiv.messages = []
document.body.appendChild(chatPopupDiv);

const anchorDiv = document.getElementById('anchor');
Expand Down Expand Up @@ -118,6 +119,9 @@ function rayAssistant(event) {
// clear search bar value and change placeholder to prompt user to ask follow up question
searchBar.value = ""
searchBar.placeholder = "Ask follow up question here"

// Add query to the list of messages
chatPopupDiv.messages.push({"role": "user", "content": searchTerm})

let msgBlock = document.createElement('div');

Expand All @@ -134,13 +138,13 @@ function rayAssistant(event) {

async function readStream() {
try {
const response = await fetch('https://ray-assistant-public-bxauk.cld-kvedzwag2qa8i5bj.s.anyscaleuserdata.com/stream', {
const response = await fetch('https://ray-assistant-public-bxauk.cld-kvedzwag2qa8i5bj.s.anyscaleuserdata.com/chat', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify({query: searchTerm})
body: JSON.stringify({messages: chatPopupDiv.messages})
});
const reader = response.body.getReader();
let decoder = new TextDecoder('utf-8');
Expand All @@ -164,6 +168,7 @@ function rayAssistant(event) {
msgContent.innerHTML = html;
highlightCode();
}
chatPopupDiv.messages.push({"role": "assistant", "content": collectChunks})
// we want to autoscroll to the bottom of the chat container after the answer is streamed in
chatContainerDiv.scrollTo(0, chatContainerDiv.scrollHeight);
} catch (error) {
Expand Down

0 comments on commit 2e3f11f

Please sign in to comment.