Skip to content

Commit

Permalink
add Qwen 1.5 0.5B and 1.8B
Browse files Browse the repository at this point in the history
  • Loading branch information
do-me committed Feb 22, 2024
1 parent 3e7fb9c commit a078d6a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
12 changes: 8 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,10 @@ <h6>Model Selection</h6>
Xenova/jina-embeddings-v2-base-de | 💾162Mb 📥0 ❤️0</option>
<option value="Xenova/jina-embeddings-v2-base-zh">
Xenova/jina-embeddings-v2-base-zh | 💾162Mb 📥0 ❤️0</option>
<option value="jinaai/jina-embeddings-v2-base-code">
<!--<option value="jinaai/jina-embeddings-v2-base-code">
jinaai/jina-embeddings-v2-base-code | 💾162Mb 📥0 ❤️0</option>
<option value="jinaai/jina-embeddings-v2-base-es">
jinaai/jina-embeddings-v2-base-es | 💾162Mb 📥0 ❤️0</option> --> <!-- access control inhibits direct loading from HF -->
<option value="do-me/jina-embeddings-v2-small-en">
do-me/jina-embeddings-v2-small-en (test)</option>
<option value="do-me/jina-embeddings-v2-base-en">
Expand Down Expand Up @@ -728,8 +730,10 @@ <h4>Chat (Retrieval Augmented Generation, RAG)</h4>
<div class="col-md-8">
<div class="form-floating mb-2">
<select class="form-select form-control" id="chat-model-name">
<option value="Xenova/Qwen1.5-0.5B-Chat">Xenova/Qwen1.5-0.5B-Chat</option>
<option selected value="Xenova/LaMini-Flan-T5-783M">
<option selected value="Xenova/Qwen1.5-0.5B-Chat">Xenova/Qwen1.5-0.5B-Chat (0.482Gb)</option>
<option value="Xenova/Qwen1.5-1.8B-Chat">Xenova/Qwen1.5-1.8B-Chat (1.87Gb)</option>

<option value="Xenova/LaMini-Flan-T5-783M">
Xenova/LaMini-Flan-T5-783M | 💾1.65Gb 📥17 ❤️20</option>
<option value="Xenova/t5-small">Xenova/t5-small | 💾81Mb 📥2
❤️2</option>
Expand Down Expand Up @@ -772,7 +776,7 @@ <h4>Chat (Retrieval Augmented Generation, RAG)</h4>
</div>

</div>
<p id="chat_text" class="ml-2"></p>
<div id="chat_text" class="ml-2"></div>
<!-- progress bar -->
<div class="col-12">
<div class="progress" role="progressbar" aria-label="Loading model" aria-valuenow="0"
Expand Down
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"bootstrap": "^5.3.2",
"codemirror": "^5.52.2",
"deck.gl": "^8.9.34",
"marked": "^12.0.0",
"pako": "^2.1.0",
"wasm-bhtsne": "^0.3.3"
},
Expand Down
1 change: 0 additions & 1 deletion src/js/semantic.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ let loadResolve;
*/
let queryResolve;


function downloadFile(data, filename, mimeType) {
const blob = new Blob([data], { type: mimeType });

Expand Down
18 changes: 11 additions & 7 deletions src/js/worker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { pipeline, AutoTokenizer } from '@xenova/transformers';
import pako from 'pako';
import init, { tSNE } from "wasm-bhtsne";
import { marked } from 'marked';

init();
// env.useBrowserCache = false; // for testing

Expand Down Expand Up @@ -81,36 +83,38 @@ async function getTokens(text) {
async function chat(text, max_new_tokens = 100) {
return new Promise(async (resolve, reject) => {
// hier Weiche einbauen für Qwen da tokenizer anders
console.log(chat_model_name);
console.log(chat_model_name, max_new_tokens);

if (chat_model_name.includes("Qwen")) {
try {

// Define the prompt and list of messages

const messages = [
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "user", "content": text }
]

const generatorText = chat_generator.tokenizer.apply_chat_template(messages, {
tokenize: false,
add_generation_prompt: true,
add_generation_prompt: false,
});

const thisChat = await chat_generator(generatorText, {
max_new_tokens: max_new_tokens,
do_sample: false,
callback_function: async function (beams) {
//const decodedText = await token_to_text(beams, chat_generator.tokenizer);
//console.log(decodedText);
console.log(beams)
let decodedText = chat_generator.tokenizer.decode(beams[0].output_token_ids, { skip_special_tokens: false })

decodedText = decodedText.split("<|im_start|>")[3].replace("<|im_end|>","") // just return the model's output
decodedText = marked(decodedText)

self.postMessage({
type: 'chat',
chat_text: beams,
chat_text: decodedText
});

resolve(beams); // Resolve the main promise with chat text
resolve(decodedText); // Resolve the main promise with chat text
},
});
} catch (error) {
Expand Down

0 comments on commit a078d6a

Please sign in to comment.