generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Refactor ai-api E2E tests (#187)
* add sample code * refactor tests and add cleanup * add changelog * update docs * fix: Changes from lint * changes * remove changelog, update README * fix: Changes from lint * restructure * add cleanup script * missing dep * whoops * changes to sample code * rename * missed one * lint -_- * changes * lockfile * forgot to change this * optimize --------- Co-authored-by: cloud-sdk-js <[email protected]>
- Loading branch information
1 parent
4715763
commit 65c50fa
Showing
14 changed files
with
423 additions
and
96 deletions.
There are no files selected for viewing
This file contains 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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,108 @@ | ||
import { DeploymentApi } from '@sap-ai-sdk/ai-api'; | ||
import type { | ||
AiDeploymentBulkModificationResponse, | ||
AiDeploymentCreationResponse, | ||
AiDeploymentDeletionResponse, | ||
AiDeploymentList, | ||
AiDeploymentModificationRequestList, | ||
AiDeploymentStatus | ||
} from '@sap-ai-sdk/ai-api'; | ||
|
||
/** | ||
* Get all deployments filtered by status. | ||
* @param resourceGroup - AI-Resource-Group where the resources are available. | ||
* @param status - Optional query parameter to filter deployments by status. | ||
* @returns List of deployments. | ||
*/ | ||
export async function getDeployments( | ||
resourceGroup: string, | ||
status?: AiDeploymentStatus | ||
): Promise<AiDeploymentList> { | ||
// check for optional query parameters. | ||
const queryParams = status ? { status } : {}; | ||
return DeploymentApi.deploymentQuery(queryParams, { | ||
'AI-Resource-Group': resourceGroup | ||
}).execute(); | ||
} | ||
|
||
/** | ||
* Create a deployment using the configuration specified by configurationId. | ||
* @param configurationId - ID of the configuration to be used. | ||
* @param resourceGroup - AI-Resource-Group where the resources are available. | ||
* @returns Deployment creation response with 'targetStatus': 'RUNNING'. | ||
*/ | ||
export async function createDeployment( | ||
configurationId: string, | ||
resourceGroup: string | ||
): Promise<AiDeploymentCreationResponse> { | ||
return DeploymentApi.deploymentCreate( | ||
{ configurationId }, | ||
{ 'AI-Resource-Group': resourceGroup } | ||
).execute(); | ||
} | ||
|
||
/** | ||
* Stop all deployments with the specific configuration ID. | ||
* Only deployments with 'status': 'RUNNING' can be stopped. | ||
* @param configurationId - ID of the configuration to be used. | ||
* @param resourceGroup - AI-Resource-Group where the resources are available. | ||
* @returns Deployment modification response list with 'targetStatus': 'STOPPED'. | ||
*/ | ||
export async function stopDeployments( | ||
configurationId: string, | ||
resourceGroup: string | ||
): Promise<AiDeploymentBulkModificationResponse> { | ||
// Get all RUNNING deployments with configurationId | ||
const deployments: AiDeploymentList = await DeploymentApi.deploymentQuery( | ||
{ status: 'RUNNING', configurationId }, | ||
{ 'AI-Resource-Group': resourceGroup } | ||
).execute(); | ||
|
||
// Map the deployment Ids and add property targetStatus: 'STOPPED' | ||
const deploymentsToStop: any = deployments.resources.map(deployment => ({ | ||
id: deployment.id, | ||
targetStatus: 'STOPPED' | ||
})); | ||
|
||
// Send batch modify request to stop deployments | ||
return DeploymentApi.deploymentBatchModify( | ||
{ deployments: deploymentsToStop as AiDeploymentModificationRequestList }, | ||
{ 'AI-Resource-Group': resourceGroup } | ||
).execute(); | ||
} | ||
|
||
/** | ||
* Delete all deployments. | ||
* Only deployments with 'status': 'STOPPED' and 'status': 'UNKNOWN' can be deleted. | ||
* @param resourceGroup - AI-Resource-Group where the resources are available. | ||
* @returns Deployment deletion response list with 'targetStatus': 'DELETED'. | ||
*/ | ||
export async function deleteDeployments( | ||
resourceGroup: string | ||
): Promise<AiDeploymentDeletionResponse[]> { | ||
// Get all STOPPED and UNKNOWN deployments | ||
const [runningDeployments, unknownDeployments] = await Promise.all([ | ||
DeploymentApi.deploymentQuery( | ||
{ status: 'STOPPED' }, | ||
{ 'AI-Resource-Group': resourceGroup } | ||
).execute(), | ||
DeploymentApi.deploymentQuery( | ||
{ status: 'UNKNOWN' }, | ||
{ 'AI-Resource-Group': resourceGroup } | ||
).execute() | ||
]); | ||
|
||
const deploymentsToDelete = [ | ||
...runningDeployments.resources, | ||
...unknownDeployments.resources | ||
]; | ||
|
||
// Delete all deployments | ||
return Promise.all( | ||
deploymentsToDelete.map(deployment => | ||
DeploymentApi.deploymentDelete(deployment.id, { | ||
'AI-Resource-Group': resourceGroup | ||
}).execute() | ||
) | ||
); | ||
} |
This file contains 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,30 @@ | ||
import { ScenarioApi } from '@sap-ai-sdk/ai-api'; | ||
import type { AiScenarioList, AiModelList } from '@sap-ai-sdk/ai-api'; | ||
|
||
/** | ||
* Get all scenarios. | ||
* @param resourceGroup - AI-Resource-Group where the resources are available. | ||
* @returns All scenarios. | ||
*/ | ||
export async function getScenarios( | ||
resourceGroup: string | ||
): Promise<AiScenarioList> { | ||
return ScenarioApi.scenarioQuery({ | ||
'AI-Resource-Group': resourceGroup | ||
}).execute(); | ||
} | ||
|
||
/** | ||
* Retrieve information about all models available in LLM global scenario. | ||
* @param scenarioId - ID of the global scenario. | ||
* @param resourceGroup - AI-Resource-Group where the resources are available. | ||
* @returns All models in given scenario. | ||
*/ | ||
export async function getModelsInScenario( | ||
scenarioId: string, | ||
resourceGroup: string | ||
): Promise<AiModelList> { | ||
return ScenarioApi.modelsGet(scenarioId, { | ||
'AI-Resource-Group': resourceGroup | ||
}).execute(); | ||
} |
This file contains 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 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 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 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.