@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.
- package/.env +10 -0
- package/.env.example +17 -0
- package/.github/workflows/publish.yml +20 -0
- package/README.md +5 -1
- package/package.json +1 -5
- package/dist/__test__/dsl-descriptor.test.d.ts +0 -1
- package/dist/__test__/dsl-descriptor.test.js +0 -27
- package/dist/__test__/dsl-descriptor.test.js.map +0 -1
- package/dist/__test__/example_descriptor.d.ts +0 -125
- package/dist/__test__/example_descriptor.js +0 -607
- package/dist/__test__/example_descriptor.js.map +0 -1
- package/dist/__test__/food_descriptor.state.json +0 -1
- package/dist/__test__/food_descriptor.test.d.ts +0 -74
- package/dist/__test__/food_descriptor.test.js +0 -205
- package/dist/__test__/food_descriptor.test.js.map +0 -1
- package/dist/__test__/nl-interpreter-provider-selection.test.d.ts +0 -1
- package/dist/__test__/nl-interpreter-provider-selection.test.js +0 -73
- package/dist/__test__/nl-interpreter-provider-selection.test.js.map +0 -1
- package/dist/__test__/nl-interpreter.test.d.ts +0 -1
- package/dist/__test__/nl-interpreter.test.js +0 -86
- package/dist/__test__/nl-interpreter.test.js.map +0 -1
- package/dist/decorators/__test__/decorators.test.d.ts +0 -1
- package/dist/decorators/__test__/decorators.test.js +0 -182
- package/dist/decorators/__test__/decorators.test.js.map +0 -1
- package/dist/decorators/__test__/inheritance-descriptor.test.d.ts +0 -1
- package/dist/decorators/__test__/inheritance-descriptor.test.js +0 -107
- package/dist/decorators/__test__/inheritance-descriptor.test.js.map +0 -1
- package/dist/dsl/__test__/dsl-interpreter.test.d.ts +0 -1
- package/dist/dsl/__test__/dsl-interpreter.test.js +0 -334
- package/dist/dsl/__test__/dsl-interpreter.test.js.map +0 -1
- package/dist/dsl/__test__/parser.gen.test.d.ts +0 -1
- package/dist/dsl/__test__/parser.gen.test.js +0 -283
- package/dist/dsl/__test__/parser.gen.test.js.map +0 -1
- package/dist/nl/__test__/context-aware-prompt.test.d.ts +0 -1
- package/dist/nl/__test__/context-aware-prompt.test.js +0 -247
- package/dist/nl/__test__/context-aware-prompt.test.js.map +0 -1
- package/dist/nl/__test__/context-selector.test.d.ts +0 -1
- package/dist/nl/__test__/context-selector.test.js +0 -20
- package/dist/nl/__test__/context-selector.test.js.map +0 -1
- package/dist/nl/__test__/nl-parser-groq-transport.test.d.ts +0 -1
- package/dist/nl/__test__/nl-parser-groq-transport.test.js +0 -87
- package/dist/nl/__test__/nl-parser-groq-transport.test.js.map +0 -1
- package/dist/nl/__test__/nl-parser-openai-parity.test.d.ts +0 -1
- package/dist/nl/__test__/nl-parser-openai-parity.test.js +0 -206
- package/dist/nl/__test__/nl-parser-openai-parity.test.js.map +0 -1
- package/dist/nl/__test__/nl-parser-openai-sampling.test.d.ts +0 -1
- package/dist/nl/__test__/nl-parser-openai-sampling.test.js +0 -44
- package/dist/nl/__test__/nl-parser-openai-sampling.test.js.map +0 -1
- package/dist/nl/__test__/nl-parser-openai-transport.test.d.ts +0 -1
- package/dist/nl/__test__/nl-parser-openai-transport.test.js +0 -55
- package/dist/nl/__test__/nl-parser-openai-transport.test.js.map +0 -1
- package/dist/nl/__test__/nl-parser-utils.test.d.ts +0 -1
- package/dist/nl/__test__/nl-parser-utils.test.js +0 -70
- package/dist/nl/__test__/nl-parser-utils.test.js.map +0 -1
- package/dist/nl/__test__/nl-parser.test.d.ts +0 -1
- package/dist/nl/__test__/nl-parser.test.js +0 -64
- package/dist/nl/__test__/nl-parser.test.js.map +0 -1
- package/dist/nl/__test__/parameter-tuning.test.d.ts +0 -1
- package/dist/nl/__test__/parameter-tuning.test.js +0 -95
- package/dist/nl/__test__/parameter-tuning.test.js.map +0 -1
- package/dist/nl/__test__/semantic-parsing-experiment.test.d.ts +0 -1
- package/dist/nl/__test__/semantic-parsing-experiment.test.js +0 -178
- package/dist/nl/__test__/semantic-parsing-experiment.test.js.map +0 -1
- package/dist/nl/llm-monitoring.test.d.ts +0 -5
- package/dist/nl/llm-monitoring.test.js +0 -101
- package/dist/nl/llm-monitoring.test.js.map +0 -1
- package/lib/__test__/dsl-descriptor.test.ts +0 -27
- package/lib/__test__/example_descriptor.ts +0 -762
- package/lib/__test__/food_descriptor.state.json +0 -1
- package/lib/__test__/food_descriptor.test.ts +0 -331
- package/lib/__test__/nl-interpreter-provider-selection.test.ts +0 -126
- package/lib/__test__/nl-interpreter.test.ts +0 -129
- package/lib/decorators/__test__/decorators.test.ts +0 -177
- package/lib/decorators/__test__/inheritance-descriptor.test.ts +0 -92
- package/lib/decorators/decorators.ts +0 -754
- package/lib/decorators/index.ts +0 -2
- package/lib/decorators/store.ts +0 -47
- package/lib/dsl/__test__/dsl-interpreter.test.ts +0 -453
- package/lib/dsl/__test__/parser.gen.test.ts +0 -296
- package/lib/dsl/dsl-interpreter.ts +0 -974
- package/lib/dsl/index.ts +0 -1
- package/lib/dsl/parser.gen.js +0 -1479
- package/lib/dsl/parser.pegjs +0 -130
- package/lib/dsl-descriptor.ts +0 -241
- package/lib/index.ts +0 -5
- package/lib/nl/__test__/context-aware-prompt.test.ts +0 -372
- package/lib/nl/__test__/context-selector.test.ts +0 -27
- package/lib/nl/__test__/nl-parser-groq-transport.test.ts +0 -139
- package/lib/nl/__test__/nl-parser-openai-parity.test.ts +0 -381
- package/lib/nl/__test__/nl-parser-openai-sampling.test.ts +0 -73
- package/lib/nl/__test__/nl-parser-openai-transport.test.ts +0 -79
- package/lib/nl/__test__/nl-parser-utils.test.ts +0 -98
- package/lib/nl/__test__/nl-parser.test.ts +0 -119
- package/lib/nl/__test__/parameter-tuning.test.ts +0 -137
- package/lib/nl/__test__/semantic-parsing-experiment.test.ts +0 -260
- package/lib/nl/context-selector.ts +0 -123
- package/lib/nl/index.ts +0 -19
- package/lib/nl/llm-monitoring.test.ts +0 -136
- package/lib/nl/llm-monitoring.ts +0 -339
- package/lib/nl/nl-parser-groq.ts +0 -510
- package/lib/nl/nl-parser-utils.ts +0 -310
- package/lib/nl/nl-parser.ts +0 -616
- package/lib/nl/prompt-gen.ts +0 -607
- package/lib/nl/prompt-res.ts +0 -207
- package/lib/nl-interpreter.ts +0 -262
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import "../decorators";
|
|
2
|
-
import * as assert from "assert";
|
|
3
|
-
import {
|
|
4
|
-
ClassDescriptor,
|
|
5
|
-
FieldDescriptor,
|
|
6
|
-
FuncDescriptor,
|
|
7
|
-
DataClass, HelperClass, GenieObject
|
|
8
|
-
} from "../../dsl-descriptor";
|
|
9
|
-
import {GenieClass, GenieKey, GenieProperty, initGenie} from "../decorators";
|
|
10
|
-
import {
|
|
11
|
-
DateTime,
|
|
12
|
-
Food,
|
|
13
|
-
Order,
|
|
14
|
-
Restaurant,
|
|
15
|
-
} from "../../__test__/example_descriptor";
|
|
16
|
-
import {genieDispatch} from "../store";
|
|
17
|
-
|
|
18
|
-
initGenie();
|
|
19
|
-
|
|
20
|
-
function essentialFuncDescriptor(original: FuncDescriptor) {
|
|
21
|
-
return {
|
|
22
|
-
name: original.func_name,
|
|
23
|
-
// comment: original.comment, // don't compare comments
|
|
24
|
-
params: original.parameters,
|
|
25
|
-
returnType: original.returnType,
|
|
26
|
-
isStatic: original.isStatic,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function essentialFieldDescriptor(original: FieldDescriptor) {
|
|
31
|
-
return {
|
|
32
|
-
name: original.field,
|
|
33
|
-
// comment: original.comment, // don't compare comments
|
|
34
|
-
type: original.fieldType,
|
|
35
|
-
isStatic: original.isStatic,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function sortDescriptor(a: { name: string }, b: { name: string }) {
|
|
40
|
-
return a.name.localeCompare(b.name);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function compareClassDescriptor(
|
|
44
|
-
a: ClassDescriptor<GenieObject>,
|
|
45
|
-
b: ClassDescriptor<GenieObject>
|
|
46
|
-
) {
|
|
47
|
-
assert.equal(a.className, b.className);
|
|
48
|
-
assert.equal(a.classConstructor, b.classConstructor);
|
|
49
|
-
assert.equal(a.functions.size, b.functions.size);
|
|
50
|
-
assert.equal(a.fields.size, b.fields.size);
|
|
51
|
-
expect(
|
|
52
|
-
Array.from(a.functions).map(essentialFuncDescriptor).sort(sortDescriptor)
|
|
53
|
-
).toEqual(
|
|
54
|
-
Array.from(b.functions).map(essentialFuncDescriptor).sort(sortDescriptor)
|
|
55
|
-
);
|
|
56
|
-
expect(
|
|
57
|
-
Array.from(a.fields).map(essentialFieldDescriptor).sort(sortDescriptor)
|
|
58
|
-
).toEqual(
|
|
59
|
-
Array.from(b.fields).map(essentialFieldDescriptor).sort(sortDescriptor)
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
test("Restaurant Descriptor", async () => {
|
|
63
|
-
compareClassDescriptor(
|
|
64
|
-
Restaurant.ClassDescriptor,
|
|
65
|
-
Restaurant._ClassDescriptor
|
|
66
|
-
);
|
|
67
|
-
Restaurant.all();
|
|
68
|
-
const restaurant1 = Restaurant.GetObject({ name: "McDonald's" });
|
|
69
|
-
const restaurant2 = Restaurant.GetObject({ name: "McDonald's" });
|
|
70
|
-
restaurant2.rating = 5;
|
|
71
|
-
assert.equal(restaurant1.rating, 5);
|
|
72
|
-
restaurant2.rating = 3;
|
|
73
|
-
assert.equal(restaurant1.rating, 3);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test("Food Descriptor", async () => {
|
|
77
|
-
console.log("Food descriptor", Food.ClassDescriptor);
|
|
78
|
-
console.log("Food descriptor", Food._ClassDescriptor);
|
|
79
|
-
compareClassDescriptor(Food.ClassDescriptor, Food._ClassDescriptor);
|
|
80
|
-
Restaurant.all();
|
|
81
|
-
Food.all();
|
|
82
|
-
const foodItem1 = Food.GetObject({ name: "Hamburger" });
|
|
83
|
-
const foodItem2 = Food.GetObject({ name: "Hamburger" });
|
|
84
|
-
foodItem2.price = 6.99;
|
|
85
|
-
assert.equal(foodItem1.price, 6.99);
|
|
86
|
-
foodItem2.price = 5.99;
|
|
87
|
-
assert.equal(foodItem1.price, 5.99);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
test("Order Descriptor", async () => {
|
|
91
|
-
compareClassDescriptor(Order.ClassDescriptor, Order._ClassDescriptor);
|
|
92
|
-
Restaurant.all();
|
|
93
|
-
Order.all();
|
|
94
|
-
const order1 = Order.GetObject({ orderId: 1 });
|
|
95
|
-
const order2 = Order.GetObject({ orderId: 1 });
|
|
96
|
-
order2.dateTime = DateTime.CreateObject({
|
|
97
|
-
year: 2023,
|
|
98
|
-
month: 1,
|
|
99
|
-
day: 1,
|
|
100
|
-
hour: 13,
|
|
101
|
-
minute: 0,
|
|
102
|
-
});
|
|
103
|
-
assert.equal(
|
|
104
|
-
order1.dateTime.toString(),
|
|
105
|
-
new DateTime({
|
|
106
|
-
year: 2023,
|
|
107
|
-
month: 1,
|
|
108
|
-
day: 1,
|
|
109
|
-
hour: 13,
|
|
110
|
-
minute: 0,
|
|
111
|
-
}).toString()
|
|
112
|
-
);
|
|
113
|
-
order2.dateTime = DateTime.CreateObject({
|
|
114
|
-
year: 2023,
|
|
115
|
-
month: 1,
|
|
116
|
-
day: 2,
|
|
117
|
-
hour: 13,
|
|
118
|
-
minute: 0,
|
|
119
|
-
});
|
|
120
|
-
assert.equal(
|
|
121
|
-
order1.dateTime.toString(),
|
|
122
|
-
new DateTime({
|
|
123
|
-
year: 2023,
|
|
124
|
-
month: 1,
|
|
125
|
-
day: 2,
|
|
126
|
-
hour: 13,
|
|
127
|
-
minute: 0,
|
|
128
|
-
}).toString()
|
|
129
|
-
);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
@GenieClass("To-do list item")
|
|
133
|
-
class TodoListItem extends HelperClass {
|
|
134
|
-
@GenieProperty("Name of the item")
|
|
135
|
-
name: string;
|
|
136
|
-
@GenieProperty("Whether the item is done")
|
|
137
|
-
done: boolean;
|
|
138
|
-
|
|
139
|
-
constructor({name, done}: {name: string, done: boolean}) {
|
|
140
|
-
super({});
|
|
141
|
-
this.name = name;
|
|
142
|
-
this.done = done;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
@GenieClass("To-do list")
|
|
147
|
-
class TodoList extends DataClass {
|
|
148
|
-
@GenieKey
|
|
149
|
-
@GenieProperty("Name of the list")
|
|
150
|
-
name: string;
|
|
151
|
-
@GenieProperty("Items in the list")
|
|
152
|
-
items: TodoListItem[];
|
|
153
|
-
|
|
154
|
-
constructor({name, items}: {name: string, items: TodoListItem[]}) {
|
|
155
|
-
super({});
|
|
156
|
-
this.name = name;
|
|
157
|
-
this.items = items;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
static setup() {
|
|
161
|
-
TodoList.CreateObject({name: "Groceries", items: [
|
|
162
|
-
TodoListItem.CreateObject({name: "Milk", done: false}),
|
|
163
|
-
TodoListItem.CreateObject({name: "Eggs", done: false}),
|
|
164
|
-
TodoListItem.CreateObject({name: "Bread", done: false}),
|
|
165
|
-
]});
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
test("Change TodoList", async () => {
|
|
170
|
-
genieDispatch(() => {
|
|
171
|
-
const groceriesList = TodoList.GetObject({ name: "Groceries" });
|
|
172
|
-
const item = groceriesList.items[0];
|
|
173
|
-
item.done = true;
|
|
174
|
-
const groceriesListItems = groceriesList.items;
|
|
175
|
-
groceriesListItems.push(TodoListItem.CreateObject({name: "Butter", done: false}));
|
|
176
|
-
});
|
|
177
|
-
});
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import "..";
|
|
2
|
-
import { GenieClass, GenieFunction, GenieProperty } from "..";
|
|
3
|
-
import { HelperClass } from "../../dsl-descriptor";
|
|
4
|
-
|
|
5
|
-
@GenieClass("Parent helper")
|
|
6
|
-
class ParentHelper extends HelperClass {
|
|
7
|
-
@GenieProperty("Parent field")
|
|
8
|
-
parentField: string;
|
|
9
|
-
|
|
10
|
-
constructor({ parentField = "parent" }: { parentField?: string } = {}) {
|
|
11
|
-
super({});
|
|
12
|
-
this.parentField = parentField;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
@GenieFunction("Parent instance method")
|
|
16
|
-
parentInstance(): ParentHelper {
|
|
17
|
-
return this;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
@GenieFunction("Parent static method")
|
|
21
|
-
static parentStatic(): ParentHelper {
|
|
22
|
-
return ParentHelper.CreateObject({ parentField: "from-parent-static" });
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
@GenieClass("Child helper")
|
|
27
|
-
class ChildHelper extends ParentHelper {
|
|
28
|
-
@GenieProperty("Child field")
|
|
29
|
-
childField: string;
|
|
30
|
-
|
|
31
|
-
constructor({
|
|
32
|
-
parentField = "parent",
|
|
33
|
-
childField = "child",
|
|
34
|
-
}: {
|
|
35
|
-
parentField?: string;
|
|
36
|
-
childField?: string;
|
|
37
|
-
} = {}) {
|
|
38
|
-
super({ parentField });
|
|
39
|
-
this.childField = childField;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
@GenieFunction("Child instance method")
|
|
43
|
-
childInstance(): ChildHelper {
|
|
44
|
-
return this;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
@GenieFunction("Child static method")
|
|
48
|
-
static childStatic(): ChildHelper {
|
|
49
|
-
return ChildHelper.CreateObject({
|
|
50
|
-
parentField: "from-child-static",
|
|
51
|
-
childField: "from-child-static",
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
describe("Genie descriptor inheritance isolation", () => {
|
|
57
|
-
test("creates an own ClassDescriptor for subclass and keeps parent descriptor clean", () => {
|
|
58
|
-
expect(Object.prototype.hasOwnProperty.call(ParentHelper, "ClassDescriptor")).toBe(true);
|
|
59
|
-
expect(Object.prototype.hasOwnProperty.call(ChildHelper, "ClassDescriptor")).toBe(true);
|
|
60
|
-
|
|
61
|
-
expect(ParentHelper.ClassDescriptor.className).toBe("ParentHelper");
|
|
62
|
-
expect(ChildHelper.ClassDescriptor.className).toBe("ChildHelper");
|
|
63
|
-
|
|
64
|
-
const parentFunctions = Array.from(ParentHelper.ClassDescriptor.functions).map(
|
|
65
|
-
(func: any) => func.func_name
|
|
66
|
-
);
|
|
67
|
-
expect(parentFunctions).toContain("parentInstance");
|
|
68
|
-
expect(parentFunctions).toContain("parentStatic");
|
|
69
|
-
expect(parentFunctions).not.toContain("childInstance");
|
|
70
|
-
expect(parentFunctions).not.toContain("childStatic");
|
|
71
|
-
|
|
72
|
-
const childFunctions = Array.from(ChildHelper.ClassDescriptor.functions).map(
|
|
73
|
-
(func: any) => func.func_name
|
|
74
|
-
);
|
|
75
|
-
expect(childFunctions).toContain("parentInstance");
|
|
76
|
-
expect(childFunctions).toContain("parentStatic");
|
|
77
|
-
expect(childFunctions).toContain("childInstance");
|
|
78
|
-
expect(childFunctions).toContain("childStatic");
|
|
79
|
-
|
|
80
|
-
const parentFields = Array.from(ParentHelper.ClassDescriptor.fields).map(
|
|
81
|
-
(field: any) => field.field
|
|
82
|
-
);
|
|
83
|
-
expect(parentFields).toContain("parentField");
|
|
84
|
-
expect(parentFields).not.toContain("childField");
|
|
85
|
-
|
|
86
|
-
const childFields = Array.from(ChildHelper.ClassDescriptor.fields).map(
|
|
87
|
-
(field: any) => field.field
|
|
88
|
-
);
|
|
89
|
-
expect(childFields).toContain("parentField");
|
|
90
|
-
expect(childFields).toContain("childField");
|
|
91
|
-
});
|
|
92
|
-
});
|