Spaces:
Running
Running
try chat template tinyLlama
Browse files
sketch.js
CHANGED
|
@@ -8,23 +8,27 @@ env.allowLocalModels = false;
|
|
| 8 |
// GLOBAL VARIABLES
|
| 9 |
let PROMPT_INPUT = `The woman has a job as a...` // a field for writing or changing a text value
|
| 10 |
let pField
|
|
|
|
| 11 |
|
| 12 |
// RUN TEXT-GEN MODEL
|
| 13 |
|
| 14 |
async function textGenTask(input){
|
| 15 |
console.log('text-gen task initiated')
|
| 16 |
|
| 17 |
-
const pipe = await pipeline('text-generation', 'Xenova/
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
max_new_tokens:
|
|
|
|
|
|
|
|
|
|
| 28 |
})
|
| 29 |
|
| 30 |
console.log(await out)
|
|
@@ -33,9 +37,14 @@ async function textGenTask(input){
|
|
| 33 |
let OUTPUT_LIST = [] // a blank array to store the results from the model
|
| 34 |
|
| 35 |
// parsing of output
|
| 36 |
-
await out.forEach(o => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
console.log(o)
|
| 38 |
-
OUTPUT_LIST.push(o.
|
| 39 |
})
|
| 40 |
|
| 41 |
console.log(OUTPUT_LIST)
|
|
|
|
| 8 |
// GLOBAL VARIABLES
|
| 9 |
let PROMPT_INPUT = `The woman has a job as a...` // a field for writing or changing a text value
|
| 10 |
let pField
|
| 11 |
+
let PREPROMPT = `You're a friendly pirate. Please complete the phrase and fill in any [MASK].`
|
| 12 |
|
| 13 |
// RUN TEXT-GEN MODEL
|
| 14 |
|
| 15 |
async function textGenTask(input){
|
| 16 |
console.log('text-gen task initiated')
|
| 17 |
|
| 18 |
+
const pipe = await pipeline('text-generation', 'Xenova/TinyLlama-1.1B-Chat-v1.0')
|
| 19 |
+
|
| 20 |
+
// const = modelsList = ['Xenova/LaMini-Cerebras-256M', ]
|
| 21 |
+
|
| 22 |
+
let messages: [
|
| 23 |
+
{"role": "system", "content": PREPROMPT},
|
| 24 |
+
{"role": "user", "content": input}
|
| 25 |
+
]
|
| 26 |
+
|
| 27 |
+
var out = await pipe(messages, {
|
| 28 |
+
max_new_tokens: 256,
|
| 29 |
+
temperature: 0.7,
|
| 30 |
+
do_sample: true,
|
| 31 |
+
top_k: 50,
|
| 32 |
})
|
| 33 |
|
| 34 |
console.log(await out)
|
|
|
|
| 37 |
let OUTPUT_LIST = [] // a blank array to store the results from the model
|
| 38 |
|
| 39 |
// parsing of output
|
| 40 |
+
// await out.forEach(o => {
|
| 41 |
+
// console.log(o)
|
| 42 |
+
// OUTPUT_LIST.push(o.generated_text)
|
| 43 |
+
// })
|
| 44 |
+
|
| 45 |
+
await out.choices.forEach(o => {
|
| 46 |
console.log(o)
|
| 47 |
+
OUTPUT_LIST.push(o.message.content)
|
| 48 |
})
|
| 49 |
|
| 50 |
console.log(OUTPUT_LIST)
|