-
Notifications
You must be signed in to change notification settings - Fork 155
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
add script to clean up e2e #366
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,106 @@ | ||||||||||||||||
import { | ||||||||||||||||
client, | ||||||||||||||||
PipelinesService, | ||||||||||||||||
ProjectsService, | ||||||||||||||||
} from "@llamaindex/cloud/api"; | ||||||||||||||||
import { DEFAULT_BASE_URL } from "@llamaindex/core/global"; | ||||||||||||||||
|
||||||||||||||||
function initService(apiKey?: string) { | ||||||||||||||||
client.setConfig({ | ||||||||||||||||
baseUrl: DEFAULT_BASE_URL, | ||||||||||||||||
throwOnError: true, | ||||||||||||||||
}); | ||||||||||||||||
const token = apiKey ?? process.env.LLAMA_CLOUD_API_KEY; | ||||||||||||||||
client.interceptors.request.use((request: any) => { | ||||||||||||||||
request.headers.set("Authorization", `Bearer ${token}`); | ||||||||||||||||
return request; | ||||||||||||||||
}); | ||||||||||||||||
if (!token) { | ||||||||||||||||
throw new Error( | ||||||||||||||||
"API Key is required for LlamaCloudIndex. Please set the LLAMA_CLOUD_API_KEY environment variable", | ||||||||||||||||
); | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
async function getProjectId(projectName: string): Promise<string> { | ||||||||||||||||
const { data: projects } = await ProjectsService.listProjectsApiV1ProjectsGet( | ||||||||||||||||
{ | ||||||||||||||||
query: { | ||||||||||||||||
project_name: projectName, | ||||||||||||||||
}, | ||||||||||||||||
throwOnError: true, | ||||||||||||||||
}, | ||||||||||||||||
); | ||||||||||||||||
|
||||||||||||||||
if (projects.length === 0) { | ||||||||||||||||
throw new Error( | ||||||||||||||||
`Unknown project name ${projectName}. Please confirm a managed project with this name exists.`, | ||||||||||||||||
); | ||||||||||||||||
} else if (projects.length > 1) { | ||||||||||||||||
throw new Error( | ||||||||||||||||
`Multiple projects found with name ${projectName}. Please specify organization_id.`, | ||||||||||||||||
); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
const project = projects[0]!; | ||||||||||||||||
|
||||||||||||||||
if (!project.id) { | ||||||||||||||||
throw new Error(`No project found with name ${projectName}`); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
return project.id; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
async function deletePipelines(projectName: string) { | ||||||||||||||||
try { | ||||||||||||||||
initService(); | ||||||||||||||||
|
||||||||||||||||
const projectId = await getProjectId(projectName); | ||||||||||||||||
|
||||||||||||||||
const { data: pipelines } = | ||||||||||||||||
await PipelinesService.searchPipelinesApiV1PipelinesGet({ | ||||||||||||||||
query: { project_id: projectId }, | ||||||||||||||||
throwOnError: true, | ||||||||||||||||
}); | ||||||||||||||||
|
||||||||||||||||
console.log(`Deleting pipelines for project "${projectName}":`); | ||||||||||||||||
|
||||||||||||||||
for (const pipeline of pipelines) { | ||||||||||||||||
if (pipeline.id) { | ||||||||||||||||
try { | ||||||||||||||||
await PipelinesService.deletePipelineApiV1PipelinesPipelineIdDelete({ | ||||||||||||||||
path: { pipeline_id: pipeline.id }, | ||||||||||||||||
throwOnError: true, | ||||||||||||||||
}); | ||||||||||||||||
console.log( | ||||||||||||||||
`✅ Deleted pipeline: ${pipeline.name} (ID: ${pipeline.id})`, | ||||||||||||||||
); | ||||||||||||||||
} catch (error) { | ||||||||||||||||
console.error( | ||||||||||||||||
`❌ Failed to delete pipeline: ${pipeline.name} (ID: ${pipeline.id})`, | ||||||||||||||||
); | ||||||||||||||||
console.error( | ||||||||||||||||
` Error: ${error instanceof Error ? error.message : String(error)}`, | ||||||||||||||||
); | ||||||||||||||||
} | ||||||||||||||||
} else { | ||||||||||||||||
console.warn(`⚠️ Skipping pipeline with no ID: ${pipeline.name}`); | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
console.log(`\nDeletion process completed for project "${projectName}".`); | ||||||||||||||||
console.log(`Total pipelines processed: ${pipelines.length}`); | ||||||||||||||||
} catch (error) { | ||||||||||||||||
console.error("Error during pipeline deletion process:", error); | ||||||||||||||||
} | ||||||||||||||||
Comment on lines
+93
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exit with a non-zero exit code when an error occurs When an error occurs during the pipeline deletion process, the script logs the error but exits with a zero exit code. To indicate failure to the calling process or CI tools, consider exiting with a non-zero exit code. Apply this diff to fix the issue: } catch (error) {
console.error("Error during pipeline deletion process:", error);
+ process.exit(1);
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
// Get the project name from command line arguments | ||||||||||||||||
const projectName = process.argv[2]; | ||||||||||||||||
|
||||||||||||||||
if (!projectName) { | ||||||||||||||||
console.error("Please provide a project name as an argument."); | ||||||||||||||||
process.exit(1); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
Comment on lines
+100
to
+105
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider using a command-line argument parser for scalability Directly accessing For example, you could modify your script to use +import yargs from 'yargs';
+
+const argv = yargs(process.argv.slice(2))
+ .usage('Usage: $0 --project <projectName>')
+ .option('project', {
+ alias: 'p',
+ describe: 'Name of the project',
+ type: 'string',
+ demandOption: true,
+ })
+ .help()
+ .argv;
+
+const projectName = argv.project;
-
-const projectName = process.argv[2];
-
-if (!projectName) {
- console.error("Please provide a project name as an argument.");
- process.exit(1);
-}
-
deletePipelines(projectName); Remember to install
|
||||||||||||||||
deletePipelines(projectName); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "@create-llama/e2e-clean", | ||
"version": "0.1.0", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"clean": "tsx clean.ts create-llama" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.0.0", | ||
"tsx": "^4.19.1" | ||
}, | ||
"dependencies": { | ||
"@llamaindex/cloud": "^0.2.14", | ||
"@llamaindex/core": "^0.2.12", | ||
"tiktoken": "^1.0.17" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move token validation before setting up the interceptor
Currently, the interceptor is set up before verifying that
token
is defined, which could lead to setting an Authorization header with an undefined token, causing unintended behavior. To prevent this, validate thattoken
is defined before setting up the interceptor.Apply this diff to fix the issue:
📝 Committable suggestion