|
10 | 10 | Any, |
11 | 11 | Union, |
12 | 12 | List, |
| 13 | + Optional, |
| 14 | + Mapping, |
13 | 15 | ) |
14 | 16 | from azure.core.credentials import AzureKeyCredential, TokenCredential |
15 | 17 | from azure.core.tracing.decorator import distributed_trace |
|
26 | 28 | from ._document_analysis_client import DocumentAnalysisClient |
27 | 29 | from ._models import ( |
28 | 30 | ModelBuildMode, |
| 31 | + DocumentClassifierDetails, |
29 | 32 | DocumentModelDetails, |
30 | 33 | DocumentModelSummary, |
31 | 34 | OperationDetails, |
32 | 35 | OperationSummary, |
33 | 36 | ResourceDetails, |
34 | 37 | TargetAuthorization, |
35 | 38 | ) |
| 39 | +from ._generated.models import ClassifierDocumentTypeDetails |
36 | 40 |
|
37 | 41 |
|
38 | 42 | class DocumentModelAdministrationClient(FormRecognizerClientBase): |
@@ -509,6 +513,161 @@ def get_operation(self, operation_id: str, **kwargs: Any) -> OperationDetails: |
509 | 513 | api_version=self._api_version, |
510 | 514 | ) |
511 | 515 |
|
| 516 | + @distributed_trace |
| 517 | + def begin_build_document_classifier( |
| 518 | + self, |
| 519 | + doc_types: Mapping[str, ClassifierDocumentTypeDetails], |
| 520 | + *, |
| 521 | + classifier_id: Optional[str] = None, |
| 522 | + description: Optional[str] = None, |
| 523 | + **kwargs: Any |
| 524 | + ) -> DocumentModelAdministrationLROPoller[DocumentClassifierDetails]: |
| 525 | + """Build a document classifier. For more information on how to build and train |
| 526 | + a custom classifier model, see https://aka.ms/azsdk/formrecognizer/buildclassifiermodel. |
| 527 | +
|
| 528 | + :param doc_types: Required. Mapping of document types to classify against. |
| 529 | + :keyword str classifier_id: Unique document classifier name. |
| 530 | + If not specified, a classifier ID will be created for you. |
| 531 | + :keyword str description: Document classifier description. |
| 532 | + :return: An instance of an DocumentModelAdministrationLROPoller. Call `result()` on the poller |
| 533 | + object to return a :class:`~azure.ai.formrecognizer.DocumentClassifierDetails`. |
| 534 | + :rtype: ~azure.ai.formrecognizer.DocumentModelAdministrationLROPoller[DocumentClassifierDetails] |
| 535 | + :raises ~azure.core.exceptions.HttpResponseError: |
| 536 | +
|
| 537 | + .. versionadded:: 2023-02-28-preview |
| 538 | + The *begin_build_document_classifier* client method. |
| 539 | +
|
| 540 | + .. admonition:: Example: |
| 541 | +
|
| 542 | + .. literalinclude:: ../samples/v3.2/sample_build_classifier.py |
| 543 | + :start-after: [START build_classifier] |
| 544 | + :end-before: [END build_classifier] |
| 545 | + :language: python |
| 546 | + :dedent: 4 |
| 547 | + :caption: Build a document classifier. |
| 548 | + """ |
| 549 | + def callback(raw_response, _, headers): # pylint: disable=unused-argument |
| 550 | + op_response = \ |
| 551 | + self._deserialize(self._generated_models.DocumentClassifierBuildOperationDetails, raw_response) |
| 552 | + model_info = self._deserialize(self._generated_models.DocumentClassifierDetails, op_response.result) |
| 553 | + return DocumentClassifierDetails._from_generated(model_info) |
| 554 | + |
| 555 | + if self._api_version == DocumentAnalysisApiVersion.V2022_08_31: |
| 556 | + raise ValueError("Method 'begin_build_document_classifier()' is only available for API version " |
| 557 | + "V2023_02_28_PREVIEW and later") |
| 558 | + cls = kwargs.pop("cls", callback) |
| 559 | + continuation_token = kwargs.pop("continuation_token", None) |
| 560 | + polling_interval = kwargs.pop("polling_interval", self._client._config.polling_interval) |
| 561 | + if classifier_id is None: |
| 562 | + classifier_id = str(uuid.uuid4()) |
| 563 | + |
| 564 | + return self._client.document_classifiers.begin_build_classifier( |
| 565 | + build_request=self._generated_models.BuildDocumentClassifierRequest( |
| 566 | + classifier_id=classifier_id, |
| 567 | + description=description, |
| 568 | + doc_types=doc_types, |
| 569 | + ), |
| 570 | + cls=cls, |
| 571 | + continuation_token=continuation_token, |
| 572 | + polling=LROBasePolling( |
| 573 | + timeout=polling_interval, lro_algorithms=[DocumentModelAdministrationPolling()], **kwargs |
| 574 | + ), |
| 575 | + **kwargs |
| 576 | + ) |
| 577 | + |
| 578 | + @distributed_trace |
| 579 | + def get_document_classifier(self, classifier_id: str, **kwargs: Any) -> DocumentClassifierDetails: |
| 580 | + """Get a document classifier by its ID. |
| 581 | +
|
| 582 | + :param str classifier_id: Classifier identifier. |
| 583 | + :return: DocumentClassifierDetails |
| 584 | + :rtype: ~azure.ai.formrecognizer.DocumentClassifierDetails |
| 585 | + :raises ~azure.core.exceptions.HttpResponseError or ~azure.core.exceptions.ResourceNotFoundError: |
| 586 | +
|
| 587 | + .. versionadded:: 2023-02-28-preview |
| 588 | + The *get_document_classifier* client method. |
| 589 | +
|
| 590 | + .. admonition:: Example: |
| 591 | +
|
| 592 | + .. literalinclude:: ../samples/v3.2/sample_manage_classifiers.py |
| 593 | + :start-after: [START get_document_classifier] |
| 594 | + :end-before: [END get_document_classifier] |
| 595 | + :language: python |
| 596 | + :dedent: 4 |
| 597 | + :caption: Get a classifier by its ID. |
| 598 | + """ |
| 599 | + |
| 600 | + if not classifier_id: |
| 601 | + raise ValueError("classifier_id cannot be None or empty.") |
| 602 | + |
| 603 | + if self._api_version == DocumentAnalysisApiVersion.V2022_08_31: |
| 604 | + raise ValueError("Method 'get_document_classifier()' is only available for API version " |
| 605 | + "V2023_02_28_PREVIEW and later") |
| 606 | + response = self._client.document_classifiers.get_classifier(classifier_id=classifier_id, **kwargs) |
| 607 | + return DocumentClassifierDetails._from_generated(response) |
| 608 | + |
| 609 | + @distributed_trace |
| 610 | + def list_document_classifiers(self, **kwargs: Any) -> ItemPaged[DocumentClassifierDetails]: |
| 611 | + """List information for each document classifier, including its classifier ID, |
| 612 | + description, and when it was created. |
| 613 | +
|
| 614 | + :return: Pageable of DocumentClassifierDetails. |
| 615 | + :rtype: ~azure.core.paging.ItemPaged[DocumentClassifierDetails] |
| 616 | + :raises ~azure.core.exceptions.HttpResponseError: |
| 617 | +
|
| 618 | + .. versionadded:: 2023-02-28-preview |
| 619 | + The *list_document_classifiers* client method. |
| 620 | +
|
| 621 | + .. admonition:: Example: |
| 622 | +
|
| 623 | + .. literalinclude:: ../samples/v3.2/sample_manage_classifiers.py |
| 624 | + :start-after: [START list_document_classifiers] |
| 625 | + :end-before: [END list_document_classifiers] |
| 626 | + :language: python |
| 627 | + :dedent: 4 |
| 628 | + :caption: List all classifiers that were built successfully under the Form Recognizer resource. |
| 629 | + """ |
| 630 | + |
| 631 | + if self._api_version == DocumentAnalysisApiVersion.V2022_08_31: |
| 632 | + raise ValueError("Method 'list_document_classifiers()' is only available for API version " |
| 633 | + "V2023_02_28_PREVIEW and later") |
| 634 | + return self._client.document_classifiers.list_classifiers( # type: ignore |
| 635 | + cls=kwargs.pop( |
| 636 | + "cls", |
| 637 | + lambda objs: [DocumentClassifierDetails._from_generated(x) for x in objs], |
| 638 | + ), |
| 639 | + **kwargs |
| 640 | + ) |
| 641 | + |
| 642 | + @distributed_trace |
| 643 | + def delete_document_classifier(self, classifier_id: str, **kwargs: Any) -> None: |
| 644 | + """Delete a document classifier. |
| 645 | +
|
| 646 | + :param str classifier_id: Classifier identifier. |
| 647 | + :rtype: None |
| 648 | + :raises ~azure.core.exceptions.HttpResponseError or ~azure.core.exceptions.ResourceNotFoundError: |
| 649 | +
|
| 650 | + .. versionadded:: 2023-02-28-preview |
| 651 | + The *delete_document_classifier* client method. |
| 652 | +
|
| 653 | + .. admonition:: Example: |
| 654 | +
|
| 655 | + .. literalinclude:: ../samples/v3.2/sample_manage_classifiers.py |
| 656 | + :start-after: [START delete_document_classifier] |
| 657 | + :end-before: [END delete_document_classifier] |
| 658 | + :language: python |
| 659 | + :dedent: 4 |
| 660 | + :caption: Delete a classifier. |
| 661 | + """ |
| 662 | + |
| 663 | + if not classifier_id: |
| 664 | + raise ValueError("classifier_id cannot be None or empty.") |
| 665 | + |
| 666 | + if self._api_version == DocumentAnalysisApiVersion.V2022_08_31: |
| 667 | + raise ValueError("Method 'delete_document_classifier()' is only available for API version " |
| 668 | + "V2023_02_28_PREVIEW and later") |
| 669 | + return self._client.document_classifiers.delete_classifier(classifier_id=classifier_id, **kwargs) |
| 670 | + |
512 | 671 | def get_document_analysis_client(self, **kwargs: Any) -> DocumentAnalysisClient: |
513 | 672 | """Get an instance of a DocumentAnalysisClient from DocumentModelAdministrationClient. |
514 | 673 |
|
|
0 commit comments