@garrix82/reactgenie-dsl 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/.env +10 -0
  2. package/.env.example +17 -0
  3. package/.github/workflows/publish.yml +20 -0
  4. package/README.md +5 -1
  5. package/package.json +1 -5
  6. package/dist/__test__/dsl-descriptor.test.d.ts +0 -1
  7. package/dist/__test__/dsl-descriptor.test.js +0 -27
  8. package/dist/__test__/dsl-descriptor.test.js.map +0 -1
  9. package/dist/__test__/example_descriptor.d.ts +0 -125
  10. package/dist/__test__/example_descriptor.js +0 -607
  11. package/dist/__test__/example_descriptor.js.map +0 -1
  12. package/dist/__test__/food_descriptor.state.json +0 -1
  13. package/dist/__test__/food_descriptor.test.d.ts +0 -74
  14. package/dist/__test__/food_descriptor.test.js +0 -205
  15. package/dist/__test__/food_descriptor.test.js.map +0 -1
  16. package/dist/__test__/nl-interpreter-provider-selection.test.d.ts +0 -1
  17. package/dist/__test__/nl-interpreter-provider-selection.test.js +0 -73
  18. package/dist/__test__/nl-interpreter-provider-selection.test.js.map +0 -1
  19. package/dist/__test__/nl-interpreter.test.d.ts +0 -1
  20. package/dist/__test__/nl-interpreter.test.js +0 -86
  21. package/dist/__test__/nl-interpreter.test.js.map +0 -1
  22. package/dist/decorators/__test__/decorators.test.d.ts +0 -1
  23. package/dist/decorators/__test__/decorators.test.js +0 -182
  24. package/dist/decorators/__test__/decorators.test.js.map +0 -1
  25. package/dist/decorators/__test__/inheritance-descriptor.test.d.ts +0 -1
  26. package/dist/decorators/__test__/inheritance-descriptor.test.js +0 -107
  27. package/dist/decorators/__test__/inheritance-descriptor.test.js.map +0 -1
  28. package/dist/dsl/__test__/dsl-interpreter.test.d.ts +0 -1
  29. package/dist/dsl/__test__/dsl-interpreter.test.js +0 -334
  30. package/dist/dsl/__test__/dsl-interpreter.test.js.map +0 -1
  31. package/dist/dsl/__test__/parser.gen.test.d.ts +0 -1
  32. package/dist/dsl/__test__/parser.gen.test.js +0 -283
  33. package/dist/dsl/__test__/parser.gen.test.js.map +0 -1
  34. package/dist/nl/__test__/context-aware-prompt.test.d.ts +0 -1
  35. package/dist/nl/__test__/context-aware-prompt.test.js +0 -247
  36. package/dist/nl/__test__/context-aware-prompt.test.js.map +0 -1
  37. package/dist/nl/__test__/context-selector.test.d.ts +0 -1
  38. package/dist/nl/__test__/context-selector.test.js +0 -20
  39. package/dist/nl/__test__/context-selector.test.js.map +0 -1
  40. package/dist/nl/__test__/nl-parser-groq-transport.test.d.ts +0 -1
  41. package/dist/nl/__test__/nl-parser-groq-transport.test.js +0 -87
  42. package/dist/nl/__test__/nl-parser-groq-transport.test.js.map +0 -1
  43. package/dist/nl/__test__/nl-parser-openai-parity.test.d.ts +0 -1
  44. package/dist/nl/__test__/nl-parser-openai-parity.test.js +0 -206
  45. package/dist/nl/__test__/nl-parser-openai-parity.test.js.map +0 -1
  46. package/dist/nl/__test__/nl-parser-openai-sampling.test.d.ts +0 -1
  47. package/dist/nl/__test__/nl-parser-openai-sampling.test.js +0 -44
  48. package/dist/nl/__test__/nl-parser-openai-sampling.test.js.map +0 -1
  49. package/dist/nl/__test__/nl-parser-openai-transport.test.d.ts +0 -1
  50. package/dist/nl/__test__/nl-parser-openai-transport.test.js +0 -55
  51. package/dist/nl/__test__/nl-parser-openai-transport.test.js.map +0 -1
  52. package/dist/nl/__test__/nl-parser-utils.test.d.ts +0 -1
  53. package/dist/nl/__test__/nl-parser-utils.test.js +0 -70
  54. package/dist/nl/__test__/nl-parser-utils.test.js.map +0 -1
  55. package/dist/nl/__test__/nl-parser.test.d.ts +0 -1
  56. package/dist/nl/__test__/nl-parser.test.js +0 -64
  57. package/dist/nl/__test__/nl-parser.test.js.map +0 -1
  58. package/dist/nl/__test__/parameter-tuning.test.d.ts +0 -1
  59. package/dist/nl/__test__/parameter-tuning.test.js +0 -95
  60. package/dist/nl/__test__/parameter-tuning.test.js.map +0 -1
  61. package/dist/nl/__test__/semantic-parsing-experiment.test.d.ts +0 -1
  62. package/dist/nl/__test__/semantic-parsing-experiment.test.js +0 -178
  63. package/dist/nl/__test__/semantic-parsing-experiment.test.js.map +0 -1
  64. package/dist/nl/llm-monitoring.test.d.ts +0 -5
  65. package/dist/nl/llm-monitoring.test.js +0 -101
  66. package/dist/nl/llm-monitoring.test.js.map +0 -1
  67. package/lib/__test__/dsl-descriptor.test.ts +0 -27
  68. package/lib/__test__/example_descriptor.ts +0 -762
  69. package/lib/__test__/food_descriptor.state.json +0 -1
  70. package/lib/__test__/food_descriptor.test.ts +0 -331
  71. package/lib/__test__/nl-interpreter-provider-selection.test.ts +0 -126
  72. package/lib/__test__/nl-interpreter.test.ts +0 -129
  73. package/lib/decorators/__test__/decorators.test.ts +0 -177
  74. package/lib/decorators/__test__/inheritance-descriptor.test.ts +0 -92
  75. package/lib/decorators/decorators.ts +0 -754
  76. package/lib/decorators/index.ts +0 -2
  77. package/lib/decorators/store.ts +0 -47
  78. package/lib/dsl/__test__/dsl-interpreter.test.ts +0 -453
  79. package/lib/dsl/__test__/parser.gen.test.ts +0 -296
  80. package/lib/dsl/dsl-interpreter.ts +0 -974
  81. package/lib/dsl/index.ts +0 -1
  82. package/lib/dsl/parser.gen.js +0 -1479
  83. package/lib/dsl/parser.pegjs +0 -130
  84. package/lib/dsl-descriptor.ts +0 -241
  85. package/lib/index.ts +0 -5
  86. package/lib/nl/__test__/context-aware-prompt.test.ts +0 -372
  87. package/lib/nl/__test__/context-selector.test.ts +0 -27
  88. package/lib/nl/__test__/nl-parser-groq-transport.test.ts +0 -139
  89. package/lib/nl/__test__/nl-parser-openai-parity.test.ts +0 -381
  90. package/lib/nl/__test__/nl-parser-openai-sampling.test.ts +0 -73
  91. package/lib/nl/__test__/nl-parser-openai-transport.test.ts +0 -79
  92. package/lib/nl/__test__/nl-parser-utils.test.ts +0 -98
  93. package/lib/nl/__test__/nl-parser.test.ts +0 -119
  94. package/lib/nl/__test__/parameter-tuning.test.ts +0 -137
  95. package/lib/nl/__test__/semantic-parsing-experiment.test.ts +0 -260
  96. package/lib/nl/context-selector.ts +0 -123
  97. package/lib/nl/index.ts +0 -19
  98. package/lib/nl/llm-monitoring.test.ts +0 -136
  99. package/lib/nl/llm-monitoring.ts +0 -339
  100. package/lib/nl/nl-parser-groq.ts +0 -510
  101. package/lib/nl/nl-parser-utils.ts +0 -310
  102. package/lib/nl/nl-parser.ts +0 -616
  103. package/lib/nl/prompt-gen.ts +0 -607
  104. package/lib/nl/prompt-res.ts +0 -207
  105. package/lib/nl-interpreter.ts +0 -262
