-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
379 lines (369 loc) · 9.45 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
// include libraries
const readXlsxFile = require("read-excel-file/node");
const fs = require("fs");
// delcares schema of converted json file
const schema = {
shop_code: {
prop: "shopCode",
type: String,
},
des_id: {
prop: "desID",
type: String,
},
description: {
prop: "description",
type: String,
},
vintage: {
prop: "vintage",
type: String,
},
rating: {
prop: "rating",
type: Number,
},
flavour_x: {
prop: "flavourX",
type: Number,
},
flavour_y: {
prop: "flavourY",
type: Number,
},
rgb: {
prop: "rgb",
type: String,
},
wine_type: {
prop: "wineType",
type: String,
},
foodpair0: {
prop: "foodpair0",
type: String,
},
foodpair1: {
prop: "foodpair1",
type: String,
},
foodpair2: {
prop: "foodpair2",
type: String,
},
foodpair3: {
prop: "foodpair3",
type: String,
},
foodpair4: {
prop: "foodpair4",
type: String,
},
foodpair5: {
prop: "foodpair5",
type: String,
},
foodpair6: {
prop: "foodpair6",
type: String,
},
collection: {
prop: "collection",
type: String,
},
subcollection: {
prop: "subcollection",
type: String,
},
region: {
prop: "region",
type: String,
},
subregion: {
prop: "subregion",
type: String,
},
occasion: {
prop: "occasion",
type: String,
},
ribbon: {
prop: "ribbon",
type: String,
},
alternative_wine: {
prop: "alternativeWine",
type: String,
},
vinvalue: {
prop: "vinValue",
type: Number,
},
color: {
prop: "color",
type: String,
},
tastingnote: {
prop: "tastingNote",
type: String,
},
price_sale: {
prop: "priceSale",
type: Number,
},
vinvaluestore: {
prop: "vinValueStore",
type: String,
},
pricecompstore: {
prop: "priceCompStore",
type: String,
},
ratingcompstore: {
prop: "ratingCompStore",
type: String,
},
flag_onsale: {
prop: "flagOnSale",
type: Number,
},
flavour_profile: {
prop: "flavourProfile",
type: String,
},
flavour_description: {
prop: "flavourDescription",
type: String,
},
flavour_taste1: {
prop: "flavourTaste1",
type: String,
},
flavour_taste2: {
prop: "flavourTaste2",
type: String,
},
expand_palate: {
prop: "expandPalate",
type: String,
},
};
// database fields explanation
const fields = [
{
name: "shopCode",
explanation:
"The tag that says the store name. When people search for wines, we want to only return wines at the right store.",
},
{
name: "desID",
explanation: "This is the unique product identifier.",
},
{
name: "vintage",
explanation:
"This is the unique wine year. All data is at the name and year level. So Tyrrells Vat 1 Semillon 2013 should be viewed independently from Tyrrells Vat 1 Semillon 2017.",
},
{
name: "rating",
explanation: "This is the 'score' that the wine received.",
},
{
name: "flavourX",
explanation:
"This metric shows how sweet or dry a wine is. Positive values mean the wine is dry. Negative values mean the wine is sweet.",
},
{
name: "flavourY",
explanation:
"This metric shows how light or bold a wine is. Positive values mean the wine is bold. Negative values mean the wine is light.",
},
{
name: "rgb",
explanation: "This value shows the approximate colour of the wine.",
},
{
name: "wineType",
explanation: "This value tells what type of wine it is at a high level.",
},
{
name: "foodpair",
explanation: "This value tells what food goes well with the wine.",
},
{
name: "collection",
explanation:
"This value gives a high level categorisation of the wine type.",
},
{
name: "subCollection",
explanation:
"This value gives a lower level categorisation of the wine type.",
},
{
name: "region",
explanation: "This value gives the region that the wine is from.",
},
{
name: "subregion",
explanation: "This value gives the subregion that the wine is from.",
},
{
name: "occasion",
explanation:
"This value gives an example of an occasion to drink a wine. For example, if someone wants a celebration wine, they would use this field to search.",
},
{
name: "ribbon",
explanation:
"This value says if the wine is listed as a 'best value' or 'best quality' wine",
},
{
name: "alternativeWine",
explanation: "This value gives other wines to try that are similar to it.",
},
{
name: "vinvalue",
explanation:
"This value is a metric that compares how good the wine scored (rating) based on its price",
},
{
name: "tastingNote",
explanation:
"This value describes some of the wine flavour in text. This should be the top priority descriptor.",
},
{
name: "priceSale",
explanation: "This value gives the price of the wine.",
},
{
name: "vinValueStore",
explanation:
"This value ranks how good the wine scored in 'VinValue' compared to other wines at that store.",
},
{
name: "priceCompStore",
explanation:
"This value ranks how good the wine scored in 'Price' compared to other wines at that store.",
},
{
name: "ratingCompStore",
explanation:
"This value ranks how good the wine scored in 'Rating' compared to other wines at that store.",
},
{
name: "flagOnsale",
explanation: "This value indicates whether the wine is on sale currently.",
},
{
name: "flavourProfile",
explanation:
"This value describes some of the wine flavour in text. This should be the third priority descriptor.",
},
{
name: "flavourDescription",
explanation:
"This value describes some of the wine flavour in text. This should be the second priority descriptor.",
},
{
name: "flavourTaste1",
explanation:
"This value describes some of the wine flavour in text. This should be the 4th priority descriptor.",
},
{
name: "flavourTaste2",
explanation:
"This value describes some of the wine flavour in text. This should be the 5th priority descriptor.",
},
];
// read excel file & prepare dataset
readXlsxFile("./given.xlsx", { schema }).then(({ rows, errors }) => {
const dataset = [];
// Question & Answer form of prompt / completion which defines fields
fields.forEach((field) =>
dataset.push({
prompt: `What is ${field.name}?`,
completion: field.explanation,
})
);
// prompt as possible customer requirement, completion as wine name reply
rows.forEach((row) => {
const prompt = `The wine has vintage year of ${row.vintage}. It has ${
row.raiting > 90 ? "high" : "normal"
} rating. It is kind of ${row.flavourX > 0 ? "dry" : "sweet"} ${
row.flavourY > 0 ? "bold" : "light"
} wine. It has ${
row.rgb > "#999999" ? "bright" : "dark"
} color. Type of wine is ${row.wineType}. Foods go well with this wine is ${
row.foodpair1
}, ${row.foodpair2}, ${row.foodpair3}, ${row.foodpair4} and ${
row.foodpair5
}. Its foodpair in detail is "${
row.foodpair0
}". Its high level categorisation of this wine type is ${row.collection.split(
"|"
)}. Simply this belongs to ${row.subcollection} wine. ${
row.region !== undefined
? "It comes from " + row.subregion + " in " + row.region + "."
: "The region it comes from is not specified."
} ${
row.occasion !== undefined
? ' People can drink this wine on the occasion of "' +
row.occasion.split("|").filter((value) => value !== "") +
'".'
: ""
}${
row.ribbon !== undefined
? " This wine is listed as " + row.ribbon + "."
: " "
}${
row.alternativeWine !== undefined
? row.alternativeWine + " Wine can be used instead of this wine."
: ""
} This wine is ${
row.vinvalue < 0 ? "not " : ""
}scored as good based on its price. It shows ${row.color.toLowerCase()} color. Its tasting note is "${
row.tastingNote
}". It costs ${row.priceSale}$. It is scored as ${
row.vinValueStore > 0.5 ? "better" : "worse"
} than others based on price. It costs ${
row.priceCompStore < 0.5 ? "more expensive" : "cheaper"
} than average price. It has ${
row.raitingCompStore > 0.5 ? "better" : "worse"
} rating than normal ones. It is currently${
row.flagOnSale === 1 ? "" : "not"
} on sale. Flavour description of this wine is "${
row.flavourDescription
}. It tastes like ${row.flavourTaste1} and ${row.flavourTaste2}. "`;
const completion = `Wine Name: ${row.description} ${
row.vintage
}. It costs ${row.priceSale}$. Its color is ${row.color}. It is rated as ${
row.rating
}. ${
row.ribbon !== undefined ? "It is listed as " + row.ribbon + ". " : ""
}des_id is ${row.desID}.`;
dataset.push({ prompt, completion });
});
rows.forEach((row) => {
const prompt = `Exact information of ${row.description} ${row.vintage}.`;
let completion = "";
Object.keys(row).forEach(
(key) => (completion += key + " is " + row[key] + ". ")
);
dataset.push({ prompt, completion });
});
dataset.forEach((data) => {
const writeData = JSON.stringify(data) + "\n";
try {
fs.appendFileSync(
"wineinfo.jsonl",
JSON.stringify(data) + "\n",
(err) => {
if (err) throw err;
}
);
} catch (err) {
console.log(err);
}
});
});