-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
136 lines (107 loc) · 3.03 KB
/
test.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
const { dirname } = require('path');
const __root = dirname(require.main.filename);
const { Chat: ChatModel } = require('./models');
const DefaultDataset = require(`${__root}/training/datasets/Default`);
const ParisDataset = require(`${__root}/training/datasets/Paris`);
const delay = ms => new Promise(res => setTimeout(res, ms));
// Run the chat model with a saved dataset
const withDataset = async (dataset, questions) => {
const agent = await ChatModel({
dataset
});
for (const question of questions) {
// Log chat response
console.log(
'\x1b[35m',
'\n\nASK >>\n\n',
`\x1b[32m Question: ${question}\n`,
`\x1b[36m Answer: ${agent.ask(question)}\n\n`,
'\x1b[0m'
);
await delay(3000);
}
};
// Run the chat model from the default bootstrap
const withBootstrap = async questions => {
// Bootstrap with a default dataset
const agent = await ChatModel({
bootstrap: true
});
for (const question of questions) {
// Log chat response
console.log(
'\x1b[35m',
'\n\nASK >>\n\n',
`\x1b[32m Question: ${question}\n`,
`\x1b[36m Answer: ${agent.ask(question)}\n\n`,
'\x1b[0m'
);
await delay(3000);
}
};
// Run the chat model with a new dataset from files
const withFiles = async (files, questions) => {
const agent = await ChatModel({
files
});
for (const question of questions) {
// Log chat response
console.log(
'\x1b[35m',
'\n\nASK >>\n\n',
`\x1b[32m Question: ${question}\n`,
`\x1b[36m Answer: ${agent.ask(question)}\n\n`,
'\x1b[0m'
);
await delay(3000);
}
};
const runTests = async () => {
// Unit: Run different chat prompts in isolation
// with different datasets
console.log(
'\x1b[35m',
'\n\nDATASET: "Default"\n\n',
'\x1b[0m'
);
await withDataset(DefaultDataset, [
"What is something unique about the tuatara?",
"tell me about london",
"what am I doing?",
"identify John",
"what could he have done?"
]);
console.log(
'\x1b[35m',
'\n\nDATASET: "Paris"\n\n',
'\x1b[0m'
);
await withDataset(ParisDataset, [
"where is Paris?",
"what is paris home to",
"talk to me about paris",
"what is Paris known for?",
"what is paris famous for",
"what is Paris the capital of?",
"what was Paris the capital of?",
"where is London",
"What is Paris surrounded by?",
"how is paris referred to?",
"Why is Paris a popular destination?",
"When was the Eiffel Tower built?",
"In Paris, is French the main language?",
"since we're talking about Paris, what is it famous for?",
"speaking of paris where is it",
"tell me about the French language",
"talk about france",
"regarding the Eiffel Tower, what was it built for?"
]);
// e2e: Run full training on user provided files then prompt
await withFiles(
['cat-facts'],
['talk to me about cats']
);
// e2e: Run training from bootstrap then get completions
await withBootstrap(['what about society?']);
};
runTests();