-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Component/Pipeline]: Add Typescript/JavaScript samples for SDKv2 (#2080
) * update * update * [PipelineJob]: Add Typescript/JavaScript samples for SDKv2 (#2087) * add sample * update * update * fix indent * Update sdk/typescript/src/resources/jobs/pipelines/pipelineJobCreateOrUpdateSample.ts Co-authored-by: guanghechen <42513619+guanghechen@users.noreply.github.com> * update gitignore * update folder structure * remove not supported delete sample --------- Co-authored-by: guanghechen <42513619+guanghechen@users.noreply.github.com> Co-authored-by: Clement Wang <clwan@microsoft.com> --------- Co-authored-by: Ying Chen <2601502859@qq.com> Co-authored-by: Han Wang <phoenix.seek@gmail.com> Co-authored-by: guanghechen <42513619+guanghechen@users.noreply.github.com> Co-authored-by: Clement Wang <clwan@microsoft.com>
- Loading branch information
1 parent
1bf6286
commit 672e378
Showing
6 changed files
with
270 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ config.json | |
*.log | ||
scratch/* | ||
config-amlexamples.json | ||
node_modules |
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
85 changes: 85 additions & 0 deletions
85
sdk/typescript/src/assets/component/componentVersionsCreateOrUpdateSample.ts
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,85 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { | ||
ComponentVersion, | ||
} from "@azure/arm-machinelearning"; | ||
import { client, getEnvironmentVariable } from "../../utils"; | ||
|
||
// Load the .env file if it exists | ||
import * as dotenv from "dotenv"; | ||
dotenv.config(); | ||
|
||
const resourceGroupName = getEnvironmentVariable("RESOURCEGROUP_NAME"); | ||
const workspaceName = getEnvironmentVariable("WORKSPACE_NAME"); | ||
|
||
/** | ||
* This sample demonstrates how to Create or update version. | ||
* | ||
* @summary Create or update version. | ||
* x-ms-original-file: specification/machinelearningservices/resource-manager/Microsoft.MachineLearningServices/stable/2022-10-01/examples/ComponentVersion/createOrUpdate.json | ||
*/ | ||
export async function createOrUpdateComponentVersion() : Promise<void> { | ||
const name = "command_component_basic"; | ||
const version = "0.0.1"; | ||
const body: ComponentVersion = { | ||
properties: { | ||
description: "This is the basic command component", | ||
componentSpec: { | ||
'command': 'echo Hello World & echo $[[${{inputs.component_in_number}}]] & echo $[[${{inputs.component_in_path}}]] & echo ${{outputs.component_out_path}} > ${{outputs.component_out_path}}/component_in_number', | ||
'environment': 'azureml:AzureML-sklearn-0.24-ubuntu18.04-py37-cpu:1', | ||
'name': 'command_component_basic', | ||
'description': 'This is the basic command component', | ||
'tags': { 'tag': 'tagvalue', 'owner': 'sdkteam' }, | ||
'version': '0.0.1', | ||
'$schema': 'https://azuremlschemas.azureedge.net/development/commandComponent.schema.json', | ||
'display_name': 'CommandComponentBasic', | ||
'is_deterministic': true, | ||
'inputs': { | ||
'component_in_number': { 'type': 'number', 'optional': true, 'default': '10.99', 'description': 'A number' }, | ||
'component_in_path': { 'type': 'uri_folder', 'optional': true, 'description': 'A path' } | ||
}, | ||
'outputs': { 'component_out_path': { 'type': 'uri_folder' } }, | ||
'type': 'command', | ||
'_source': 'YAML.COMPONENT' | ||
}, | ||
isAnonymous: false, | ||
properties: {}, | ||
tags: { 'tag': 'tagvalue', 'owner': 'sdkteam' } | ||
} | ||
}; | ||
// const credential = new DefaultAzureCredential(); | ||
// const client = new AzureMachineLearningWorkspaces(credential, subscriptionId); | ||
try { | ||
console.log("Create or update component version ...") | ||
const componentVersionsCreateOrUpdateResponse = await client.componentVersions.createOrUpdate( | ||
resourceGroupName, | ||
workspaceName, | ||
name, | ||
version, | ||
body | ||
); | ||
console.log(componentVersionsCreateOrUpdateResponse); | ||
console.log(`Created or update component ${componentVersionsCreateOrUpdateResponse.name} successfully`); | ||
} catch (err: any) { | ||
console.log( | ||
`errorMessage - ${err.message}\n` | ||
) | ||
} | ||
} | ||
|
||
// createOrUpdateComponentVersion().catch(console.error); | ||
export async function main(): Promise<void> { | ||
// This sample uses DefaultAzureCredential, which supports a number of authentication mechanisms. | ||
// See https://docs.microsoft.com/javascript/api/overview/azure/identity-readme?view=azure-node-latest for more information | ||
// about DefaultAzureCredential and the other credentials that are available for use. | ||
await createOrUpdateComponentVersion(); | ||
} | ||
|
||
main().catch((error: any) => { | ||
console.error("An error occurred:", error); | ||
console.log("error code: ", error.code); | ||
console.log("error message: ", error.message); | ||
console.log("error stack: ", error.stack); | ||
process.exit(1); | ||
}); |
52 changes: 52 additions & 0 deletions
52
sdk/typescript/src/assets/component/componentVersionsGetSample.ts
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,52 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { client, getEnvironmentVariable } from "../../utils"; | ||
// Load the .env file if it exists | ||
import * as dotenv from "dotenv"; | ||
dotenv.config(); | ||
|
||
const resourceGroupName = getEnvironmentVariable("RESOURCEGROUP_NAME"); | ||
const workspaceName = getEnvironmentVariable("WORKSPACE_NAME"); | ||
|
||
/** | ||
* This sample demonstrates how to Get version. | ||
* | ||
* @summary Get version. | ||
* x-ms-original-file: specification/machinelearningservices/resource-manager/Microsoft.MachineLearningServices/stable/2022-10-01/examples/ComponentVersion/get.json | ||
*/ | ||
async function getComponentVersion(): Promise<void> { | ||
const name = "command_component_basic"; | ||
const version = "0.0.1"; | ||
try { | ||
console.log("Get component ...") | ||
const componentVersionsGetResponse = await client.componentVersions.get( | ||
resourceGroupName, | ||
workspaceName, | ||
name, | ||
version | ||
); | ||
console.log(componentVersionsGetResponse); | ||
console.log(`Get component ${componentVersionsGetResponse.name} successfully`); | ||
} catch (err: any) { | ||
console.log( | ||
`errorMessage - ${err.message}\n` | ||
) | ||
} | ||
} | ||
|
||
// getComponentVersion().catch(console.error); | ||
export async function main(): Promise<void> { | ||
// This sample uses DefaultAzureCredential, which supports a number of authentication mechanisms. | ||
// See https://docs.microsoft.com/javascript/api/overview/azure/identity-readme?view=azure-node-latest for more information | ||
// about DefaultAzureCredential and the other credentials that are available for use. | ||
await getComponentVersion(); | ||
} | ||
|
||
main().catch((error: any) => { | ||
console.error("An error occurred:", error); | ||
console.log("error code: ", error.code); | ||
console.log("error message: ", error.message); | ||
console.log("error stack: ", error.stack); | ||
process.exit(1); | ||
}); |
55 changes: 55 additions & 0 deletions
55
sdk/typescript/src/assets/component/componentVersionsListSample.ts
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,55 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
import { | ||
ComponentVersion, | ||
ComponentVersionsListOptionalParams, | ||
} from "@azure/arm-machinelearning"; | ||
|
||
import { client, getEnvironmentVariable } from "../../utils"; | ||
// Load the .env file if it exists | ||
import * as dotenv from "dotenv"; | ||
dotenv.config(); | ||
|
||
const resourceGroupName = getEnvironmentVariable("RESOURCEGROUP_NAME"); | ||
const workspaceName = getEnvironmentVariable("WORKSPACE_NAME"); | ||
|
||
/** | ||
* This sample demonstrates how to List component versions. | ||
* | ||
* @summary List component versions. | ||
* x-ms-original-file: specification/machinelearningservices/resource-manager/Microsoft.MachineLearningServices/stable/2022-10-01/examples/ComponentVersion/list.json | ||
*/ | ||
async function listComponentVersion(): Promise<void> { | ||
const name = "command_component_basic"; | ||
const orderBy = "createdtime desc"; | ||
const top = 1; | ||
const options: ComponentVersionsListOptionalParams = { orderBy, top }; | ||
const resArray = new Array<ComponentVersion>(); | ||
for await (let componentItem of client.componentVersions.list( | ||
resourceGroupName, | ||
workspaceName, | ||
name, | ||
options | ||
)) { | ||
resArray.push(componentItem); | ||
console.log(componentItem); | ||
} | ||
console.log(resArray); | ||
} | ||
|
||
// listComponentVersion().catch(console.error); | ||
export async function main(): Promise<void> { | ||
// This sample uses DefaultAzureCredential, which supports a number of authentication mechanisms. | ||
// See https://docs.microsoft.com/javascript/api/overview/azure/identity-readme?view=azure-node-latest for more information | ||
// about DefaultAzureCredential and the other credentials that are available for use. | ||
console.log("Listing the Component"); | ||
await listComponentVersion(); | ||
} | ||
|
||
main().catch((error) => { | ||
console.error("An error occurred:", error); | ||
console.log("error code: ", error.code); | ||
console.log("error message: ", error.message); | ||
console.log("error stack: ", error.stack); | ||
process.exit(1); | ||
}); |
75 changes: 75 additions & 0 deletions
75
sdk/typescript/src/jobs/pipelines/pipelineJobCreateOrUpdateSample.ts
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,75 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { | ||
JobBase, | ||
} from "@azure/arm-machinelearning"; | ||
import { client, getEnvironmentVariable } from "../../utils"; | ||
import { createOrUpdateComponentVersion } from "../../assets/component/componentVersionsCreateOrUpdateSample"; | ||
|
||
// Load the .env file if it exists | ||
import * as dotenv from "dotenv"; | ||
dotenv.config(); | ||
|
||
const resourceGroupName = getEnvironmentVariable("RESOURCEGROUP_NAME"); | ||
const workspaceName = getEnvironmentVariable("WORKSPACE_NAME"); | ||
|
||
/** | ||
* This sample demonstrates how to Create or update pipeline job. | ||
* | ||
* @summary Create or update version. | ||
*/ | ||
async function createOrUpdatePipelineJob(): Promise<void> { | ||
// create a simple component | ||
await createOrUpdateComponentVersion(); | ||
const name = "simple_pipeline_job"; | ||
const body: JobBase = { | ||
properties: { | ||
description: "This is the basic pipeline job", | ||
computeId: "cpu-cluster", | ||
jobType: "Pipeline", | ||
jobs: { | ||
"node1": { | ||
"name": "node1", | ||
"type": "command", | ||
"componentId": "command_component_basic:0.0.1" | ||
} | ||
}, | ||
properties: {}, | ||
tags: { 'tag': 'tagvalue', 'owner': 'sdkteam' } | ||
} | ||
}; | ||
// const credential = new DefaultAzureCredential(); | ||
// const client = new AzureMachineLearningWorkspaces(credential, subscriptionId); | ||
try { | ||
console.log("Create or update pipeline job ...") | ||
const pipelineJobCreateOrUpdateResponse = await client.jobs.createOrUpdate( | ||
resourceGroupName, | ||
workspaceName, | ||
name, | ||
body | ||
); | ||
console.log(pipelineJobCreateOrUpdateResponse); | ||
console.log(`Created or update pipeline job ${pipelineJobCreateOrUpdateResponse.name} successfully`); | ||
} catch (err: any) { | ||
console.log( | ||
`errorMessage - ${err.message}\n` | ||
) | ||
} | ||
} | ||
|
||
// createOrUpdateComponentVersion().catch(console.error); | ||
export async function main(): Promise<void> { | ||
// This sample uses DefaultAzureCredential, which supports a number of authentication mechanisms. | ||
// See https://docs.microsoft.com/javascript/api/overview/azure/identity-readme?view=azure-node-latest for more information | ||
// about DefaultAzureCredential and the other credentials that are available for use. | ||
await createOrUpdatePipelineJob(); | ||
} | ||
|
||
main().catch((error: any) => { | ||
console.error("An error occurred:", error); | ||
console.log("error code: ", error.code); | ||
console.log("error message: ", error.message); | ||
console.log("error stack: ", error.stack); | ||
process.exit(1); | ||
}); |