@@ -1,762 +0,0 @@
1
- import {
2
- ClassDescriptor,
3
- FieldDescriptor,
4
- FuncDescriptor,
5
- DataClass,
6
- ParamDescriptor,
7
- HelperClass,
8
- } from "../dsl-descriptor";
9
- import { ExampleParse } from "../nl";
10
- import {
11
- float,
12
- GenieClass,
13
- GenieFunction,
14
- GenieKey,
15
- GenieProperty,
16
- int,
17
- LazyType,
18
- } from "../decorators";
19
-
20
- export let recentBooking = null;
21
-
22
- @GenieClass("Representing a date and time")
23
- export class DateTime extends HelperClass {
24
- private _date: Date;
25
-
26
- public year: number;
27
- public month: number;
28
- public day: number;
29
- public dayOfWeek: string;
30
- public hour: number;
31
- public minute: number;
32
-
33
- private updateDate() {
34
- this.year = this._date.getFullYear();
35
- this.month = this._date.getMonth() + 1;
36
- this.day = this._date.getDate();
37
- this.hour = this._date.getHours();
38
- this.minute = this._date.getMinutes();
39
- this.dayOfWeek = this._date.toLocaleDateString("en-US", { weekday: "long" });
40
- }
41
-
42
- static today() {
43
- return DateTime.CreateObject({
44
- year: 2020,
45
- month: 2,
46
- day: 4,
47
- hour: 12,
48
- minute: 0,
49
- });
50
- }
51
-
52
- static sunday = 0;
53
- static monday = 1;
54
- static tuesday = 2;
55
- static wednesday = 3;
56
- static thursday = 4;
57
- static friday = 5;
58
- static saturday = 6;
59
-
60
- static fromDate(date: Date) {
61
- const dt = DateTime.CreateObject({});
62
- dt._date = date;
63
- dt.updateDate();
64
- return dt;
65
- }
66
-
67
- description(): {} {
68
- return {
69
- year: this.year,
70
- month: this.month,
71
- day: this.day,
72
- dayOfWeek: this.dayOfWeek,
73
- hour: this.hour,
74
- minute: this.minute,
75
- };
76
- }
77
-
78
- // custom comparator for sorting
79
-
80
- static compare(a: DateTime, b: DateTime) {
81
- return a._date.getTime() - b._date.getTime();
82
- }
83
-
84
- constructor({
85
- year = undefined,
86
- month = undefined,
87
- day = undefined,
88
- hour = undefined,
89
- minute = undefined,
90
- }: {
91
- year?: number;
92
- month?: number;
93
- day?: number;
94
- hour?: number;
95
- minute?: number;
96
- }) {
97
- super({});
98
- this._date = new Date();
99
- this.setDate({ year, month, day, hour, minute });
100
- }
101
-
102
- _getConstructorParams(): any {
103
- return {
104
- year: this.year,
105
- month: this.month,
106
- day: this.day,
107
- hour: this.hour,
108
- minute: this.minute,
109
- };
110
- }
111
-
112
- addDateOffset({
113
- year = 0,
114
- month = 0,
115
- day = 0,
116
- hour = 0,
117
- minute = 0,
118
- }: {
119
- year: number;
120
- month: number;
121
- day: number;
122
- hour: number;
123
- minute: number;
124
- }) {
125
- this._date.setFullYear(this._date.getFullYear() + year);
126
- this._date.setMonth(this._date.getMonth() + month);
127
- this._date.setDate(this._date.getDate() + day);
128
- this._date.setHours(this._date.getHours() + hour);
129
- this._date.setMinutes(this._date.getMinutes() + minute);
130
- this.updateDate();
131
- return this;
132
- }
133
-
134
- setDate({
135
- year = undefined,
136
- month = undefined,
137
- day = undefined,
138
- hour = undefined,
139
- minute = undefined,
140
- day_of_the_week = undefined,
141
- }: {
142
- year?: number;
143
- month?: number;
144
- day?: number;
145
- hour?: number;
146
- minute?: number;
147
- day_of_the_week?: number;
148
- }) {
149
- if (year !== undefined) {
150
- this._date.setFullYear(year);
151
- }
152
- if (month !== undefined) {
153
- this._date.setMonth(month - 1);
154
- }
155
- if (day !== undefined) {
156
- this._date.setDate(day);
157
- }
158
- if (day_of_the_week !== undefined) {
159
- this._date.setDate(
160
- this._date.getDate() + (day_of_the_week - this._date.getDay())
161
- );
162
- }
163
- if (hour !== undefined) {
164
- this._date.setHours(hour);
165
- }
166
- if (minute !== undefined) {
167
- this._date.setMinutes(minute);
168
- }
169
- this.updateDate();
170
- return this;
171
- }
172
-
173
- toString() {
174
- return `${this.year}-${this.month}-${this.day} ${this.hour}:${this.minute}`;
175
- }
176
-
177
- static _ClassDescriptor = new ClassDescriptor<DateTime>(
178
- "DateTime",
179
- [
180
- new FuncDescriptor(
181
- "addDateOffset",
182
- [
183
- new ParamDescriptor("year", "int"),
184
- new ParamDescriptor("month", "int"),
185
- new ParamDescriptor("day", "int"),
186
- new ParamDescriptor("hour", "int"),
187
- new ParamDescriptor("minute", "int"),
188
- ],
189
- "DateTime",
190
- false,
191
- "Add a date offset to the current date"
192
- ),
193
- new FuncDescriptor(
194
- "constructor",
195
- [
196
- new ParamDescriptor("year", "int", false),
197
- new ParamDescriptor("month", "int", false),
198
- new ParamDescriptor("day", "int", false),
199
- new ParamDescriptor("hour", "int", false),
200
- new ParamDescriptor("minute", "int", false),
201
- ],
202
- "DateTime",
203
- false,
204
- "Create a new date time object"
205
- ),
206
- new FuncDescriptor(
207
- "setDate",
208
- [
209
- new ParamDescriptor("year", "int", false),
210
- new ParamDescriptor("month", "int", false),
211
- new ParamDescriptor("day", "int", false),
212
- new ParamDescriptor("hour", "int", false),
213
- new ParamDescriptor("minute", "int", false),
214
- new ParamDescriptor("day_of_the_week", "int", false),
215
- ],
216
- "DateTime",
217
- false,
218
- "Set the date of the date time object"
219
- ),
220
- new FuncDescriptor(
221
- "today",
222
- [],
223
- "DateTime",
224
- true,
225
- "Get the current date time"
226
- ),
227
- ],
228
- [
229
- new FieldDescriptor("year", "int", false),
230
- new FieldDescriptor("month", "int", false),
231
- new FieldDescriptor("day", "int", false),
232
- new FieldDescriptor("hour", "int", false),
233
- new FieldDescriptor("minute", "int", false),
234
- new FieldDescriptor("dayOfWeek", "string", false),
235
- new FieldDescriptor("sunday", "int", true),
236
- new FieldDescriptor("monday", "int", true),
237
- new FieldDescriptor("tuesday", "int", true),
238
- new FieldDescriptor("wednesday", "int", true),
239
- new FieldDescriptor("thursday", "int", true),
240
- new FieldDescriptor("friday", "int", true),
241
- new FieldDescriptor("saturday", "int", true),
242
- ],
243
- DateTime,
244
- "Representing a date and time"
245
- );
246
- }
247
-
248
- @GenieClass("A food item")
249
- export class Food extends DataClass {
250
- static _all: Food[] = [];
251
-
252
- @GenieFunction("Get all food items")
253
- static all(): Food[] {
254
- return Food._all;
255
- }
256
-
257
- public _price: float;
258
-
259
- @GenieKey
260
- @GenieProperty("Name of the food item")
261
- public name: string;
262
- @GenieProperty("Price of the food item")
263
- public price: float;
264
- @GenieProperty("Restaurant of the food item")
265
- public restaurant: LazyType<Restaurant>;
266
-
267
- constructor({
268
- name,
269
- price,
270
- restaurant,
271
- }: {
272
- name: string;
273
- price: float;
274
- restaurant: LazyType<Restaurant>;
275
- }) {
276
- super({});
277
- this.name = name;
278
- this._price = price;
279
- this.restaurant = restaurant;
280
- Food._all.push(this);
281
- }
282
-
283
- async update() {
284
- await new Promise((resolve) => {
285
- setTimeout(() => {
286
- resolve(void 0);
287
- }, 10);
288
- });
289
- this.price = this._price;
290
- }
291
-
292
- description(): {} {
293
- return {
294
- name: this.name,
295
- price: this.price,
296
- restaurant: this.restaurant.name,
297
- };
298
- }
299
-
300
- static _ClassDescriptor = new ClassDescriptor<Food>(
301
- "Food",
302
- [new FuncDescriptor("all", [], "Food[]", true, "All foods"),
303
- new FuncDescriptor("All", [], "Food[]", true, "")
304
- ],
305
-
306
- [
307
- new FieldDescriptor("name", "string", false),
308
- new FieldDescriptor("price", "float", false),
309
- new FieldDescriptor(
310
- "restaurant",
311
- "Restaurant",
312
- false,
313
- "The restaurant this food is served at"
314
- ),
315
- ],
316
- Food,
317
- "A food item"
318
- );
319
- }
320
-
321
- @GenieClass("An Order")
322
- export class Order extends DataClass {
323
- static _all: Order[] = [];
324
- @GenieFunction("Get all orders")
325
- static all(): Order[] {
326
- return Order._all;
327
- }
328
-
329
- static _current: Order = undefined;
330
-
331
- @GenieFunction("Get the current order")
332
- static async current(): Promise<Order> {
333
- if (this._current === undefined) {
334
- this._current = Order.CreateObject({
335
- orderId: (Order.all().length + 1).toString(),
336
- dateTime: DateTime.fromDate(new Date()),
337
- foods: [],
338
- restaurant: await Restaurant.current(),
339
- });
340
- }
341
- return this._current;
342
- }
343
-
344
- @GenieKey
345
- @GenieProperty("Order ID number")
346
- public orderId: string;
347
- @GenieProperty("Time that order is placed")
348
- public dateTime: DateTime;
349
- @GenieProperty("Foods in the order")
350
- public foods: Food[];
351
- @GenieProperty("Restaurant of the order")
352
- public restaurant: LazyType<Restaurant>;
353
-
354
- constructor({
355
- orderId,
356
- dateTime,
357
- foods,
358
- restaurant,
359
- }: {
360
- orderId: string;
361
- dateTime: DateTime;
362
- foods: Food[];
363
- restaurant: LazyType<Restaurant> | null;
364
- }) {
365
- super({ orderId: orderId });
366
- this.orderId = (Order.all().length + 1).toString();
367
- this.dateTime = dateTime;
368
- this.foods = foods;
369
- this.restaurant = restaurant;
370
- Order._all.push(this);
371
- }
372
-
373
- @GenieFunction("Add foods to the order")
374
- addFoods({ foods }: { foods: Food[] }): void {
375
- this.foods.push(...foods);
376
- }
377
-
378
- @GenieFunction("Remove foods from the order")
379
- removeFoods({ foods }: { foods: Food[] }): void {
380
- this.foods = this.foods.filter((f) => !foods.includes(f));
381
- }
382
-
383
- @GenieFunction("Place the order")
384
- placeOrder(): void {
385
- this.restaurant.orders.push(this);
386
- }
387
-
388
- description(): {} {
389
- return {
390
- dateTime: this.dateTime.toString(),
391
- foods: this.foods.map((f) => f.name),
392
- restaurant: this.restaurant.name,
393
- };
394
- }
395
-
396
- static _ClassDescriptor = new ClassDescriptor<Order>(
397
- "Order",
398
- [
399
- new FuncDescriptor(
400
- "addFoods",
401
- [new ParamDescriptor("foods", "Food[]")],
402
- "void",
403
- false,
404
- "Add a list of foods to the order"
405
- ),
406
- new FuncDescriptor(
407
- "removeFoods",
408
- [new ParamDescriptor("foods", "Food[]")],
409
- "void",
410
- false,
411
- "Remove a list of foods from the order"
412
- ),
413
- new FuncDescriptor("placeOrder", [], "void", false, "Place the order"),
414
- new FuncDescriptor("current", [], "Order", true, "The current order"),
415
- new FuncDescriptor("all", [], "Order[]", true, "All past orders"),
416
- new FuncDescriptor("All", [], "Order[]", true, ""),
417
-
418
- ],
419
- [
420
- new FieldDescriptor("orderId", "string", false),
421
- new FieldDescriptor("dateTime", "DateTime", false),
422
- new FieldDescriptor("foods", "Food[]", false),
423
- new FieldDescriptor("restaurant", "Restaurant", false),
424
- ],
425
- Order,
426
- "An Order"
427
- );
428
- }
429
-
430
- @GenieClass("A restaurant")
431
- export class Restaurant extends DataClass {
432
- static _all: Restaurant[] = undefined;
433
- @GenieProperty("Past orders of the restaurant")
434
- public orders: Order[] = [];
435
-
436
- @GenieFunction("Get all restaurants")
437
- static all(): Restaurant[] {
438
- if (this._all === undefined) {
439
- const mcDonald = Restaurant.CreateObject({
440
- name: "McDonald's",
441
- menu: [],
442
- rating: 4,
443
- priceGrade: 2,
444
- cuisine: "Fast Food",
445
- address: "123 Main St, Mountain view, USA",
446
- });
447
- const kfc = Restaurant.CreateObject({
448
- name: "KFC",
449
- menu: [],
450
- rating: 3,
451
- priceGrade: 1,
452
- cuisine: "Fast Food",
453
- address: "123 Main St, Palo Alto, USA",
454
- });
455
- const pizzaHut = Restaurant.CreateObject({
456
- name: "Pizza Hut",
457
- menu: [],
458
- rating: 4,
459
- priceGrade: 2,
460
- cuisine: "Fast Food",
461
- address: "123 Main St, Palo Alto, USA",
462
- });
463
- const burgerKing = Restaurant.CreateObject({
464
- name: "Burger King",
465
- menu: [],
466
- rating: 4,
467
- priceGrade: 2,
468
- cuisine: "Fast Food",
469
- address: "123 Main St, Mountain View, USA",
470
- });
471
- const taste = Restaurant.CreateObject({
472
- name: "Taste",
473
- menu: [],
474
- rating: 5,
475
- priceGrade: 3,
476
- cuisine: "Chinese",
477
- address: "123 Main St, Palo Alto, USA",
478
- });
479
- const orensHummus = Restaurant.CreateObject({
480
- name: "Oren's Hummus",
481
- menu: [],
482
- rating: 4,
483
- priceGrade: 2,
484
- cuisine: "Middle Eastern",
485
- address: "123 Main St, Mountain View, USA",
486
- });
487
- const steam = Restaurant.CreateObject({
488
- name: "Steam",
489
- menu: [],
490
- rating: 4,
491
- priceGrade: 2,
492
- cuisine: "Chinese",
493
- address: "123 Main St, Palo Alto, USA",
494
- });
495
-
496
- mcDonald.createFood("Hamburger", 5);
497
- mcDonald.createFood("Cheeseburger", 6);
498
- mcDonald.createFood("McFlurry", 3);
499
- mcDonald.createFood("McChicken", 4);
500
- mcDonald.createFood("McDouble", 4);
501
- mcDonald.createFood("Coca Cola Coke", 2);
502
- mcDonald.createOrder(
503
- (Order.all().length + 1).toString(),
504
- DateTime.CreateObject({
505
- year: 2020,
506
- month: 1,
507
- day: 1,
508
- hour: 12,
509
- minute: 0,
510
- }),
511
- [mcDonald.menu[0], mcDonald.menu[1]]
512
- );
513
- mcDonald.createOrder(
514
- (Order.all().length + 1).toString(),
515
- DateTime.CreateObject({
516
- year: 2020,
517
- month: 2,
518
- day: 1,
519
- hour: 13,
520
- minute: 0,
521
- }),
522
- [mcDonald.menu[2], mcDonald.menu[3]]
523
- );
524
- mcDonald.createOrder(
525
- (Order.all().length + 1).toString(),
526
- DateTime.CreateObject({
527
- year: 2020,
528
- month: 2,
529
- day: 3,
530
- hour: 14,
531
- minute: 0,
532
- }),
533
- [mcDonald.menu[4], mcDonald.menu[5]]
534
- );
535
-
536
- kfc.createFood("Chicken", 5);
537
- kfc.createFood("Fries", 2);
538
- kfc.createFood("Pepsi Coke", 2);
539
- kfc.createOrder(
540
- (Order.all().length + 1).toString(),
541
- DateTime.CreateObject({
542
- year: 2020,
543
- month: 1,
544
- day: 4,
545
- hour: 15,
546
- minute: 0,
547
- }),
548
- [kfc.menu[0], kfc.menu[1]]
549
- );
550
-
551
- this._all = [
552
- mcDonald,
553
- kfc,
554
- pizzaHut,
555
- burgerKing,
556
- taste,
557
- orensHummus,
558
- steam,
559
- ];
560
- }
561
- return this._all;
562
- }
563
-
564
- description(): {} {
565
- return {
566
- name: this.name,
567
- cuisine: this.cuisine,
568
- rating: this.rating,
569
- priceGrade: this.priceGrade,
570
- address: this.address,
571
- };
572
- }
573
-
574
- createFood(name: string, price: float) {
575
- const food: Food = Food.CreateObject({ name, price, restaurant: this });
576
- this.menu.push(food);
577
- return food;
578
- }
579
-
580
- async createOrder(orderId: string, dateTime: DateTime, foods: Food[]) {
581
- const order = Order.CreateObject({
582
- orderId,
583
- dateTime,
584
- foods,
585
- restaurant: this,
586
- });
587
- this.orders.push(order);
588
- return new Promise<Order>((resolve) => {
589
- setTimeout(() => {
590
- resolve(order);
591
- }, 10);
592
- });
593
- }
594
-
595
- @GenieFunction("Get the current restaurant")
596
- static async current(): Promise<Restaurant> {
597
- await new Promise((resolve) => {
598
- setTimeout(() => {
599
- resolve(void 0);
600
- }, 10);
601
- });
602
- return this.all()[0];
603
- }
604
-
605
- @GenieFunction("Book a table for a given date time")
606
- book({ dateTime = DateTime.today() }: { dateTime?: DateTime }): void {
607
- console.log(`${this.name} is booking for ${dateTime.toString()}`);
608
- recentBooking = `${this.name} is booking for ${dateTime.toString()}`;
609
- }
610
-
611
- @GenieFunction("Book numbers tables for a given date time")
612
- bookTable({ dateTime = undefined, number }: { dateTime?: DateTime, number?: int }): void {
613
- if (dateTime === undefined) {
614
- dateTime = DateTime.today();
615
- }
616
- if (number === undefined) {
617
- number = 1;
618
- }
619
- console.log(`${this.name} is booking ${number} tables for ${dateTime.toString()}`);
620
- recentBooking = `${this.name} is booking ${number} tables for ${dateTime.toString()}`;
621
- }
622
-
623
- @GenieKey
624
- @GenieProperty("Name of the restaurant")
625
- public name: string;
626
- @GenieProperty("Menu of the restaurant")
627
- public menu: Food[];
628
- @GenieProperty("Rating of the restaurant")
629
- public rating: int;
630
- @GenieProperty("Price grade of the restaurant")
631
- public priceGrade: float;
632
- @GenieProperty("Cuisine of the restaurant")
633
- public cuisine: string;
634
- @GenieProperty("Address of the restaurant")
635
- public address: string;
636
-
637
- constructor({
638
- name,
639
- menu,
640
- rating = 0,
641
- priceGrade = 0,
642
- cuisine = "",
643
- address = "",
644
- }: {
645
- name: string;
646
- menu: Food[];
647
- rating: number;
648
- priceGrade: number;
649
- cuisine: string;
650
- address: string;
651
- }) {
652
- super({ name: name });
653
- this.name = name;
654
- this.menu = menu;
655
- this.rating = rating;
656
- this.priceGrade = priceGrade;
657
- this.cuisine = cuisine;
658
- this.address = address;
659
- }
660
-
661
- static _ClassDescriptor = new ClassDescriptor<Restaurant>(
662
- "Restaurant",
663
- [
664
- new FuncDescriptor(
665
- "all",
666
- [],
667
- "Restaurant[]",
668
- true,
669
- "All active restaurants"
670
- ),
671
- new FuncDescriptor(
672
- "All",
673
- [],
674
- "Restaurant[]",
675
- true,
676
- "All active restaurants"
677
- ),
678
- new FuncDescriptor(
679
- "current",
680
- [],
681
- "Restaurant",
682
- true,
683
- "The current restaurant"
684
- ),
685
- new FuncDescriptor(
686
- "book",
687
- [new ParamDescriptor("dateTime", "DateTime", false, "DateTime.today()")],
688
- "void",
689
- false,
690
- "Book a table for a given date time"
691
- ),
692
- new FuncDescriptor(
693
- "bookTable",
694
- [
695
- new ParamDescriptor("dateTime", "DateTime", false, null),
696
- new ParamDescriptor("number", "int", false, null)
697
- ],
698
- "void",
699
- false,
700
- "Book numbers tables for a given date time"
701
- ),
702
- ],
703
- [
704
- new FieldDescriptor("name", "string", false),
705
- new FieldDescriptor("menu", "Food[]", false),
706
- new FieldDescriptor("rating", "int", false),
707
- new FieldDescriptor("priceGrade", "float", false),
708
- new FieldDescriptor("cuisine", "string", false),
709
- new FieldDescriptor("address", "string", false),
710
- new FieldDescriptor("orders", "Order[]", false),
711
- ],
712
- Restaurant,
713
- "A restaurant"
714
- );
715
- }
716
-
717
- export const allDescriptors = [
718
- Restaurant.ClassDescriptor,
719
- Food.ClassDescriptor,
720
- Order.ClassDescriptor,
721
- DateTime._ClassDescriptor,
722
- ];
723
-
724
- export const classDescriptions = allDescriptors.map((d) => d.description());
725
-
726
- export const examples: ExampleParse[] = [
727
- {
728
- user_utterance: "get me the best restaurant in palo alto",
729
- example_parsed:
730
- 'Restaurant.all().matching(field: .address, value: "palo alto").sort(field: .rating, ascending: false)[0]',
731
- },
732
- {
733
- user_utterance:
734
- "get me the least expensive restaurant that serves chinese food",
735
- example_parsed:
736
- 'Restaurant.all().matching(field: .cuisine, value: "chinese").sort(field: .price, ascending: true)[0]',
737
- },
738
- {
739
- user_utterance: "add hamburger to the order",
740
- example_parsed:
741
- 'Order.current().addFoods(foods: [Restaurant.current().menu.matching(field: .name, value: "hamburger")[0]])',
742
- },
743
- {
744
- user_utterance: "remove hamburger from the order",
745
- example_parsed:
746
- 'Order.current().removeFoods(foods: Order.current().foods.matching(field: .name, value: "hamburger"))',
747
- },
748
- {
749
- user_utterance: "what do I have in my order",
750
- example_parsed: "Order.current().foods",
751
- },
752
- {
753
- user_utterance: "what did I ordered at mcDonald last time?",
754
- example_parsed:
755
- 'Order.all().matching(field: .restaurant, value: Restaurant.all().matching(field: .name, value: "mcDonald")[0]).sort(field: .dateTime, ascending: false)[0].foods\n',
756
- },
757
- {
758
- user_utterance: "what's my recent order with a milkshake?",
759
- example_parsed:
760
- 'Order.all().contains(field: .foods, value: Food.all().matching(field: .name, value: "milkshake")[0]).sort(field: .dateTime, ascending: false)[0]',
761
- },
762
- ];