1
1
/* eslint-disable import/no-extraneous-dependencies */
2
2
import { execSync } from "child_process" ;
3
- import Commander from "commander" ;
4
- import Conf from "conf" ;
3
+ import { Command } from "commander" ;
5
4
import fs from "fs" ;
6
5
import path from "path" ;
7
6
import { bold , cyan , green , red , yellow } from "picocolors" ;
@@ -17,8 +16,9 @@ import { runApp } from "./helpers/run-app";
17
16
import { getTools } from "./helpers/tools" ;
18
17
import { validateNpmName } from "./helpers/validate-pkg" ;
19
18
import packageJson from "./package.json" ;
20
- import { QuestionArgs , askQuestions , onPromptState } from "./questions" ;
21
-
19
+ import { askQuestions } from "./questions/index" ;
20
+ import { QuestionArgs } from "./questions/types" ;
21
+ import { onPromptState } from "./questions/utils" ;
22
22
// Run the initialization function
23
23
initializeGlobalAgent ( ) ;
24
24
@@ -29,12 +29,14 @@ const handleSigTerm = () => process.exit(0);
29
29
process . on ( "SIGINT" , handleSigTerm ) ;
30
30
process . on ( "SIGTERM" , handleSigTerm ) ;
31
31
32
- const program = new Commander . Command ( packageJson . name )
32
+ const program = new Command ( packageJson . name )
33
33
. version ( packageJson . version )
34
- . arguments ( "< project-directory> " )
35
- . usage ( `${ green ( "< project-directory> " ) } [options]` )
34
+ . arguments ( "[ project-directory] " )
35
+ . usage ( `${ green ( "[ project-directory] " ) } [options]` )
36
36
. action ( ( name ) => {
37
- projectPath = name ;
37
+ if ( name ) {
38
+ projectPath = name ;
39
+ }
38
40
} )
39
41
. option (
40
42
"--use-npm" ,
@@ -55,13 +57,6 @@ const program = new Commander.Command(packageJson.name)
55
57
`
56
58
57
59
Explicitly tell the CLI to bootstrap the application using Yarn
58
- ` ,
59
- )
60
- . option (
61
- "--reset-preferences" ,
62
- `
63
-
64
- Explicitly tell the CLI to reset any stored preferences
65
60
` ,
66
61
)
67
62
. option (
@@ -124,7 +119,14 @@ const program = new Commander.Command(packageJson.name)
124
119
"--frontend" ,
125
120
`
126
121
127
- Whether to generate a frontend for your backend.
122
+ Generate a frontend for your backend.
123
+ ` ,
124
+ )
125
+ . option (
126
+ "--no-frontend" ,
127
+ `
128
+
129
+ Do not generate a frontend for your backend.
128
130
` ,
129
131
)
130
132
. option (
@@ -161,6 +163,13 @@ const program = new Commander.Command(packageJson.name)
161
163
162
164
Specify the tools you want to use by providing a comma-separated list. For example, 'wikipedia.WikipediaToolSpec,google.GoogleSearchToolSpec'. Use 'none' to not using any tools.
163
165
` ,
166
+ ( tools , _ ) => {
167
+ if ( tools === "none" ) {
168
+ return [ ] ;
169
+ } else {
170
+ return getTools ( tools . split ( "," ) ) ;
171
+ }
172
+ } ,
164
173
)
165
174
. option (
166
175
"--use-llama-parse" ,
@@ -189,86 +198,66 @@ const program = new Commander.Command(packageJson.name)
189
198
190
199
Allow interactive selection of LLM and embedding models of different model providers.
191
200
` ,
201
+ false ,
192
202
)
193
203
. option (
194
- "--ask-examples " ,
204
+ "--pro " ,
195
205
`
196
206
197
- Allow interactive selection of community templates and LlamaPacks .
207
+ Allow interactive selection of all features .
198
208
` ,
209
+ false ,
199
210
)
200
211
. allowUnknownOption ( )
201
212
. parse ( process . argv ) ;
202
- if ( process . argv . includes ( "--no-frontend" ) ) {
203
- program . frontend = false ;
204
- }
205
- if ( process . argv . includes ( "--tools" ) ) {
206
- if ( program . tools === "none" ) {
207
- program . tools = [ ] ;
208
- } else {
209
- program . tools = getTools ( program . tools . split ( "," ) ) ;
210
- }
211
- }
213
+
214
+ const options = program . opts ( ) ;
215
+
212
216
if (
213
217
process . argv . includes ( "--no-llama-parse" ) ||
214
- program . template === "extractor"
218
+ options . template === "extractor"
215
219
) {
216
- program . useLlamaParse = false ;
220
+ options . useLlamaParse = false ;
217
221
}
218
- program . askModels = process . argv . includes ( "--ask-models" ) ;
219
- program . askExamples = process . argv . includes ( "--ask-examples" ) ;
220
222
if ( process . argv . includes ( "--no-files" ) ) {
221
- program . dataSources = [ ] ;
223
+ options . dataSources = [ ] ;
222
224
} else if ( process . argv . includes ( "--example-file" ) ) {
223
- program . dataSources = getDataSources ( program . files , program . exampleFile ) ;
225
+ options . dataSources = getDataSources ( options . files , options . exampleFile ) ;
224
226
} else if ( process . argv . includes ( "--llamacloud" ) ) {
225
- program . dataSources = [
226
- {
227
- type : "llamacloud" ,
228
- config : { } ,
229
- } ,
230
- EXAMPLE_FILE ,
231
- ] ;
227
+ options . dataSources = [ EXAMPLE_FILE ] ;
228
+ options . vectorDb = "llamacloud" ;
232
229
} else if ( process . argv . includes ( "--web-source" ) ) {
233
- program . dataSources = [
230
+ options . dataSources = [
234
231
{
235
232
type : "web" ,
236
233
config : {
237
- baseUrl : program . webSource ,
238
- prefix : program . webSource ,
234
+ baseUrl : options . webSource ,
235
+ prefix : options . webSource ,
239
236
depth : 1 ,
240
237
} ,
241
238
} ,
242
239
] ;
243
240
} else if ( process . argv . includes ( "--db-source" ) ) {
244
- program . dataSources = [
241
+ options . dataSources = [
245
242
{
246
243
type : "db" ,
247
244
config : {
248
- uri : program . dbSource ,
249
- queries : program . dbQuery || "SELECT * FROM mytable" ,
245
+ uri : options . dbSource ,
246
+ queries : options . dbQuery || "SELECT * FROM mytable" ,
250
247
} ,
251
248
} ,
252
249
] ;
253
250
}
254
251
255
- const packageManager = ! ! program . useNpm
252
+ const packageManager = ! ! options . useNpm
256
253
? "npm"
257
- : ! ! program . usePnpm
254
+ : ! ! options . usePnpm
258
255
? "pnpm"
259
- : ! ! program . useYarn
256
+ : ! ! options . useYarn
260
257
? "yarn"
261
258
: getPkgManager ( ) ;
262
259
263
260
async function run ( ) : Promise < void > {
264
- const conf = new Conf ( { projectName : "create-llama" } ) ;
265
-
266
- if ( program . resetPreferences ) {
267
- conf . clear ( ) ;
268
- console . log ( `Preferences reset successfully` ) ;
269
- return ;
270
- }
271
-
272
261
if ( typeof projectPath === "string" ) {
273
262
projectPath = projectPath . trim ( ) ;
274
263
}
@@ -331,35 +320,16 @@ async function run(): Promise<void> {
331
320
process . exit ( 1 ) ;
332
321
}
333
322
334
- const preferences = ( conf . get ( "preferences" ) || { } ) as QuestionArgs ;
335
- await askQuestions (
336
- program as unknown as QuestionArgs ,
337
- preferences ,
338
- program . openAiKey ,
339
- ) ;
323
+ const answers = await askQuestions ( options as unknown as QuestionArgs ) ;
340
324
341
325
await createApp ( {
342
- template : program . template ,
343
- framework : program . framework ,
344
- ui : program . ui ,
326
+ ...answers ,
345
327
appPath : resolvedProjectPath ,
346
328
packageManager,
347
- frontend : program . frontend ,
348
- modelConfig : program . modelConfig ,
349
- llamaCloudKey : program . llamaCloudKey ,
350
- communityProjectConfig : program . communityProjectConfig ,
351
- llamapack : program . llamapack ,
352
- vectorDb : program . vectorDb ,
353
- externalPort : program . externalPort ,
354
- postInstallAction : program . postInstallAction ,
355
- dataSources : program . dataSources ,
356
- tools : program . tools ,
357
- useLlamaParse : program . useLlamaParse ,
358
- observability : program . observability ,
329
+ externalPort : options . externalPort ,
359
330
} ) ;
360
- conf . set ( "preferences" , preferences ) ;
361
331
362
- if ( program . postInstallAction === "VSCode" ) {
332
+ if ( answers . postInstallAction === "VSCode" ) {
363
333
console . log ( `Starting VSCode in ${ root } ...` ) ;
364
334
try {
365
335
execSync ( `code . --new-window --goto README.md` , {
@@ -383,15 +353,15 @@ Please check ${cyan(
383
353
) } for more information.`,
384
354
) ;
385
355
}
386
- } else if ( program . postInstallAction === "runApp" ) {
356
+ } else if ( answers . postInstallAction === "runApp" ) {
387
357
console . log ( `Running app in ${ root } ...` ) ;
388
358
await runApp (
389
359
root ,
390
- program . template ,
391
- program . frontend ,
392
- program . framework ,
393
- program . port ,
394
- program . externalPort ,
360
+ answers . template ,
361
+ answers . frontend ,
362
+ answers . framework ,
363
+ options . port ,
364
+ options . externalPort ,
395
365
) ;
396
366
}
397
367
}
0 commit comments