diff --git a/packages/ai-core/src/client-tests/artifact.unit.test.ts b/packages/ai-core/src/client-tests/artifact.unit.test.ts index 33179716..fccb4400 100644 --- a/packages/ai-core/src/client-tests/artifact.unit.test.ts +++ b/packages/ai-core/src/client-tests/artifact.unit.test.ts @@ -1,94 +1,102 @@ import nock from 'nock'; import { HttpDestination } from '@sap-cloud-sdk/connectivity'; import { - ArtifactApi, - ArtifactCreationResponse, - ArtifactList, - ArtifactPostData, - Artifact -} from '../index.js' + ArtifactApi, + ArtifactCreationResponse, + ArtifactList, + ArtifactPostData, + Artifact +} from '../index.js'; describe('artifact unit tests', () => { - let destination: HttpDestination; + let destination: HttpDestination; - beforeAll(() => { - destination = { - url: 'https://api.ai.intprod-eu12.eu-central-1.aws.ml.hana.ondemand.com/v2' - } - }); + beforeAll(() => { + destination = { + url: 'https://api.ai.intprod-eu12.eu-central-1.aws.ml.hana.ondemand.com/v2' + }; + }); + + afterEach(() => { + nock.cleanAll(); + }); - afterEach(() => { - nock.cleanAll(); - }); - - it('get artifact parses a successful response', async () => { - nock(destination.url) - .get('/lm/artifacts') - .reply(200, { - count: 1, - resources: [ - { - createdAt: '2024-07-08T13:36:41Z', - description: 'dataset for training test', - id: '08b9e4a4-2cea-4a3c-a509-9308d92bda85', - kind: 'dataset', - modifiedAt: '2024-07-08T13:36:41Z', - name: 'i745181-test-data', - scenarioId: 'foundation-models', - url: 'ai://default/spam/data' - } - ] - }, { - 'Content-Type': 'application/json', - 'AI-Resource-Group': 'default' - }); + it('get artifact parses a successful response', async () => { + nock(destination.url) + .get('/lm/artifacts') + .reply( + 200, + { + count: 1, + resources: [ + { + createdAt: '2024-07-08T13:36:41Z', + description: 'dataset for training test', + id: '08b9e4a4-2cea-4a3c-a509-9308d92bda85', + kind: 'dataset', + modifiedAt: '2024-07-08T13:36:41Z', + name: 'i745181-test-data', + scenarioId: 'foundation-models', + url: 'ai://default/spam/data' + } + ] + }, + { + 'Content-Type': 'application/json', + 'AI-Resource-Group': 'default' + } + ); - const result: ArtifactList = - await ArtifactApi.artifactQuery({}, {'AI-Resource-Group': 'default'}) - .execute(destination); + const result: ArtifactList = await ArtifactApi.artifactQuery( + {}, + { 'AI-Resource-Group': 'default' } + ).execute(destination); - expect(result).toBeTruthy(); - expect(result.count).toBe(1); - expect(result.resources.length).toBe(1); + expect(result).toBeTruthy(); + expect(result.count).toBe(1); + expect(result.resources.length).toBe(1); - const artifact: Artifact = result.resources[0]; - expect(artifact.createdAt).toBe('2024-07-08T13:36:41Z'); - expect(artifact.description).toBe('dataset for training test'); - expect(artifact.id).toBe('08b9e4a4-2cea-4a3c-a509-9308d92bda85'); - expect(artifact.kind).toBe('dataset'); - expect(artifact.modifiedAt).toBe('2024-07-08T13:36:41Z'); - expect(artifact.name).toBe('i745181-test-data'); - expect(artifact.scenarioId).toBe('foundation-models'); - expect(artifact.url).toBe('ai://default/spam/data'); - }); + const artifact: Artifact = result.resources[0]; + expect(artifact.createdAt).toBe('2024-07-08T13:36:41Z'); + expect(artifact.description).toBe('dataset for training test'); + expect(artifact.id).toBe('08b9e4a4-2cea-4a3c-a509-9308d92bda85'); + expect(artifact.kind).toBe('dataset'); + expect(artifact.modifiedAt).toBe('2024-07-08T13:36:41Z'); + expect(artifact.name).toBe('i745181-test-data'); + expect(artifact.scenarioId).toBe('foundation-models'); + expect(artifact.url).toBe('ai://default/spam/data'); + }); - it('post artifact parses a successful response', async () => { - nock(destination.url) - .post('/lm/artifacts') - .reply(200, { - id: '08b9e4a4-2cea-4a3c-a509-9308d92bda85', - message: 'Artifact acknowledged', - url: 'ai://default/spam/data' - }, { - 'Content-Type': 'application/json', - 'AI-Resource-Group': 'default' - }); + it('post artifact parses a successful response', async () => { + nock(destination.url).post('/lm/artifacts').reply( + 200, + { + id: '08b9e4a4-2cea-4a3c-a509-9308d92bda85', + message: 'Artifact acknowledged', + url: 'ai://default/spam/data' + }, + { + 'Content-Type': 'application/json', + 'AI-Resource-Group': 'default' + } + ); - const artifactPostData: ArtifactPostData = { - description: 'dataset for training test', - kind: 'dataset', - name: 'i745181-test-data', - scenarioId: 'foundation-models', - url: 'ai://default/spam/data' - }; + const artifactPostData: ArtifactPostData = { + description: 'dataset for training test', + kind: 'dataset', + name: 'i745181-test-data', + scenarioId: 'foundation-models', + url: 'ai://default/spam/data' + }; - const result: ArtifactCreationResponse = await ArtifactApi - .artifactCreate(artifactPostData, {'AI-Resource-Group': 'default'}) - .execute(destination); + const result: ArtifactCreationResponse = await ArtifactApi.artifactCreate( + artifactPostData, + { 'AI-Resource-Group': 'default' } + ).execute(destination); - expect(result).toBeTruthy(); - expect(result.id).toBe('08b9e4a4-2cea-4a3c-a509-9308d92bda85'); - expect(result.message).toBe('Artifact acknowledged'); - expect(result.url).toBe('ai://default/spam/data'); - }); -}); \ No newline at end of file + expect(result).toBeTruthy(); + expect(result.id).toBe('08b9e4a4-2cea-4a3c-a509-9308d92bda85'); + expect(result.message).toBe('Artifact acknowledged'); + expect(result.url).toBe('ai://default/spam/data'); + }); +}); diff --git a/packages/ai-core/src/client-tests/configuration.unit.test.ts b/packages/ai-core/src/client-tests/configuration.unit.test.ts index 192c7f11..1d32fd66 100644 --- a/packages/ai-core/src/client-tests/configuration.unit.test.ts +++ b/packages/ai-core/src/client-tests/configuration.unit.test.ts @@ -1,107 +1,115 @@ import nock from 'nock'; import { HttpDestination } from '@sap-cloud-sdk/connectivity'; import { - ConfigurationApi, - ConfigurationBaseData, - ConfigurationCreationResponse, - ConfigurationList, - Configuration -} from '../index.js' + ConfigurationApi, + ConfigurationBaseData, + ConfigurationCreationResponse, + ConfigurationList, + Configuration +} from '../index.js'; describe('configuration unit tests', () => { - let destination: HttpDestination; + let destination: HttpDestination; - beforeAll(() => { - destination = { - url: 'https://api.ai.intprod-eu12.eu-central-1.aws.ml.hana.ondemand.com/v2' - } - }); + beforeAll(() => { + destination = { + url: 'https://api.ai.intprod-eu12.eu-central-1.aws.ml.hana.ondemand.com/v2' + }; + }); - afterEach(() => { - nock.cleanAll(); - }); - - it('get configuration parses a successful response', async () => { - nock(destination.url) - .get('/lm/configurations') - .reply(200, { - count: 1, - resources: [ - { - createdAt: '2024-04-17T15:19:45Z', - executableId: 'azure-openai', - id: '7652a231-ba9b-4fcc-b473-2c355cb21b61', - inputArtifactBindings: [], - name: 'gpt-4-32k', - parameterBindings: [ - { - key: 'modelName', - value: 'gpt-4-32k' - }, - { - key: 'modelVersion', - value: 'latest' - } - ], - scenarioId: 'foundation-models' - } - ] - }, { - 'Content-Type': 'application/json', - 'AI-Resource-Group': 'default' - }); + afterEach(() => { + nock.cleanAll(); + }); - const result: ConfigurationList = - await ConfigurationApi.configurationQuery({}, {'AI-Resource-Group': 'default'}) - .execute(destination); + it('get configuration parses a successful response', async () => { + nock(destination.url) + .get('/lm/configurations') + .reply( + 200, + { + count: 1, + resources: [ + { + createdAt: '2024-04-17T15:19:45Z', + executableId: 'azure-openai', + id: '7652a231-ba9b-4fcc-b473-2c355cb21b61', + inputArtifactBindings: [], + name: 'gpt-4-32k', + parameterBindings: [ + { + key: 'modelName', + value: 'gpt-4-32k' + }, + { + key: 'modelVersion', + value: 'latest' + } + ], + scenarioId: 'foundation-models' + } + ] + }, + { + 'Content-Type': 'application/json', + 'AI-Resource-Group': 'default' + } + ); - expect(result).toBeTruthy(); - expect(result.count).toBe(1); - expect(result.resources.length).toBe(1); + const result: ConfigurationList = await ConfigurationApi.configurationQuery( + {}, + { 'AI-Resource-Group': 'default' } + ).execute(destination); - const configuration: Configuration = result.resources[0]; - const parameterBindings = configuration.parameterBindings ?? []; + expect(result).toBeTruthy(); + expect(result.count).toBe(1); + expect(result.resources.length).toBe(1); - expect(configuration.createdAt).toBe('2024-04-17T15:19:45Z'); - expect(configuration.executableId).toBe('azure-openai'); - expect(configuration.id).toBe('7652a231-ba9b-4fcc-b473-2c355cb21b61'); - expect(configuration.name).toBe('gpt-4-32k'); - expect(parameterBindings[0]?.key).toBe('modelName'); - expect(parameterBindings[0]?.value).toBe('gpt-4-32k'); - expect(parameterBindings[1]?.key).toBe('modelVersion'); - expect(parameterBindings[1]?.value).toBe('latest'); - expect(configuration.scenarioId).toBe('foundation-models'); - }); + const configuration: Configuration = result.resources[0]; + const parameterBindings = configuration.parameterBindings ?? []; - it('post configuration parses a successful response', async () => { - nock(destination.url) - .post('/lm/configurations') - .reply(200, { - 'id': '39f08464-4407-4b98-ade1-578a5ddb08b2', - 'message': 'Configuration created' - }, { - 'Content-Type': 'application/json', - 'AI-Resource-Group': 'default' - }); + expect(configuration.createdAt).toBe('2024-04-17T15:19:45Z'); + expect(configuration.executableId).toBe('azure-openai'); + expect(configuration.id).toBe('7652a231-ba9b-4fcc-b473-2c355cb21b61'); + expect(configuration.name).toBe('gpt-4-32k'); + expect(parameterBindings[0]?.key).toBe('modelName'); + expect(parameterBindings[0]?.value).toBe('gpt-4-32k'); + expect(parameterBindings[1]?.key).toBe('modelVersion'); + expect(parameterBindings[1]?.value).toBe('latest'); + expect(configuration.scenarioId).toBe('foundation-models'); + }); - const configurationPostData: ConfigurationBaseData = { - name: 'i745181-test-config', - executableId: 'azure-openai', - scenarioId: 'foundation-models', - inputArtifactBindings: [ - { - artifactId: '08b9e4a4-2cea-4a3c-a509-9308d92bda85', - key: 'spam-data' - } - ] - }; + it('post configuration parses a successful response', async () => { + nock(destination.url).post('/lm/configurations').reply( + 200, + { + id: '39f08464-4407-4b98-ade1-578a5ddb08b2', + message: 'Configuration created' + }, + { + 'Content-Type': 'application/json', + 'AI-Resource-Group': 'default' + } + ); + + const configurationPostData: ConfigurationBaseData = { + name: 'i745181-test-config', + executableId: 'azure-openai', + scenarioId: 'foundation-models', + inputArtifactBindings: [ + { + artifactId: '08b9e4a4-2cea-4a3c-a509-9308d92bda85', + key: 'spam-data' + } + ] + }; - const result: ConfigurationCreationResponse = await ConfigurationApi - .configurationCreate(configurationPostData, {'AI-Resource-Group': 'default'}) - .execute(destination); + const result: ConfigurationCreationResponse = + await ConfigurationApi.configurationCreate(configurationPostData, { + 'AI-Resource-Group': 'default' + }).execute(destination); - expect(result).toBeTruthy(); - expect(result.id).toBe('39f08464-4407-4b98-ade1-578a5ddb08b2'); - expect(result.message).toBe('Configuration created'); - }); -}); \ No newline at end of file + expect(result).toBeTruthy(); + expect(result.id).toBe('39f08464-4407-4b98-ade1-578a5ddb08b2'); + expect(result.message).toBe('Configuration created'); + }); +}); diff --git a/packages/ai-core/src/client-tests/deployment.unit.test.ts b/packages/ai-core/src/client-tests/deployment.unit.test.ts index a4e68cd7..49e056b4 100644 --- a/packages/ai-core/src/client-tests/deployment.unit.test.ts +++ b/packages/ai-core/src/client-tests/deployment.unit.test.ts @@ -1,168 +1,187 @@ import nock from 'nock'; import { HttpDestination } from '@sap-cloud-sdk/connectivity'; import { - Deployment, - DeploymentCreationRequest, - DeploymentCreationResponse, - DeploymentDeletionResponse, - DeploymentList, - DeploymentModificationRequest, - DeploymentApi, - DeploymentModificationResponse, - Status -} from '../index.js' + Deployment, + DeploymentCreationRequest, + DeploymentCreationResponse, + DeploymentDeletionResponse, + DeploymentList, + DeploymentModificationRequest, + DeploymentApi, + DeploymentModificationResponse, + Status +} from '../index.js'; describe('deployment unit tests', () => { - let destination: HttpDestination; - - beforeAll(() => { - destination = { - url: 'https://api.ai.intprod-eu12.eu-central-1.aws.ml.hana.ondemand.com/v2' - } - }); - - afterEach(() => { - nock.cleanAll(); - }); - - it('get deployment parses a successful response', async () => { - nock(destination.url) - .get('/lm/deployments') - .reply(200, { - count: 1, - resources: [ - { - configurationId: '7652a231-ba9b-4fcc-b473-2c355cb21b61', - configurationName: 'gpt-4-32k', - createdAt: '2024-04-17T15:19:53Z', - deploymentUrl: 'https://api.ai.intprod-eu12.eu-central-1.aws.ml.hana.ondemand.com/v2/inference/deployments/d19b998f347341aa', - details: { - resources: { - backend_details: { - model: { - name: 'gpt-4-32k', - version: 'latest' - } - } - }, - scaling: { - backend_details: {} - } - }, - id: 'd19b998f347341aa', - lastOperation: 'CREATE', - latestRunningConfigurationId: '7652a231-ba9b-4fcc-b473-2c355cb21b61', - modifiedAt: '2024-05-07T13:05:45Z', - scenarioId: 'foundation-models', - startTime: '2024-04-17T15:21:15Z', - status: 'RUNNING', - submissionTime: '2024-04-17T15:20:11Z', - targetStatus: 'RUNNING' + let destination: HttpDestination; + + beforeAll(() => { + destination = { + url: 'https://api.ai.intprod-eu12.eu-central-1.aws.ml.hana.ondemand.com/v2' + }; + }); + + afterEach(() => { + nock.cleanAll(); + }); + + it('get deployment parses a successful response', async () => { + nock(destination.url) + .get('/lm/deployments') + .reply( + 200, + { + count: 1, + resources: [ + { + configurationId: '7652a231-ba9b-4fcc-b473-2c355cb21b61', + configurationName: 'gpt-4-32k', + createdAt: '2024-04-17T15:19:53Z', + deploymentUrl: + 'https://api.ai.intprod-eu12.eu-central-1.aws.ml.hana.ondemand.com/v2/inference/deployments/d19b998f347341aa', + details: { + resources: { + backend_details: { + model: { + name: 'gpt-4-32k', + version: 'latest' + } } - ] - }, { - 'Content-Type': 'application/json', - 'AI-Resource-Group': 'default' - }); - - const result: DeploymentList = - await DeploymentApi.deploymentQuery({}, {'AI-Resource-Group': 'default'}) - .execute(destination); - - expect(result).toBeTruthy(); - expect(result.count).toBe(1); - expect(result.resources.length).toBe(1); - - const deployment: Deployment = result.resources[0]; - - expect(deployment.configurationId).toBe('7652a231-ba9b-4fcc-b473-2c355cb21b61'); - expect(deployment.configurationName).toBe('gpt-4-32k'); - expect(deployment.id).toBe('d19b998f347341aa'); - expect(deployment.status).toBe('RUNNING'); - expect(deployment.startTime).toBe('2024-04-17T15:21:15Z'); - }); - - it('post deployment parses a successful response', async () => { - nock(destination.url) - .post('/lm/deployments') - .reply(200, { - 'deploymentUrl': '', - 'id': 'd5b764fe55b3e87c', - 'message': 'Deployment scheduled', - 'status': 'UNKNOWN' - }, { - 'Content-Type': 'application/json', - 'AI-Resource-Group': 'default' - }); - - const deploymentPostData: DeploymentCreationRequest = { - configurationId: '7652a231-ba9b-4fcc-b473-2c355cb21b61' + }, + scaling: { + backend_details: {} + } + }, + id: 'd19b998f347341aa', + lastOperation: 'CREATE', + latestRunningConfigurationId: + '7652a231-ba9b-4fcc-b473-2c355cb21b61', + modifiedAt: '2024-05-07T13:05:45Z', + scenarioId: 'foundation-models', + startTime: '2024-04-17T15:21:15Z', + status: 'RUNNING', + submissionTime: '2024-04-17T15:20:11Z', + targetStatus: 'RUNNING' + } + ] + }, + { + 'Content-Type': 'application/json', + 'AI-Resource-Group': 'default' } - - const result: DeploymentCreationResponse = - await DeploymentApi.deploymentCreate(deploymentPostData, {'AI-Resource-Group': 'default'}) - .execute(destination); - - expect(result).toBeTruthy(); - expect(result.deploymentUrl).toBe(''); - expect(result.id).toBe('d5b764fe55b3e87c'); - expect(result.message).toBe('Deployment scheduled'); - }); - - it('patch deployment parses a successful response', async () => { - const deploymentId = 'd19b998f347341aa'; - - nock(destination.url) - .patch(`/lm/deployments/${deploymentId}`, body => { - expect(body).toEqual({ - targetStatus: 'STOPPED' - }); - - expect(body).not.toHaveProperty('scenarioId'); - return true; - }) - .reply(200, { - id: 'd5b764fe55b3e87c', - message: 'Deployment modification scheduled' - }, { - 'Content-Type': 'application/json', - 'AI-Resource-Group': 'default' - }); - - const deploymentPatchData: DeploymentModificationRequest = { - targetStatus: 'STOPPED' + ); + + const result: DeploymentList = await DeploymentApi.deploymentQuery( + {}, + { 'AI-Resource-Group': 'default' } + ).execute(destination); + + expect(result).toBeTruthy(); + expect(result.count).toBe(1); + expect(result.resources.length).toBe(1); + + const deployment: Deployment = result.resources[0]; + + expect(deployment.configurationId).toBe( + '7652a231-ba9b-4fcc-b473-2c355cb21b61' + ); + expect(deployment.configurationName).toBe('gpt-4-32k'); + expect(deployment.id).toBe('d19b998f347341aa'); + expect(deployment.status).toBe('RUNNING'); + expect(deployment.startTime).toBe('2024-04-17T15:21:15Z'); + }); + + it('post deployment parses a successful response', async () => { + nock(destination.url).post('/lm/deployments').reply( + 200, + { + deploymentUrl: '', + id: 'd5b764fe55b3e87c', + message: 'Deployment scheduled', + status: 'UNKNOWN' + }, + { + 'Content-Type': 'application/json', + 'AI-Resource-Group': 'default' + } + ); + + const deploymentPostData: DeploymentCreationRequest = { + configurationId: '7652a231-ba9b-4fcc-b473-2c355cb21b61' + }; + + const result: DeploymentCreationResponse = + await DeploymentApi.deploymentCreate(deploymentPostData, { + 'AI-Resource-Group': 'default' + }).execute(destination); + + expect(result).toBeTruthy(); + expect(result.deploymentUrl).toBe(''); + expect(result.id).toBe('d5b764fe55b3e87c'); + expect(result.message).toBe('Deployment scheduled'); + }); + + it('patch deployment parses a successful response', async () => { + const deploymentId = 'd19b998f347341aa'; + + nock(destination.url) + .patch(`/lm/deployments/${deploymentId}`, body => { + expect(body).toEqual({ + targetStatus: 'STOPPED' + }); + + expect(body).not.toHaveProperty('scenarioId'); + return true; + }) + .reply( + 200, + { + id: 'd5b764fe55b3e87c', + message: 'Deployment modification scheduled' + }, + { + 'Content-Type': 'application/json', + 'AI-Resource-Group': 'default' } - - const result: DeploymentModificationResponse = - await DeploymentApi.deploymentModify(deploymentId, deploymentPatchData, {'AI-Resource-Group': 'default'}) - .execute(destination); - - expect(result).toBeTruthy(); - expect(result.id).toBe('d5b764fe55b3e87c'); - expect(result.message).toBe('Deployment modification scheduled'); - - }); - - it('delete deployment parses a successful response', async () => { - const deploymentId = 'd5b764fe55b3e87c'; - - nock(destination.url) - .delete(`/lm/deployments/${deploymentId}`) - .reply(200, { - id: 'd5b764fe55b3e87c', - message: 'Deletion scheduled', - targetStatus: 'DELETED' - }, { - 'Content-Type': 'application/json', - 'AI-Resource-Group': 'default' - }); - - const result: DeploymentDeletionResponse = - await DeploymentApi.deploymentDelete(deploymentId, {'AI-Resource-Group': 'default'}) - .execute(destination); - - expect(result).toBeTruthy(); - expect(result.id).toBe(deploymentId); - expect(result.targetStatus).toBe('DELETED'); - }); -}); \ No newline at end of file + ); + + const deploymentPatchData: DeploymentModificationRequest = { + targetStatus: 'STOPPED' + }; + + const result: DeploymentModificationResponse = + await DeploymentApi.deploymentModify(deploymentId, deploymentPatchData, { + 'AI-Resource-Group': 'default' + }).execute(destination); + + expect(result).toBeTruthy(); + expect(result.id).toBe('d5b764fe55b3e87c'); + expect(result.message).toBe('Deployment modification scheduled'); + }); + + it('delete deployment parses a successful response', async () => { + const deploymentId = 'd5b764fe55b3e87c'; + + nock(destination.url).delete(`/lm/deployments/${deploymentId}`).reply( + 200, + { + id: 'd5b764fe55b3e87c', + message: 'Deletion scheduled', + targetStatus: 'DELETED' + }, + { + 'Content-Type': 'application/json', + 'AI-Resource-Group': 'default' + } + ); + + const result: DeploymentDeletionResponse = + await DeploymentApi.deploymentDelete(deploymentId, { + 'AI-Resource-Group': 'default' + }).execute(destination); + + expect(result).toBeTruthy(); + expect(result.id).toBe(deploymentId); + expect(result.targetStatus).toBe('DELETED'); + }); +}); diff --git a/packages/ai-core/src/client-tests/execution.unit.test.ts b/packages/ai-core/src/client-tests/execution.unit.test.ts index 7c23cd8b..9e6f11ca 100644 --- a/packages/ai-core/src/client-tests/execution.unit.test.ts +++ b/packages/ai-core/src/client-tests/execution.unit.test.ts @@ -1,111 +1,126 @@ import nock from 'nock'; import { HttpDestination } from '@sap-cloud-sdk/connectivity'; import { - EnactmentCreationRequest, - Execution, - ExecutionApi, - ExecutionCreationResponse, - ExecutionList -} from '../index.js' + EnactmentCreationRequest, + Execution, + ExecutionApi, + ExecutionCreationResponse, + ExecutionList +} from '../index.js'; describe('execution unit tests', () => { - let destination: HttpDestination; + let destination: HttpDestination; - beforeAll(() => { - destination = { - url: 'https://api.ai.intprod-eu12.eu-central-1.aws.ml.hana.ondemand.com/v2' - } - }); + beforeAll(() => { + destination = { + url: 'https://api.ai.intprod-eu12.eu-central-1.aws.ml.hana.ondemand.com/v2' + }; + }); + + afterEach(() => { + nock.cleanAll(); + }); - afterEach(() => { - nock.cleanAll(); - }); + it('get execution parses a successful response', async () => { + nock(destination.url) + .get('/lm/executions') + .reply( + 200, + { + count: 1, + resources: [ + { + completionTime: '2023-08-05T14:10:16Z', + configurationId: 'e0a9eb2e-9ea1-43bf-aff5-7660db166676', + configurationName: 'spam-detection-execution-config-0', + createdAt: '2023-08-05T14:07:52Z', + executableId: 'wt-spam-detection-i343697', + id: 'eab289226fe981da', + modifiedAt: '2023-08-05T14:10:54Z', + outputArtifacts: [ + { + createdAt: '2023-08-05T14:10:05Z', + description: '', + executionId: 'eab289226fe981da', + id: 'be0d728f-1cb2-4ff4-97ad-45c54ac592f6', + kind: 'model', + modifiedAt: '2023-08-05T14:10:05Z', + name: 'classifier-model-output', + scenarioId: 'scenario-spam-detection-i343697', + url: 'ai://default/eab289226fe981da/classifier-model-output' + } + ], + scenarioId: 'scenario-spam-detection-i343697', + startTime: '2023-08-05T14:09:21Z', + status: 'COMPLETED', + submissionTime: '2023-08-05T14:09:21Z', + targetStatus: 'COMPLETED' + } + ] + }, + { + 'Content-Type': 'application/json', + 'AI-Resource-Group': 'default' + } + ); - it('get execution parses a successful response', async () => { - nock(destination.url) - .get('/lm/executions') - .reply(200, { - count: 1, - resources: [ - { - completionTime: '2023-08-05T14:10:16Z', - configurationId: 'e0a9eb2e-9ea1-43bf-aff5-7660db166676', - configurationName: 'spam-detection-execution-config-0', - createdAt: '2023-08-05T14:07:52Z', - executableId: 'wt-spam-detection-i343697', - id: 'eab289226fe981da', - modifiedAt: '2023-08-05T14:10:54Z', - outputArtifacts: [ - { - createdAt: '2023-08-05T14:10:05Z', - description: '', - executionId: 'eab289226fe981da', - id: 'be0d728f-1cb2-4ff4-97ad-45c54ac592f6', - kind: 'model', - modifiedAt: '2023-08-05T14:10:05Z', - name: 'classifier-model-output', - scenarioId: 'scenario-spam-detection-i343697', - url: 'ai://default/eab289226fe981da/classifier-model-output' - } - ], - scenarioId: 'scenario-spam-detection-i343697', - startTime: '2023-08-05T14:09:21Z', - status: 'COMPLETED', - submissionTime: '2023-08-05T14:09:21Z', - targetStatus: 'COMPLETED' - } - ] - }, { - 'Content-Type': 'application/json', - 'AI-Resource-Group': 'default' - }); + const result: ExecutionList = await ExecutionApi.executionQuery( + {}, + { 'AI-Resource-Group': 'default' } + ).execute(destination); - const result: ExecutionList = - await ExecutionApi.executionQuery({}, {'AI-Resource-Group': 'default'}) - .execute(destination); + expect(result).not.toBeNull(); + expect(result.count).toEqual(1); + expect(result.resources.length).toEqual(1); - expect(result).not.toBeNull(); - expect(result.count).toEqual(1); - expect(result.resources.length).toEqual(1); + const execution: Execution = result.resources[0]; + const outputArtifacts = execution.outputArtifacts ?? []; - const execution: Execution = result.resources[0]; - const outputArtifacts = execution.outputArtifacts ?? []; + expect(execution.completionTime).toEqual('2023-08-05T14:10:16Z'); + expect(execution.configurationId).toEqual( + 'e0a9eb2e-9ea1-43bf-aff5-7660db166676' + ); + expect(execution.configurationName).toEqual( + 'spam-detection-execution-config-0' + ); + expect(execution.createdAt).toEqual('2023-08-05T14:07:52Z'); + expect(execution.status).toEqual('COMPLETED'); + expect(execution.executableId).toEqual('wt-spam-detection-i343697'); + expect(outputArtifacts[0].id).toEqual( + 'be0d728f-1cb2-4ff4-97ad-45c54ac592f6' + ); + expect(outputArtifacts[0].kind).toEqual('model'); + expect(outputArtifacts[0].url).toEqual( + 'ai://default/eab289226fe981da/classifier-model-output' + ); + }); - expect(execution.completionTime).toEqual('2023-08-05T14:10:16Z'); - expect(execution.configurationId).toEqual('e0a9eb2e-9ea1-43bf-aff5-7660db166676'); - expect(execution.configurationName).toEqual('spam-detection-execution-config-0'); - expect(execution.createdAt).toEqual('2023-08-05T14:07:52Z'); - expect(execution.status).toEqual('COMPLETED'); - expect(execution.executableId).toEqual('wt-spam-detection-i343697'); - expect(outputArtifacts[0].id).toEqual('be0d728f-1cb2-4ff4-97ad-45c54ac592f6'); - expect(outputArtifacts[0].kind).toEqual('model'); - expect(outputArtifacts[0].url).toEqual('ai://default/eab289226fe981da/classifier-model-output'); - }); + it('post execution parses a successful response', async () => { + nock(destination.url).post('/lm/executions').reply( + 200, + { + id: 'eab289226fe981da', + message: 'Execution acknowledged', + url: 'ai://default/eab289226fe981da' + }, + { + 'Content-Type': 'application/json', + 'AI-Resource-Group': 'default' + } + ); - it('post execution parses a successful response', async () => { - nock(destination.url) - .post('/lm/executions') - .reply(200, { - id: 'eab289226fe981da', - message: 'Execution acknowledged', - url: 'ai://default/eab289226fe981da' - }, { - 'Content-Type': 'application/json', - 'AI-Resource-Group': 'default' - }); - - const executionPostData: EnactmentCreationRequest = { - configurationId: 'eab289226fe981da' - } + const executionPostData: EnactmentCreationRequest = { + configurationId: 'eab289226fe981da' + }; - const result: ExecutionCreationResponse = await ExecutionApi - .executionCreate(executionPostData, {'AI-Resource-Group': 'default'}) - .execute(destination); - - expect(result).toBeTruthy(); - expect(result.id).toBe('eab289226fe981da'); - expect(result.message).toBe('Execution acknowledged'); - expect(result.url).toBe('ai://default/eab289226fe981da') - }); + const result: ExecutionCreationResponse = + await ExecutionApi.executionCreate(executionPostData, { + 'AI-Resource-Group': 'default' + }).execute(destination); -}); \ No newline at end of file + expect(result).toBeTruthy(); + expect(result.id).toBe('eab289226fe981da'); + expect(result.message).toBe('Execution acknowledged'); + expect(result.url).toBe('ai://default/eab289226fe981da'); + }); +}); diff --git a/packages/ai-core/src/client-tests/scenario.unit.test.ts b/packages/ai-core/src/client-tests/scenario.unit.test.ts index d59f2ac5..b6bb047d 100644 --- a/packages/ai-core/src/client-tests/scenario.unit.test.ts +++ b/packages/ai-core/src/client-tests/scenario.unit.test.ts @@ -1,62 +1,62 @@ import nock from 'nock'; import { HttpDestination } from '@sap-cloud-sdk/connectivity'; -import { - Scenario, - ScenarioApi, - ScenarioList -} from '../index.js' +import { Scenario, ScenarioApi, ScenarioList } from '../index.js'; describe('scenario unit tests', () => { - let destination: HttpDestination; + let destination: HttpDestination; - beforeAll(() => { - destination = { - url: 'https://api.ai.intprod-eu12.eu-central-1.aws.ml.hana.ondemand.com/v2' - } - }); + beforeAll(() => { + destination = { + url: 'https://api.ai.intprod-eu12.eu-central-1.aws.ml.hana.ondemand.com/v2' + }; + }); + + afterEach(() => { + nock.cleanAll(); + }); - afterEach(() => { - nock.cleanAll(); - }); + it('get scenario parses a successful response', async () => { + nock(destination.url) + .get('/lm/scenarios') + .reply( + 200, + { + count: 1, + resources: [ + { + createdAt: '2024-02-22T17:57:23+00:00', + description: 'AI Core Global Scenario for LLM Access', + id: 'foundation-models', + labels: [ + { + key: 'scenarios.ai.sap.com/llm', + value: 'true' + } + ], + modifiedAt: '2024-05-08T08:41:23+00:00', + name: 'foundation-models' + } + ] + }, + { + 'Content-Type': 'application/json', + 'AI-Resource-Group': 'default' + } + ); - it('get scenario parses a successful response', async () => { - nock(destination.url) - .get('/lm/scenarios') - .reply(200, { - count: 1, - resources: [ - { - createdAt: "2024-02-22T17:57:23+00:00", - description: "AI Core Global Scenario for LLM Access", - id: "foundation-models", - labels: [ - { - key: "scenarios.ai.sap.com/llm", - value: "true" - } - ], - modifiedAt: "2024-05-08T08:41:23+00:00", - name: "foundation-models" - } - ] - }, { - 'Content-Type': 'application/json', - 'AI-Resource-Group': 'default' - }); - - const result: ScenarioList = - await ScenarioApi.scenarioQuery({'AI-Resource-Group': 'default'}) - .execute(destination); + const result: ScenarioList = await ScenarioApi.scenarioQuery({ + 'AI-Resource-Group': 'default' + }).execute(destination); - expect(result).not.toBeNull(); - expect(result.count).toEqual(1); - expect(result.resources.length).toEqual(1); + expect(result).not.toBeNull(); + expect(result.count).toEqual(1); + expect(result.resources.length).toEqual(1); - const scenario: Scenario = result.resources[0]; - expect(scenario.id).toEqual('foundation-models'); - expect(scenario.name).toEqual('foundation-models'); - expect(scenario.labels[0].key).toEqual('scenarios.ai.sap.com/llm'); - expect(scenario.labels[0].value).toEqual('true'); - expect(scenario.modifiedAt).toEqual('2024-05-08T08:41:23+00:00'); - }); -}); \ No newline at end of file + const scenario: Scenario = result.resources[0]; + expect(scenario.id).toEqual('foundation-models'); + expect(scenario.name).toEqual('foundation-models'); + expect(scenario.labels[0].key).toEqual('scenarios.ai.sap.com/llm'); + expect(scenario.labels[0].value).toEqual('true'); + expect(scenario.modifiedAt).toEqual('2024-05-08T08:41:23+00:00'); + }); +});