-
Notifications
You must be signed in to change notification settings - Fork 182
feat: add test and fix python dependencies #304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
364d221
add test and fix deps
leehuwuj 3f2b434
add resolve-python-dependencies job
leehuwuj 89c1114
Only support python 3.11 and python 3.12 for now
leehuwuj 680c0fd
add web and db data source
leehuwuj 471aca2
remove python matrix for resolve-python-dependencies
leehuwuj b982e7a
ci: use only one e2e test
marcusschiesser File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import { expect, test } from "@playwright/test"; | ||
import { exec } from "child_process"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
import util from "util"; | ||
import { TemplateFramework, TemplateVectorDB } from "../helpers/types"; | ||
import { createTestDir, runCreateLlama } from "./utils"; | ||
|
||
const execAsync = util.promisify(exec); | ||
|
||
const templateFramework: TemplateFramework = process.env.FRAMEWORK | ||
? (process.env.FRAMEWORK as TemplateFramework) | ||
: "fastapi"; | ||
const dataSource: string = process.env.DATASOURCE | ||
? process.env.DATASOURCE | ||
: "--example-file"; | ||
|
||
if ( | ||
templateFramework == "fastapi" && // test is only relevant for fastapi | ||
process.version.startsWith("v20.") && // XXX: Only run for Node.js version 20 (CI matrix will trigger other versions) | ||
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) | ||
) { | ||
// vectorDBs, tools, and data source combinations to test | ||
const vectorDbs: TemplateVectorDB[] = [ | ||
"mongo", | ||
"pg", | ||
"pinecone", | ||
"milvus", | ||
"astra", | ||
"qdrant", | ||
"chroma", | ||
"weaviate", | ||
]; | ||
|
||
const toolOptions = [ | ||
"wikipedia.WikipediaToolSpec", | ||
"google.GoogleSearchToolSpec", | ||
]; | ||
|
||
const dataSources = [ | ||
"--example-file", | ||
"--web-source https://www.example.com", | ||
"--db-source mysql+pymysql://user:pass@localhost:3306/mydb", | ||
]; | ||
|
||
test.describe("Test resolve python dependencies", () => { | ||
for (const vectorDb of vectorDbs) { | ||
for (const tool of toolOptions) { | ||
for (const dataSource of dataSources) { | ||
const dataSourceType = dataSource.split(" ")[0]; | ||
const optionDescription = `vectorDb: ${vectorDb}, tools: ${tool}, dataSource: ${dataSourceType}`; | ||
|
||
test(`options: ${optionDescription}`, async () => { | ||
const cwd = await createTestDir(); | ||
|
||
const result = await runCreateLlama( | ||
cwd, | ||
"streaming", | ||
"fastapi", | ||
dataSource, | ||
vectorDb, | ||
3000, // port | ||
8000, // externalPort | ||
"none", // postInstallAction | ||
undefined, // ui | ||
"--no-frontend", // appType | ||
undefined, // llamaCloudProjectName | ||
undefined, // llamaCloudIndexName | ||
tool, | ||
); | ||
const name = result.projectName; | ||
|
||
// Check if the app folder exists | ||
const dirExists = fs.existsSync(path.join(cwd, name)); | ||
expect(dirExists).toBeTruthy(); | ||
|
||
// Check if pyproject.toml exists | ||
const pyprojectPath = path.join(cwd, name, "pyproject.toml"); | ||
const pyprojectExists = fs.existsSync(pyprojectPath); | ||
expect(pyprojectExists).toBeTruthy(); | ||
|
||
// Run poetry lock | ||
try { | ||
const { stdout, stderr } = await execAsync( | ||
"poetry config virtualenvs.in-project true && poetry lock --no-update", | ||
{ | ||
cwd: path.join(cwd, name), | ||
}, | ||
); | ||
console.log("poetry lock stdout:", stdout); | ||
console.error("poetry lock stderr:", stderr); | ||
} catch (error) { | ||
console.error("Error running poetry lock:", error); | ||
throw error; | ||
} | ||
|
||
// Check if poetry.lock file was created | ||
const poetryLockExists = fs.existsSync( | ||
path.join(cwd, name, "poetry.lock"), | ||
); | ||
expect(poetryLockExists).toBeTruthy(); | ||
|
||
// Verify that specific dependencies are in pyproject.toml | ||
const pyprojectContent = fs.readFileSync(pyprojectPath, "utf-8"); | ||
if (vectorDb !== "none") { | ||
if (vectorDb === "pg") { | ||
expect(pyprojectContent).toContain( | ||
"llama-index-vector-stores-postgres", | ||
); | ||
} else { | ||
expect(pyprojectContent).toContain( | ||
`llama-index-vector-stores-${vectorDb}`, | ||
); | ||
} | ||
} | ||
if (tool !== "none") { | ||
if (tool === "wikipedia.WikipediaToolSpec") { | ||
expect(pyprojectContent).toContain("wikipedia"); | ||
} | ||
if (tool === "google.GoogleSearchToolSpec") { | ||
expect(pyprojectContent).toContain("google"); | ||
} | ||
} | ||
|
||
// Check for data source specific dependencies | ||
if (dataSource.includes("--web-source")) { | ||
expect(pyprojectContent).toContain("llama-index-readers-web"); | ||
} | ||
if (dataSource.includes("--db-source")) { | ||
expect(pyprojectContent).toContain( | ||
"llama-index-readers-database ", | ||
); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
}); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.