-
Notifications
You must be signed in to change notification settings - Fork 70
/
plopfile.mjs
168 lines (147 loc) · 5.11 KB
/
plopfile.mjs
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
import { createRequire } from "module";
const require = createRequire(import.meta.url);
const vectaraWebsiteQuestions = require("./config/website-vectara/queries.json");
const vectaraDocsQuestions = require("./config/vectara-docs/queries.json");
const askFeynmanQuestions = require("./config/ask-feynman/queries.json");
const DEFAULT_CONFIGS = {
"vectara-docs": {
customerId: "1366999410",
corpusId: "1",
apiKey: "zqt_UXrBcnI2UXINZkrv4g1tQPhzj02vfdtqYJIDiA",
appTitle: "Vectara Docs Search",
searchTitle: "Vectara Docs Search",
searchDescription: "All of Vectara's Platform Documentation",
questions: JSON.stringify(vectaraDocsQuestions.questions),
},
"vectara-website": {
customerId: "1366999410",
corpusId: "2",
apiKey: "zqt_UXrBcnnt4156FZqMtzK8OEoZqcR0OrecS5Bb6Q",
appTitle: "Vectara Website Search",
searchTitle: "Vectara Website Search",
searchDescription: "All the content on Vectara's Website",
questions: JSON.stringify(vectaraWebsiteQuestions.questions),
},
"ask-feynman": {
customerId: "1366999410",
corpusId: "3",
apiKey: "zqt_UXrBclYURJiAW9MiKT1L60EJC6iaIoWYj_bSJg",
appTitle: "Ask Feynman",
searchTitle: "Ask Feynman",
searchDescription: "All of Richard Feynman's Lectures",
questions: JSON.stringify(askFeynmanQuestions.questions),
},
};
let presetAppName;
const checkNeedsConfiguration = (context) => {
return !context.presetAppName;
};
export default function (plop) {
plop.setGenerator("env", {
description: "Application Configuration Variables",
prompts: async function (inquirer) {
const acknowledgeAns = await inquirer.prompt({
type: "input",
name: "acknowledgePrimer",
message:
"Welcome to vectara-answer!\nLet's configure your application.\nYou can choose from a pre-configured one, or configure your own.\nNOTE: THIS WILL OVERWRITE .env CONFIGURATION FILE.\n\nPress Enter to continue.",
});
const presetAppNameAns = await inquirer.prompt({
type: "list",
name: "presetAppName",
message: "Which application would you like to create?",
choices: [
{ name: "Vectara Docs", value: "vectara-docs" },
{ name: "Vectara.com", value: "vectara-website" },
{ name: "AskFeynman", value: "ask-feynman" },
{ name: "[Create Your Own]", value: undefined },
],
filter: (input) => {
// Cache the chosen app name.
// We'll check for this when creating the .env file.
presetAppName = input;
return presetAppName;
},
});
if (presetAppNameAns.presetAppName) {
presetAppName = presetAppNameAns.presetAppName;
return;
}
const appTitleAns = await inquirer.prompt({
when: checkNeedsConfiguration,
type: "input",
name: "searchTitle",
message: "What would you like to name your application?",
});
const customerIdAns = await inquirer.prompt({
when: checkNeedsConfiguration,
type: "input",
name: "customerId",
message: "What's your Vectara Customer ID?",
});
const corpusIdAns = await inquirer.prompt({
when: checkNeedsConfiguration,
type: "input",
name: "corpusId",
message: "What Vectara Corpus ID is associated with your data?",
});
const apiKeyAns = await inquirer.prompt({
when: checkNeedsConfiguration,
type: "input",
name: "apiKey",
message:
"What is your Vectara QueryService API Key (This can be safely shared)?",
});
const questions = [];
const haveQuestionsAns = await inquirer.prompt({
type: "confirm",
name: "value",
message: "Would you like to add sample questions for your users?",
});
if (haveQuestionsAns.value) {
let moreQuestionsAns;
let numQuestions = 0;
do {
numQuestions++;
let questionAns = await inquirer.prompt({
type: "input",
name: "value",
message: `Enter sample question ${numQuestions}:`,
});
questions.push(questionAns.value);
moreQuestionsAns = await inquirer.prompt({
type: "confirm",
name: "value",
message: "Would you like to add more questions?",
});
} while (moreQuestionsAns.value);
}
return {
...acknowledgeAns,
...presetAppNameAns,
...appTitleAns,
...customerIdAns,
...corpusIdAns,
...apiKeyAns,
questions: JSON.stringify(questions),
};
},
actions: [
{
type: "add",
data: () => {
// Check our cached app name since this function does
// not have a reference to the current Plop context.
if (presetAppName) {
return DEFAULT_CONFIGS[presetAppName];
}
return {};
},
path: "./.env",
templateFile: "plopTemplates/env.hbs",
force: true,
},
"Configuration created! To run your app, run `npm run start` or `bash docker/run.sh`.",
],
});
}