Sarah Ciston commited on
Commit
08e8ca7
1 Parent(s): f8c97c4

try simplified zephyr

Browse files
Files changed (2) hide show
  1. sketch.js +23 -20
  2. tutorial.mdx → tutorial.md +79 -9
sketch.js CHANGED
@@ -34,7 +34,7 @@ var blanksArray = []
34
 
35
  new p5(function (p5) {
36
  p5.setup = function(){
37
- console.log('p5 loaded')
38
  p5.noCanvas()
39
  makeInterface()
40
  }
@@ -43,9 +43,9 @@ new p5(function (p5) {
43
  //
44
  }
45
 
46
- window.onload = function(){
47
- console.log('dom and js loaded')
48
- }
49
 
50
  let fieldsDiv = document.querySelector("#blanks")
51
 
@@ -179,23 +179,26 @@ async function runModel(PREPROMPT, PROMPT){
179
 
180
  let pipe = pipeline("text-generation", "HuggingFaceH4/zephyr-7b-beta")
181
 
 
182
  // for zephyr customizing
183
- let MESSAGES = [
184
- {
185
- "role": "system",
186
- "content": PREPROMPT
187
- },{
188
- "role": "user",
189
- "content": PROMPT
190
- }
191
- ]
192
-
193
- let res = await pipe(MESSAGES, {
194
- max_new_tokens: 150,
195
- temperature: 0.7,
196
- top_k: 50,
197
- top_p: 0.95
198
- });
 
 
199
 
200
  console.log(res)
201
 
 
34
 
35
  new p5(function (p5) {
36
  p5.setup = function(){
37
+ console.log('p5 instance loaded')
38
  p5.noCanvas()
39
  makeInterface()
40
  }
 
43
  //
44
  }
45
 
46
+ // window.onload = function(){
47
+ // console.log('p5 instance loaded')
48
+ // }
49
 
50
  let fieldsDiv = document.querySelector("#blanks")
51
 
 
179
 
180
  let pipe = pipeline("text-generation", "HuggingFaceH4/zephyr-7b-beta")
181
 
182
+ let MESSAGES = PREPROMPT + PROMPT
183
  // for zephyr customizing
184
+ // let MESSAGES = [
185
+ // {
186
+ // "role": "system",
187
+ // "content": PREPROMPT
188
+ // },{
189
+ // "role": "user",
190
+ // "content": PROMPT
191
+ // }
192
+ // ]
193
+
194
+ let res = await pipe(MESSAGES)
195
+
196
+ // let res = await pipe(MESSAGES, {
197
+ // max_new_tokens: 150,
198
+ // temperature: 0.7,
199
+ // top_k: 50,
200
+ // top_p: 0.95
201
+ // });
202
 
203
  console.log(res)
204
 
tutorial.mdx → tutorial.md RENAMED
@@ -7,8 +7,6 @@ editors:
7
  category: critical-ai
8
  ---
9
 
10
- <!-- more background: https://huggingface.co/tasks/text-generation -->
11
-
12
  # p5.js Critical AI Prompt Battle
13
  By Sarah Ciston
14
  With Emily Martinez and Minne Atairu
@@ -43,6 +41,8 @@ Put this code at the top of `sketch.js`:
43
 
44
  ```javascript
45
  import { pipeline, env } from 'https://cdn.jsdelivr.net/npm/@xenova/[email protected]';
 
 
46
  ```
47
  The import phrase says we are bringing in a library (or module) and the curly braces let us specify which specific functions from the library we want to use, in case we don't want to import the entire thing. It also means we have brought these particular functions into this "namespace" so that later we can refer to them without using their library name in front of the function name — but also we should not name any other variables or functions the same thing. More information on importing [Modules]([XXX]).
48
 
@@ -55,20 +55,25 @@ var promptInput // will be a field for insert a text value
55
  var blankArray = [] // will be an array to insert a list of text values from multiple fields
56
  ```
57
 
 
 
 
 
 
 
58
  #### X. Write instructions for your model.
59
-
60
- Set PREPROMPT = `Return an array of sentences. In each sentence, fill in the [BLANK] in the following sentence with each word I provide in the array ${blankArray}. Replace any [FILL] with an appropriate word of your choice.`
61
 
62
- <!-- A [BLANK] family travels to [FILL] and on the way encounters... -->
 
 
 
 
 
63
 
64
  #### X. [PSEUDOCODE] Add async function runModel() wrapping HF API await. {// explain link to await} explain
65
 
66
  #### X. [PSEUDOCODE] Add model results processing with await
67
 
68
- #### X. [PSEUDOCODE] Create makeInterface() and add features
69
-
70
- #### X. [PSEUDOCODE] Connect form, test with console.log
71
-
72
  #### X. [PSEUDOCODE] Connect model results, send model results to interface
73
 
74
  #### X. [PSEUDOCODE] Test with simple example.
@@ -129,3 +134,68 @@ Consider making it a habit to add text like "AI generated" to the title of any c
129
  Morgan, Yasmin. 2022. "AIxDesign Icebreakers, Mini-Games & Interactive Exercises." https://aixdesign.co/posts/ai-icebreakers-mini-games-interactive-exercises
130
 
131
  > Ref Minne's worksheet (Atairu 2024)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  category: critical-ai
8
  ---
9
 
 
 
10
  # p5.js Critical AI Prompt Battle
11
  By Sarah Ciston
12
  With Emily Martinez and Minne Atairu
 
41
 
42
  ```javascript
43
  import { pipeline, env } from 'https://cdn.jsdelivr.net/npm/@xenova/[email protected]';
44
+
45
+ env.allowLocalModels = false;
46
  ```
47
  The import phrase says we are bringing in a library (or module) and the curly braces let us specify which specific functions from the library we want to use, in case we don't want to import the entire thing. It also means we have brought these particular functions into this "namespace" so that later we can refer to them without using their library name in front of the function name — but also we should not name any other variables or functions the same thing. More information on importing [Modules]([XXX]).
48
 
 
55
  var blankArray = [] // will be an array to insert a list of text values from multiple fields
56
  ```
57
 
58
+ We will be making a form that lets us write a prompt and send it to a model. It will have extra inputs for making variations of the prompt it sends. The `promptInput` variable will carry the prompt we create, and the `blankArray` will carry the variations we tell the model to insert into the prompt.
59
+
60
+ #### X. [PSEUDOCODE] Create makeInterface() and add features
61
+
62
+ #### X. [PSEUDOCODE] Connect form, test with console.log
63
+
64
  #### X. Write instructions for your model.
 
 
65
 
66
+ We can instruct the model by giving it pre-instructions that go along with every prompt. We'll write also write those instructions now. Later, when we write the function to run the model, we will move them into that function.
67
+
68
+ ```js
69
+ let PREPROMPT = `Return an array of sentences. In each sentence, fill in the [BLANK] in the following sentence with each word I provide in the array ${blankArray}. Replace any [FILL] with an appropriate word of your choice.`
70
+ ```
71
+ With the dollar sign and curly braces `${blankArray}`, we make a "string variable." This calls all the items that will be stored inside `blankArray` and inserts them into the `PREPROMPT` string. Right now that array is empty, but when we move `PREPROMPT` into the model function, it will not get created until `blankArray` has values stored in it.
72
 
73
  #### X. [PSEUDOCODE] Add async function runModel() wrapping HF API await. {// explain link to await} explain
74
 
75
  #### X. [PSEUDOCODE] Add model results processing with await
76
 
 
 
 
 
77
  #### X. [PSEUDOCODE] Connect model results, send model results to interface
78
 
79
  #### X. [PSEUDOCODE] Test with simple example.
 
134
  Morgan, Yasmin. 2022. "AIxDesign Icebreakers, Mini-Games & Interactive Exercises." https://aixdesign.co/posts/ai-icebreakers-mini-games-interactive-exercises
135
 
136
  > Ref Minne's worksheet (Atairu 2024)
137
+
138
+
139
+
140
+
141
+
142
+ ============================================
143
+
144
+
145
+ Tutorial 1:
146
+
147
+ #### X. Create a class instance of p5 in `sketch.js`
148
+
149
+ Because we are going to use several other libraries alongside p5.js, it will be necessary and helpful to use p5.js in "Instance Mode." You may have seen this before in this [Multiple Canvases](https://p5js.org/examples/advanced-canvas-rendering-multiple-canvases/) example.
150
+
151
+ Our p5.js Instance is basically a wrapper that allows us to hold all of our p5.js functions together in one place and label them, so that the program can recognize them as belonging to p5.js.
152
+
153
+ First we declare a `new p5()` class instance:
154
+
155
+ ```javascript
156
+ new p5(function (p5) {
157
+ //
158
+ }
159
+ ```
160
+ Then, all our usual p5.js coding will happen within these curly braces.
161
+
162
+ ```js
163
+ new p5(function (p5) {
164
+ p5.setup = function(){
165
+ //
166
+ }
167
+
168
+ p5.draw = function(){
169
+ //
170
+ }
171
+ }
172
+ ```
173
+ Important: When using any functions specific to p5.js, you will start them out with a label of whatever you called your p5.js instance. In this case we called it `p5` so our functions will be called `p5.setup()` and `p5.draw()` instead of the `setup()` and `draw()` you may recognize.
174
+
175
+ This will apply to any other function that is special to p5.js, like `p5.noCanvas`, but *not* to other functions which are standard to Javascript. Anything code written outside of the `new p5(){}` instance will not understand any p5.js syntax.
176
+
177
+ Let's add the instance mode version of `p5.noCanvas()` because we will be working directly with the DOM and don't need a canvas.
178
+
179
+ ```js
180
+ new p5(function (p5) {
181
+ p5.setup = function(){
182
+ p5.noCanvas()
183
+ console.log('p5 instance loaded')
184
+ }
185
+
186
+ p5.draw = function(){
187
+ //
188
+ }
189
+ }
190
+ ```
191
+ We can also check that the p5 instance is working correctly by adding `console.log('p5 instance loaded')` to `p5.setup()`, since you won't yet see a canvas or any DOM elements
192
+
193
+
194
+ Check that the page loaded, since we don't have a canvas
195
+
196
+ ```js
197
+ window.onload = function(){
198
+ console.log('DOM loaded, sketch.js loaded')
199
+ }
200
+
201
+ ```