Skip to content

Commit

Permalink
add full text context for chat feature
Browse files Browse the repository at this point in the history
  • Loading branch information
do-me committed Mar 4, 2024
1 parent 34bb5e8 commit d97cf5d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
13 changes: 5 additions & 8 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -707,26 +707,23 @@ <h4>Dimensionality Reduction (New🔥) </h4>
<div>
<hr />
<h4>Chat (Retrieval Augmented Generation, RAG)</h4>
<p>Enter a question to be answered. The model is automatically prompted with the top search
results in the form: <br><b>"Based on the following input, answer the question: [your
question] [top search results]"</b>.<br> If you encounter errors, the input is probably
<p>Enter a question to be answered and use the placeholders <b>SEARCH_RESULTS</b> or <b>FULL_TEXT</b> for context.<br> If you encounter errors, the input is probably
too long (either too many or too
long results or too long prompt). Also, make
sure to check the right prompting style! Xenova/LaMini-Flan-T5-783M is by far the best
sure to check the right prompting style! Xenova/Qwen1.5-1.8B-Chat is by far the best
quantized
model currently available and delivers good results while the others produce nonsense in
most cases. At some point <a href="https://github.com/xenova/transformers.js/pull/379"
model currently available and delivers good results. At some point <a href="https://github.com/xenova/transformers.js/pull/379"
target="_blank">Falcon & Mistral/Zephyr models</a> will probably become available
here.<br><b>Attention</b>: Loads very large models with
more than 1.5Gb (!) of resources.</p>
<div class="form-floating input-group mb-2">
<input id="chat_query" class="form-control"
value="What do these paragraphs have in common?">
value="Based on the following context, answer the question: What do these paragraphs have in common? Context: SEARCH_RESULTS">
<label for="query-text">Chat Query</label>
</div>

<div class="d-flex flex-row">
<button id="get_chat" class="btn btn-md btn-primary mb-2 nav-button" disabled>💬 Chat</button>
<button id="get_chat" class="btn btn-md btn-primary mb-2 nav-button">💬 Chat</button>
<div class="row">
<div class="col-md-8">
<div class="form-floating mb-2">
Expand Down
18 changes: 13 additions & 5 deletions src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,12 +506,20 @@ async function summarizeTopResults() {
}

async function chatTopResults() {
document.getElementById("chat_text").innerHTML = "";
var chatQuery = "Based on the following input, answer the question:" + document.getElementById("chat_query").value;
var max_new_tokens = document.getElementById("chat_max_new_tokens").value;
document.getElementById("chat_text").innerHTML = ""; // progress bar

var topResultsString = chatQuery + " Context:\nParagraph: " + Array.from(document.querySelectorAll('#results-list .card-title')).map(title => title.textContent).join('\nParagraph: ');
const currentChat = await chatText(topResultsString, max_new_tokens);
const chatQuery = document.getElementById("chat_query").value;
const search_results = "\nParagraph: " + Array.from(document.querySelectorAll('#results-list .card-title')).map(title => title.textContent).join('\nParagraph: ');
const full_text = editor.getValue()

const finalQuery = chatQuery.replace("SEARCH_RESULTS", `"""${search_results}"""`).replace("FULL_TEXT",`"""${full_text}"""`) // add variables in string
console.log(finalQuery)
if (finalQuery.length > 10000){
alert("Attention: Context might be too large (> 10.000 chars) and require too much RAM to be processed. Try working with fewer results or shorter chunks.")
}

var max_new_tokens = document.getElementById("chat_max_new_tokens").value;
const currentChat = await chatText(finalQuery, max_new_tokens);
}

function resetMetadata() {
Expand Down

0 comments on commit d97cf5d

Please sign in to comment.