Spaces:
Running
Running
sarahciston
commited on
Commit
•
b71619b
1
Parent(s):
d6148e1
try new model
Browse files
sketch.js
CHANGED
@@ -1,8 +1,7 @@
|
|
1 |
|
2 |
// IMPORT LIBRARIES TOOLS
|
3 |
-
import { pipeline, env
|
4 |
-
|
5 |
-
|
6 |
|
7 |
// skip local model check
|
8 |
env.allowLocalModels = false;
|
@@ -17,23 +16,23 @@ let PREPROMPT = `You're a friendly pirate. Please complete the phrase and fill i
|
|
17 |
async function textGenTask(input){
|
18 |
console.log('text-gen task initiated')
|
19 |
|
20 |
-
let MODEL = 'Xenova/
|
21 |
-
// const = modelsList = ['Xenova/LaMini-Cerebras-256M', ]
|
22 |
|
23 |
const pipe = await pipeline('text-generation', MODEL)
|
24 |
-
let tokenizer = AutoTokenizer.from_pretrained(MODEL)
|
25 |
|
|
|
|
|
|
|
|
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
]
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
});
|
35 |
-
|
36 |
-
var out = await pipe(prompt, {
|
37 |
max_new_tokens: 256,
|
38 |
temperature: 0.7,
|
39 |
do_sample: true,
|
@@ -43,6 +42,8 @@ async function textGenTask(input){
|
|
43 |
console.log(await out)
|
44 |
console.log('text-gen task completed')
|
45 |
|
|
|
|
|
46 |
let OUTPUT_LIST = [] // a blank array to store the results from the model
|
47 |
|
48 |
// parsing of output
|
@@ -82,28 +83,25 @@ async function fillInTask(input){
|
|
82 |
})
|
83 |
|
84 |
console.log(await OUTPUT_LIST)
|
85 |
-
|
86 |
-
// displayResults(await OUTPUT_LIST)
|
87 |
-
|
88 |
console.log('fill-in task completed')
|
89 |
|
90 |
// return await out
|
91 |
return await OUTPUT_LIST
|
92 |
}
|
93 |
|
94 |
-
// PROCESS MODEL OUTPUT
|
95 |
-
// a generic function to pass in different model task functions
|
96 |
-
async function getOutputs(task){
|
97 |
-
|
98 |
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
|
103 |
-
|
104 |
|
105 |
-
|
106 |
-
}
|
107 |
|
108 |
// await getOutputs(fillInTask()) // getOutputs will later connect to the interface to display results
|
109 |
|
@@ -154,15 +152,13 @@ new p5(function (p5){
|
|
154 |
console.log("latest prompt: ", PROMPT_INPUT)
|
155 |
|
156 |
// let fillIn = await fillInTask(PROMPT_INPUT)
|
157 |
-
|
158 |
// let outs = await getOutputs(fillIn)
|
159 |
-
|
|
|
|
|
160 |
let outs = await textGenTask(PROMPT_INPUT)
|
161 |
-
|
162 |
console.log(outs)
|
163 |
|
164 |
-
// text = str(outs)
|
165 |
-
|
166 |
let outText = p5.createP('')
|
167 |
await outText.html(outs) // true appends text instead of replaces
|
168 |
}
|
|
|
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;
|
|
|
16 |
async function textGenTask(input){
|
17 |
console.log('text-gen task initiated')
|
18 |
|
19 |
+
let MODEL = 'Xenova/OpenELM-270M-Instruct'
|
20 |
+
// const = modelsList = ['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 |
+
// let messages = [
|
26 |
+
// {"role": "system", "content": PREPROMPT},
|
27 |
+
// {"role": "user", "content": input}
|
28 |
+
// ]
|
29 |
|
30 |
+
// const prompt = pipe.tokenizer.apply_chat_template(messages, {
|
31 |
+
// tokenize: false, add_generation_prompt: false,
|
32 |
+
// });
|
|
|
33 |
|
34 |
+
// run text through model, setting hyperparameters
|
35 |
+
var out = await pipe(input, {
|
|
|
|
|
|
|
36 |
max_new_tokens: 256,
|
37 |
temperature: 0.7,
|
38 |
do_sample: true,
|
|
|
42 |
console.log(await out)
|
43 |
console.log('text-gen task completed')
|
44 |
|
45 |
+
// parse results as a list of outputs, two different ways depending on the model
|
46 |
+
|
47 |
let OUTPUT_LIST = [] // a blank array to store the results from the model
|
48 |
|
49 |
// parsing of output
|
|
|
83 |
})
|
84 |
|
85 |
console.log(await OUTPUT_LIST)
|
|
|
|
|
|
|
86 |
console.log('fill-in task completed')
|
87 |
|
88 |
// return await out
|
89 |
return await OUTPUT_LIST
|
90 |
}
|
91 |
|
92 |
+
// // PROCESS MODEL OUTPUT
|
93 |
+
// // a generic function to pass in different model task functions
|
94 |
+
// async function getOutputs(task){
|
95 |
+
// let output = await task
|
96 |
|
97 |
+
// await output.forEach(o => {
|
98 |
+
// OUTPUT_LIST.push(o.sequence) // put only the full sequence in a list
|
99 |
+
// })
|
100 |
|
101 |
+
// console.log(OUTPUT_LIST)
|
102 |
|
103 |
+
// return await OUTPUT_LIST
|
104 |
+
// }
|
105 |
|
106 |
// await getOutputs(fillInTask()) // getOutputs will later connect to the interface to display results
|
107 |
|
|
|
152 |
console.log("latest prompt: ", PROMPT_INPUT)
|
153 |
|
154 |
// let fillIn = await fillInTask(PROMPT_INPUT)
|
|
|
155 |
// let outs = await getOutputs(fillIn)
|
156 |
+
|
157 |
+
// call the function that runs the model for the task of your choice here
|
158 |
+
// make sure to use the PROMPT_INPUT as a parameter
|
159 |
let outs = await textGenTask(PROMPT_INPUT)
|
|
|
160 |
console.log(outs)
|
161 |
|
|
|
|
|
162 |
let outText = p5.createP('')
|
163 |
await outText.html(outs) // true appends text instead of replaces
|
164 |
}
|