Spaces:
Running
Running
try new model chat template
Browse files
sketch.js
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
|
2 |
// IMPORT LIBRARIES TOOLS
|
3 |
-
import { pipeline, env } from 'https://cdn.jsdelivr.net/npm/@xenova/[email protected]';
|
4 |
// AutoTokenizer
|
5 |
|
6 |
// skip local model check
|
7 |
env.allowLocalModels = false;
|
8 |
|
9 |
// GLOBAL VARIABLES
|
10 |
-
let PROMPT_INPUT = `The woman has a job as a...` // a field for writing or changing a text value
|
11 |
let pField
|
12 |
let PREPROMPT = `You're a friendly pirate. Please complete the phrase and fill in any [MASK].`
|
13 |
|
@@ -16,20 +16,26 @@ let PREPROMPT = `You're a friendly pirate. Please complete the phrase and fill i
|
|
16 |
async function textGenTask(input){
|
17 |
console.log('text-gen task initiated')
|
18 |
|
19 |
-
let MODEL = 'Xenova/
|
20 |
-
// const = modelsList = ['Xenova/LaMini-Cerebras-256M', 'Xenova/TinyLlama-1.1B-Chat-v1.0']
|
21 |
|
22 |
const pipe = await pipeline('text-generation', MODEL)
|
23 |
-
|
24 |
|
25 |
-
//
|
26 |
// {"role": "system", "content": PREPROMPT},
|
27 |
// {"role": "user", "content": input}
|
28 |
// ]
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
// run text through model, setting hyperparameters
|
35 |
var out = await pipe(input, {
|
|
|
1 |
|
2 |
// IMPORT LIBRARIES TOOLS
|
3 |
+
import { pipeline, env, AutoTokenizer } from 'https://cdn.jsdelivr.net/npm/@xenova/[email protected]';
|
4 |
// AutoTokenizer
|
5 |
|
6 |
// skip local model check
|
7 |
env.allowLocalModels = false;
|
8 |
|
9 |
// GLOBAL VARIABLES
|
10 |
+
let PROMPT_INPUT = `The woman has a job as a [MASK] and likes to ...` // a field for writing or changing a text value
|
11 |
let pField
|
12 |
let PREPROMPT = `You're a friendly pirate. Please complete the phrase and fill in any [MASK].`
|
13 |
|
|
|
16 |
async function textGenTask(input){
|
17 |
console.log('text-gen task initiated')
|
18 |
|
19 |
+
let MODEL = 'Xenova/stablelm-2-zephyr-1_6b'
|
20 |
+
// const = modelsList = ['Xenova/stablelm-2-zephyr-1_6b', 'Xenova/LaMini-Cerebras-256M', 'Xenova/TinyLlama-1.1B-Chat-v1.0']
|
21 |
|
22 |
const pipe = await pipeline('text-generation', MODEL)
|
23 |
+
let tokenizer = AutoTokenizer.from_pretrained(MODEL)
|
24 |
|
25 |
+
// const messages = [
|
26 |
// {"role": "system", "content": PREPROMPT},
|
27 |
// {"role": "user", "content": input}
|
28 |
// ]
|
29 |
|
30 |
+
const messages = [
|
31 |
+
{ "role": "system", "content": "You are a helpful assistant." },
|
32 |
+
{ "role": "user", "content": input },
|
33 |
+
]
|
34 |
+
|
35 |
+
const prompt = pipe.tokenizer.apply_chat_template(messages, {
|
36 |
+
tokenize: false,
|
37 |
+
add_generation_prompt: false,
|
38 |
+
});
|
39 |
|
40 |
// run text through model, setting hyperparameters
|
41 |
var out = await pipe(input, {
|