-
Notifications
You must be signed in to change notification settings - Fork 3.3k
models wrapping + sdk integration with generated client #17071
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
Changes from all commits
3d9b5c6
27f62c1
b1c82d8
48bddc8
6153f28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,12 +55,20 @@ def create_translation_job(self, batch, **kwargs): | |
| :rtype: JobStatusDetail | ||
| """ | ||
|
|
||
| return self._client.document_translation.begin_submit_batch_request( | ||
| inputs=batch, | ||
| polling=True, | ||
| # submit translation job | ||
| response_headers = self._client.document_translation._submit_batch_request_initial( | ||
| inputs = BatchDocumentInput._to_generated_list(batch), | ||
| cls = lambda x,y,z: z, | ||
| **kwargs | ||
| ) | ||
|
|
||
| # get job id from response header | ||
| job_id = response_headers['Operation-Location'] | ||
|
|
||
| # get job status | ||
| return self.get_job_status(job_id) | ||
|
|
||
|
|
||
| @distributed_trace | ||
| def get_job_status(self, job_id, **kwargs): | ||
| # type: (str, **Any) -> JobStatusDetail | ||
|
|
@@ -71,7 +79,8 @@ def get_job_status(self, job_id, **kwargs): | |
| :rtype: ~azure.ai.documenttranslation.JobStatusDetail | ||
| """ | ||
|
|
||
| return self._client.document_translation.get_operation_status(job_id, **kwargs) | ||
| job_status = self._client.document_translation.get_operation_status(job_id, **kwargs) | ||
| return JobStatusDetail._from_generated(job_status) | ||
|
|
||
| @distributed_trace | ||
| def cancel_job(self, job_id, **kwargs): | ||
|
|
@@ -142,7 +151,8 @@ def get_supported_storage_sources(self, **kwargs): | |
|
|
||
| :rtype: List[str] | ||
| """ | ||
| return self._client.document_translation.get_document_storage_source(**kwargs) | ||
| result = self._client.document_translation.get_document_storage_source(**kwargs) | ||
| return result.value | ||
|
|
||
| @distributed_trace | ||
| def get_supported_glossary_formats(self, **kwargs): | ||
|
|
@@ -152,7 +162,8 @@ def get_supported_glossary_formats(self, **kwargs): | |
| :rtype: List[FileFormat] | ||
| """ | ||
|
|
||
| return self._client.document_translation.get_glossary_formats(**kwargs) | ||
| glossary_formats = self._client.document_translation.get_glossary_formats(**kwargs) | ||
| return FileFormat._from_generated_list(glossary_formats) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would it work to fold the helper methods into one like this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i used to do it inline, but i thought it's much cleaner if i created "_from_generated_list()" to process lists |
||
|
|
||
| @distributed_trace | ||
| def get_supported_document_formats(self, **kwargs): | ||
|
|
@@ -162,4 +173,5 @@ def get_supported_document_formats(self, **kwargs): | |
| :rtype: List[FileFormat] | ||
| """ | ||
|
|
||
| return self._client.document_translation.get_document_formats(**kwargs) | ||
| document_formats = self._client.document_translation.get_document_formats(**kwargs) | ||
| return FileFormat._from_generated_list(document_formats) | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,14 @@ | |||||
|
|
||||||
| from typing import Any, List | ||||||
|
|
||||||
| from ._generated.models import ( | ||||||
| BatchRequest as _BatchRequest, | ||||||
| SourceInput as _SourceInput, | ||||||
| DocumentFilter as _DocumentFilter, | ||||||
| TargetInput as _TargetInput, | ||||||
| Glossary as _Glossary | ||||||
| ) | ||||||
|
|
||||||
|
|
||||||
| class TranslationGlossary(object): | ||||||
| """Glossary / translation memory for the request. | ||||||
|
|
@@ -32,6 +40,27 @@ def __init__( | |||||
| self.format_version = kwargs.get("format_version", None) | ||||||
| self.storage_source = kwargs.get("storage_source", None) | ||||||
|
|
||||||
| @classmethod | ||||||
|
mshaban-msft marked this conversation as resolved.
|
||||||
| def _to_generated_list(cls, glossaries): | ||||||
| result = list(_Glossary) | ||||||
|
mshaban-msft marked this conversation as resolved.
|
||||||
| for glossary in glossaries: | ||||||
| if isinstance(TranslationGlossary): | ||||||
| result.append( | ||||||
| _Glossary( | ||||||
| glossary_url = glossary.glossary_url, | ||||||
| format = glossary.format, | ||||||
|
mshaban-msft marked this conversation as resolved.
|
||||||
| version = glossary.version, | ||||||
| storage_source = glossary.storage_source | ||||||
| ) | ||||||
| ) | ||||||
| elif isinstance(str): | ||||||
|
mshaban-msft marked this conversation as resolved.
|
||||||
| result.append( | ||||||
| _Glossary( | ||||||
| glossary_url = glossary, | ||||||
| ) | ||||||
| ) | ||||||
| return result | ||||||
|
|
||||||
|
|
||||||
| class StorageTarget(object): | ||||||
| """Destination for the finished translated documents. | ||||||
|
|
@@ -60,6 +89,19 @@ def __init__( | |||||
| self.glossaries = kwargs.get("glossaries", None) | ||||||
| self.storage_source = kwargs.get("storage_source", None) | ||||||
|
|
||||||
| @classmethod | ||||||
|
mshaban-msft marked this conversation as resolved.
|
||||||
| def _to_generated_list(cls, targets): | ||||||
| return [ | ||||||
| _TargetInput( | ||||||
| target_url = target.target_url, | ||||||
| category = target.category_id, | ||||||
| language = target.language, | ||||||
| storage_source = target.storage_source, | ||||||
| glossaries = TranslationGlossary._to_generated_list(target.glossaries) | ||||||
| ) | ||||||
| for target in targets | ||||||
| ] | ||||||
|
|
||||||
|
|
||||||
| class BatchDocumentInput(object): | ||||||
| """Definition for the input batch translation request. | ||||||
|
|
@@ -97,6 +139,26 @@ def __init__( | |||||
| self.prefix = kwargs.get("prefix", None) | ||||||
| self.suffix = kwargs.get("suffix", None) | ||||||
|
|
||||||
| @classmethod | ||||||
| def _to_generated_list(cls, batch_document_inputs): | ||||||
| return [ | ||||||
| _BatchRequest( | ||||||
| source = _SourceInput( | ||||||
| source_url = batch_document_input.source_url, | ||||||
| filter = _DocumentFilter( | ||||||
| prefix = batch_document_input.prefix, | ||||||
| suffix = batch_document_input.suffix | ||||||
| ), | ||||||
| language = batch_document_input.source_language, | ||||||
| storage_source = batch_document_input.storage_source | ||||||
| ), | ||||||
| targets = StorageTarget._to_generated_list(batch_document_input.targets), | ||||||
| storage_type = batch_document_input.storage_type | ||||||
| ) | ||||||
| for batch_document_input in batch_document_inputs | ||||||
| ] | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
| class JobStatusDetail(object): | ||||||
| """Job status response. | ||||||
|
|
@@ -143,6 +205,23 @@ def __init__( | |||||
| self.documents_cancelled_count = kwargs.get('documents_cancelled_count', None) | ||||||
| self.total_characters_charged = kwargs.get('total_characters_charged', None) | ||||||
|
|
||||||
| @classmethod | ||||||
| def _from_generated(cls, batch_status_details): | ||||||
| return cls( | ||||||
| id = batch_status_details.id, | ||||||
| created_on = batch_status_details.created_date_time_utc, | ||||||
| last_updated_on = batch_status_details.last_action_date_time_utc, | ||||||
| status = batch_status_details.status, | ||||||
| error = DocumentTranslationError._from_generated(batch_status_details.error), | ||||||
| documents_total_count = batch_status_details.summary.total, | ||||||
| documents_failed_count = batch_status_details.summary.failed, | ||||||
| documents_succeeded_count = batch_status_details.summary.success, | ||||||
| documents_in_progress_count = batch_status_details.summary.in_progress, | ||||||
| documents_not_yet_started_count = batch_status_details.summary.not_yet_started, | ||||||
| documents_cancelled_count = batch_status_details.summary.cancelled, | ||||||
| total_characters_charged = batch_status_details.summary.total_character_charged | ||||||
| ) | ||||||
|
|
||||||
|
|
||||||
| class DocumentStatusDetail(object): | ||||||
| """DocumentStatusDetail. | ||||||
|
|
@@ -210,6 +289,14 @@ def __init__( | |||||
| self.message = None | ||||||
| self.target = None | ||||||
|
|
||||||
| @classmethod | ||||||
| def _from_generated(cls, error): | ||||||
| return cls( | ||||||
| code=error.code, | ||||||
| message=error.message, | ||||||
| target=error.target | ||||||
| ) | ||||||
|
|
||||||
|
|
||||||
| class FileFormat(object): | ||||||
| """FileFormat. | ||||||
|
|
@@ -233,3 +320,16 @@ def __init__( | |||||
| self.file_extensions = kwargs.get('file_extensions', None) | ||||||
| self.content_types = kwargs.get('content_types', None) | ||||||
| self.versions = kwargs.get('versions', None) | ||||||
|
|
||||||
| @classmethod | ||||||
| def _from_generated(cls, file_format): | ||||||
| return cls( | ||||||
| format=file_format.format, | ||||||
| file_extentions=file_format.file_extentions, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ?!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spelling
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry :) |
||||||
| content_types=file_format.content_types, | ||||||
| versions=file_format.versions | ||||||
| ) | ||||||
|
|
||||||
| @classmethod | ||||||
| def _from_generated_list(cls, file_formats): | ||||||
| return list( [ FileFormat._from_generated(file_formats) for file_formats in file_formats ] ) | ||||||
Uh oh!
There was an error while loading. Please reload this page.