@@ -3,121 +3,137 @@ import { exec } from "child_process";
3
3
import fs from "fs" ;
4
4
import path from "path" ;
5
5
import util from "util" ;
6
- import { TemplateVectorDB } from "../helpers/types" ;
6
+ import { TemplateFramework , TemplateVectorDB } from "../helpers/types" ;
7
7
import { createTestDir , runCreateLlama } from "./utils" ;
8
8
9
9
const execAsync = util . promisify ( exec ) ;
10
10
11
- const vectorDbs : TemplateVectorDB [ ] = [
12
- "mongo" ,
13
- "pg" ,
14
- "pinecone" ,
15
- "milvus" ,
16
- "astra" ,
17
- "qdrant" ,
18
- "chroma" ,
19
- "weaviate" ,
20
- ] ;
11
+ const templateFramework : TemplateFramework = process . env . FRAMEWORK
12
+ ? ( process . env . FRAMEWORK as TemplateFramework )
13
+ : "fastapi" ;
14
+ const dataSource : string = process . env . DATASOURCE
15
+ ? process . env . DATASOURCE
16
+ : "--example-file" ;
21
17
22
- const toolOptions = [
23
- "wikipedia.WikipediaToolSpec" ,
24
- "google.GoogleSearchToolSpec" ,
25
- ] ;
18
+ if (
19
+ templateFramework == "fastapi" && // test is only relevant for fastapi
20
+ process . version . startsWith ( "v20." ) && // XXX: Only run for Node.js version 20 (CI matrix will trigger other versions)
21
+ dataSource === "--example-file" // XXX: this test provides its own data source - only trigger it on one data source (usually the CI matrix will trigger multiple data sources)
22
+ ) {
23
+ // vectorDBs, tools, and data source combinations to test
24
+ const vectorDbs : TemplateVectorDB [ ] = [
25
+ "mongo" ,
26
+ "pg" ,
27
+ "pinecone" ,
28
+ "milvus" ,
29
+ "astra" ,
30
+ "qdrant" ,
31
+ "chroma" ,
32
+ "weaviate" ,
33
+ ] ;
26
34
27
- const dataSources = [
28
- "--example-file" ,
29
- "--web-source https://www.example.com" ,
30
- "--db-source mysql+pymysql://user:pass@localhost:3306/mydb" ,
31
- ] ;
35
+ const toolOptions = [
36
+ "wikipedia.WikipediaToolSpec" ,
37
+ "google.GoogleSearchToolSpec" ,
38
+ ] ;
32
39
33
- test . describe ( "Test resolve python dependencies" , ( ) => {
34
- for ( const vectorDb of vectorDbs ) {
35
- for ( const tool of toolOptions ) {
36
- for ( const dataSource of dataSources ) {
37
- const dataSourceType = dataSource . split ( " " ) [ 0 ] ;
38
- const optionDescription = `vectorDb: ${ vectorDb } , tools: ${ tool } , dataSource: ${ dataSourceType } ` ;
40
+ const dataSources = [
41
+ "--example-file" ,
42
+ "--web-source https://www.example.com" ,
43
+ "--db-source mysql+pymysql://user:pass@localhost:3306/mydb" ,
44
+ ] ;
39
45
40
- test ( `options: ${ optionDescription } ` , async ( ) => {
41
- const cwd = await createTestDir ( ) ;
46
+ test . describe ( "Test resolve python dependencies" , ( ) => {
47
+ for ( const vectorDb of vectorDbs ) {
48
+ for ( const tool of toolOptions ) {
49
+ for ( const dataSource of dataSources ) {
50
+ const dataSourceType = dataSource . split ( " " ) [ 0 ] ;
51
+ const optionDescription = `vectorDb: ${ vectorDb } , tools: ${ tool } , dataSource: ${ dataSourceType } ` ;
42
52
43
- const result = await runCreateLlama (
44
- cwd ,
45
- "streaming" ,
46
- "fastapi" ,
47
- dataSource ,
48
- vectorDb ,
49
- 3000 , // port
50
- 8000 , // externalPort
51
- "none" , // postInstallAction
52
- undefined , // ui
53
- "--no-frontend" , // appType
54
- undefined , // llamaCloudProjectName
55
- undefined , // llamaCloudIndexName
56
- tool ,
57
- ) ;
58
- const name = result . projectName ;
53
+ test ( `options: ${ optionDescription } ` , async ( ) => {
54
+ const cwd = await createTestDir ( ) ;
59
55
60
- // Check if the app folder exists
61
- const dirExists = fs . existsSync ( path . join ( cwd , name ) ) ;
62
- expect ( dirExists ) . toBeTruthy ( ) ;
63
-
64
- // Check if pyproject.toml exists
65
- const pyprojectPath = path . join ( cwd , name , "pyproject.toml" ) ;
66
- const pyprojectExists = fs . existsSync ( pyprojectPath ) ;
67
- expect ( pyprojectExists ) . toBeTruthy ( ) ;
68
-
69
- // Run poetry lock
70
- try {
71
- const { stdout, stderr } = await execAsync (
72
- "poetry config virtualenvs.in-project true && poetry lock --no-update" ,
73
- {
74
- cwd : path . join ( cwd , name ) ,
75
- } ,
56
+ const result = await runCreateLlama (
57
+ cwd ,
58
+ "streaming" ,
59
+ "fastapi" ,
60
+ dataSource ,
61
+ vectorDb ,
62
+ 3000 , // port
63
+ 8000 , // externalPort
64
+ "none" , // postInstallAction
65
+ undefined , // ui
66
+ "--no-frontend" , // appType
67
+ undefined , // llamaCloudProjectName
68
+ undefined , // llamaCloudIndexName
69
+ tool ,
76
70
) ;
77
- console . log ( "poetry lock stdout:" , stdout ) ;
78
- console . error ( "poetry lock stderr:" , stderr ) ;
79
- } catch ( error ) {
80
- console . error ( "Error running poetry lock:" , error ) ;
81
- throw error ;
82
- }
71
+ const name = result . projectName ;
83
72
84
- // Check if poetry.lock file was created
85
- const poetryLockExists = fs . existsSync (
86
- path . join ( cwd , name , "poetry.lock" ) ,
87
- ) ;
88
- expect ( poetryLockExists ) . toBeTruthy ( ) ;
73
+ // Check if the app folder exists
74
+ const dirExists = fs . existsSync ( path . join ( cwd , name ) ) ;
75
+ expect ( dirExists ) . toBeTruthy ( ) ;
89
76
90
- // Verify that specific dependencies are in pyproject.toml
91
- const pyprojectContent = fs . readFileSync ( pyprojectPath , "utf-8" ) ;
92
- if ( vectorDb !== "none" ) {
93
- if ( vectorDb === "pg" ) {
94
- expect ( pyprojectContent ) . toContain (
95
- "llama-index-vector-stores-postgres" ,
96
- ) ;
97
- } else {
98
- expect ( pyprojectContent ) . toContain (
99
- `llama-index-vector-stores-${ vectorDb } ` ,
77
+ // Check if pyproject.toml exists
78
+ const pyprojectPath = path . join ( cwd , name , "pyproject.toml" ) ;
79
+ const pyprojectExists = fs . existsSync ( pyprojectPath ) ;
80
+ expect ( pyprojectExists ) . toBeTruthy ( ) ;
81
+
82
+ // Run poetry lock
83
+ try {
84
+ const { stdout, stderr } = await execAsync (
85
+ "poetry config virtualenvs.in-project true && poetry lock --no-update" ,
86
+ {
87
+ cwd : path . join ( cwd , name ) ,
88
+ } ,
100
89
) ;
90
+ console . log ( "poetry lock stdout:" , stdout ) ;
91
+ console . error ( "poetry lock stderr:" , stderr ) ;
92
+ } catch ( error ) {
93
+ console . error ( "Error running poetry lock:" , error ) ;
94
+ throw error ;
101
95
}
102
- }
103
- if ( tool !== "none" ) {
104
- if ( tool === "wikipedia.WikipediaToolSpec" ) {
105
- expect ( pyprojectContent ) . toContain ( "wikipedia" ) ;
96
+
97
+ // Check if poetry.lock file was created
98
+ const poetryLockExists = fs . existsSync (
99
+ path . join ( cwd , name , "poetry.lock" ) ,
100
+ ) ;
101
+ expect ( poetryLockExists ) . toBeTruthy ( ) ;
102
+
103
+ // Verify that specific dependencies are in pyproject.toml
104
+ const pyprojectContent = fs . readFileSync ( pyprojectPath , "utf-8" ) ;
105
+ if ( vectorDb !== "none" ) {
106
+ if ( vectorDb === "pg" ) {
107
+ expect ( pyprojectContent ) . toContain (
108
+ "llama-index-vector-stores-postgres" ,
109
+ ) ;
110
+ } else {
111
+ expect ( pyprojectContent ) . toContain (
112
+ `llama-index-vector-stores-${ vectorDb } ` ,
113
+ ) ;
114
+ }
106
115
}
107
- if ( tool === "google.GoogleSearchToolSpec" ) {
108
- expect ( pyprojectContent ) . toContain ( "google" ) ;
116
+ if ( tool !== "none" ) {
117
+ if ( tool === "wikipedia.WikipediaToolSpec" ) {
118
+ expect ( pyprojectContent ) . toContain ( "wikipedia" ) ;
119
+ }
120
+ if ( tool === "google.GoogleSearchToolSpec" ) {
121
+ expect ( pyprojectContent ) . toContain ( "google" ) ;
122
+ }
109
123
}
110
- }
111
124
112
- // Check for data source specific dependencies
113
- if ( dataSource . includes ( "--web-source" ) ) {
114
- expect ( pyprojectContent ) . toContain ( "llama-index-readers-web" ) ;
115
- }
116
- if ( dataSource . includes ( "--db-source" ) ) {
117
- expect ( pyprojectContent ) . toContain ( "llama-index-readers-database " ) ;
118
- }
119
- } ) ;
125
+ // Check for data source specific dependencies
126
+ if ( dataSource . includes ( "--web-source" ) ) {
127
+ expect ( pyprojectContent ) . toContain ( "llama-index-readers-web" ) ;
128
+ }
129
+ if ( dataSource . includes ( "--db-source" ) ) {
130
+ expect ( pyprojectContent ) . toContain (
131
+ "llama-index-readers-database " ,
132
+ ) ;
133
+ }
134
+ } ) ;
135
+ }
120
136
}
121
137
}
122
- }
123
- } ) ;
138
+ } ) ;
139
+ }
0 commit comments