-
Notifications
You must be signed in to change notification settings - Fork 333
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
Adds spp model apply
command. Closes #6119
#6453
base: main
Are you sure you want to change the base?
Conversation
Thank you for the PR and the additional info @mkm17! We'll get back to you ASAP. |
@mkm17 I added the |
c69155f
to
f366ea7
Compare
@mkm17, could you resolve the merge conflicts, please? |
f366ea7
to
d7d8e52
Compare
hi @milanholemans , I apologize for the delay, but I finally found some time to resolve the conflicts here. I have also reviewed the code and made the changes you pointed out in some other |
Hi @mkm17, sorry again, could you resolve the conflicts? Will try to review it ASAP when they are resolved. |
d7d8e52
to
4bd3c1e
Compare
Conflicts resolved :) |
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.
First of all, sorry for the late review. The last couple of weeks were a bit hectic for me. Anyway, I did a first review, and it looks already quite good. In the meantime, could you also rebase your branch with the latest main
? There are no merge conflicts, but main
contains some updated logic about how we call the telemetry collection function.
#initOptions(): void { | ||
this.options.unshift( | ||
{ | ||
option: '-u, --siteUrl <siteUrl>' |
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.
Since a list can be on a sub site, I'm wondering if we should rename this option to webUrl
instead. However, it would be inconsistent with the other spp model
commands. Is it possible to create/list/remove models on a sub site? If so, maybe we should consider renaming their option as well.
if (args.options.id && !validation.isValidGuid(args.options.id)) { | ||
return `${args.options.id} in parameter id is not a valid GUID`; | ||
} | ||
|
||
if (args.options.listId && | ||
!validation.isValidGuid(args.options.listId)) { | ||
return `${args.options.listId} in parameter listId is not a valid GUID`; | ||
} |
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.
if (args.options.id && !validation.isValidGuid(args.options.id)) { | |
return `${args.options.id} in parameter id is not a valid GUID`; | |
} | |
if (args.options.listId && | |
!validation.isValidGuid(args.options.listId)) { | |
return `${args.options.listId} in parameter listId is not a valid GUID`; | |
} | |
if (args.options.id && !validation.isValidGuid(args.options.id)) { | |
return `${args.options.id} is not a valid GUID for option 'id'.`; | |
} | |
if (args.options.listId && | |
!validation.isValidGuid(args.options.listId)) { | |
return `${args.options.listId} is not a valid GUID for option 'listId'.`; | |
} |
return `${args.options.listId} in parameter listId is not a valid GUID`; | ||
} | ||
|
||
if (typeof args.options.viewOption !== 'undefined') { |
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.
We shouldn't compare it with a string, right?
if (typeof args.options.viewOption !== 'undefined') { | |
if (typeof args.options.viewOption !== undefined) { |
} | ||
|
||
if (typeof args.options.viewOption !== 'undefined') { | ||
if (!this.viewOptions.some(viewOption => viewOption.toLocaleLowerCase() === args.options.viewOption?.toLowerCase())) { |
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.
if (!this.viewOptions.some(viewOption => viewOption.toLocaleLowerCase() === args.options.viewOption?.toLowerCase())) { | |
if (!this.viewOptions.some(viewOption => viewOption.toLowerCase() === args.options.viewOption?.toLowerCase())) { |
|
||
if (typeof args.options.viewOption !== 'undefined') { | ||
if (!this.viewOptions.some(viewOption => viewOption.toLocaleLowerCase() === args.options.viewOption?.toLowerCase())) { | ||
return `The value of parameter viewOption must be ${this.viewOptions.join(', ')}`; |
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.
return `The value of parameter viewOption must be ${this.viewOptions.join(', ')}`; | |
return `The value of parameter viewOption must be: ${this.viewOptions.join(', ')}.`; |
|
||
before(() => { | ||
sinon.stub(auth, 'restoreAuth').resolves(); | ||
sinon.stub(telemetry, 'trackEvent').returns(); |
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.
sinon.stub(telemetry, 'trackEvent').returns(); | |
sinon.stub(telemetry, 'trackEvent').resolves(); |
await assert.rejects(command.action(logger, { options: { siteUrl: 'https://contoso.sharepoint.com/sites/sales', contentCenterUrl: 'https://contoso.sharepoint.com/sites/contentCenter', id: '9b1b1e42-794b-4c71-93ac-5ed92488b67f', listId: '421b1e42-794b-4c71-93ac-5ed92488b67d' } }), new CommandError('List does not exist. The page you selected contains a list that does not exist. It may have been deleted by another user.')); | ||
}); | ||
|
||
it('corretly handles error when try to apply model to SP list', async () => { |
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.
it('corretly handles error when try to apply model to SP list', async () => { | |
it('correctly handles error when try to apply model to SP list', async () => { |
Test names below have the same typo.
throw `${opts.url} is invalid request`; | ||
}); | ||
|
||
await assert.rejects(command.action(logger, { options: { siteUrl: 'https://contoso.sharepoint.com/sites/sales', contentCenterUrl: 'https://contoso.sharepoint.com/sites/contentCenter', id: '9b1b1e42-794b-4c71-93ac-5ed92488b67f', listId: '421b1e42-794b-4c71-93ac-5ed92488b67d' } }), new CommandError('List does not exist. The page you selected contains a list that does not exist. It may have been deleted by another user.')); |
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.
Let's put the error on a new line to make it a bit more readable (same with other tests).
await assert.rejects(command.action(logger, { options: { siteUrl: 'https://contoso.sharepoint.com/sites/sales', contentCenterUrl: 'https://contoso.sharepoint.com/sites/contentCenter', id: '9b1b1e42-794b-4c71-93ac-5ed92488b67f', listId: '421b1e42-794b-4c71-93ac-5ed92488b67d' } }), new CommandError('List does not exist. The page you selected contains a list that does not exist. It may have been deleted by another user.')); | |
await assert.rejects(command.action(logger, { options: { siteUrl: 'https://contoso.sharepoint.com/sites/sales', contentCenterUrl: 'https://contoso.sharepoint.com/sites/contentCenter', id: '9b1b1e42-794b-4c71-93ac-5ed92488b67f', listId: '421b1e42-794b-4c71-93ac-5ed92488b67d' } }), | |
new CommandError('List does not exist. The page you selected contains a list that does not exist. It may have been deleted by another user.')); |
: Server or web-relative URL of the library to which the model will be applied. Specify either `listTitle`, `listId`, or `listUrl` but not multiple. | ||
|
||
`--viewOption [viewOption]` | ||
: Defines whether the model view should be set as the default view for the document library. Allowed values are: `NewViewAsDefault`, `DoNotChangeDefault`, `TileViewAsDefault`. |
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.
Let's also describe which value is used as default.
Applies a trained document understanding model using its unique ID to a document library, identified by its title. | ||
|
||
```sh | ||
m365 spp model apply --siteUrl "https://contoso.sharepoint.com" --contentCenterUrl "https://contoso.sharepoint.com/sites/ContentCenter" --id "7645e69d-21fb-4a24-a17a-9bdfa7cb63dc" --listTitle "Shared Documents" | ||
``` | ||
|
||
Applies a trained document understanding model using its display name to a document library, identified by its title. | ||
|
||
```sh | ||
m365 spp model apply --siteUrl "https://contoso.sharepoint.com" --contentCenterUrl "https://contoso.sharepoint.com/sites/ContentCenter" --title "ModelExample" --listTitle "Shared Documents" | ||
``` | ||
|
||
Applies a trained document understanding model using its display name to a document library, identified by its URL. | ||
|
||
```sh | ||
m365 spp model apply --siteUrl "https://contoso.sharepoint.com" --contentCenterUrl "https://contoso.sharepoint.com/sites/ContentCenter" --title "ModelExample" --listUrl "/Shared Documents" | ||
``` | ||
|
||
Applies a trained document understanding model using its display name to a document library, identified by its unique ID. | ||
|
||
```sh | ||
m365 spp model apply --siteUrl "https://contoso.sharepoint.com" --contentCenterUrl "https://contoso.sharepoint.com/sites/ContentCenter" --title "ModelExample" --listId "b4cfa0d9-b3d7-49ae-a0f0-f14ffdd005f7" | ||
``` |
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.
Could we also use viewOption
at least in one example?
Great suggestion, feel free to add it to this PR as well. |
Adds
spp model apply
command. Closes #6119I realized I forgot to add a parameter needed to locate the content site where the model is stored:
contentCenterUrl
Let me know if name is ok. We can change it to modelContentSiteUrl or something else.
I also modified the
viewOption
parameter. During testing, I saw that it’s possible to set three different values:NewViewAsDefault
,DoNotChangeDefault
,TileViewAsDefault
The API does not return an error when attempting to apply a model to a custom SharePoint List. However, I’ve added a condition to check if the list is a document library. I hope that’s ok.
potentially, when the
spp model get
command is approved, thegetModel
function from this command should be exported to thespp.ts
file so it can be used by both commands.