From 241081c023182f2787c3c5928e27b461b14c0647 Mon Sep 17 00:00:00 2001 From: Jenny Wong Date: Thu, 24 Oct 2024 15:09:58 -0700 Subject: [PATCH] wip --- README.md | 5 +++-- src/rev_ai/__init__.py | 3 ++- src/rev_ai/apiclient.py | 14 ++++++++++---- src/rev_ai/generic_api_client.py | 12 ++++++++++-- src/rev_ai/language_identification_client.py | 9 ++++++--- src/rev_ai/models/__init__.py | 1 + .../models/revaiapi_deployment_config_constants.py | 10 ++++++++++ 7 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 src/rev_ai/models/revaiapi_deployment_config_constants.py diff --git a/README.md b/README.md index b29d82ca..b3bc35dd 100644 --- a/README.md +++ b/README.md @@ -29,10 +29,11 @@ your [AccessToken Settings Page](https://www.rev.ai/access_token). Create a clie generated Access Token: ```python -from rev_ai import apiclient +from rev_ai import apiclient, RevAiApiDeploymentConfigMap, RevAiApiDeployment # create your client -client = apiclient.RevAiAPIClient("ACCESS TOKEN") +# optionally configure the Rev AI deployment to use +client = apiclient.RevAiAPIClient("ACCESS TOKEN", RevAiApiDeploymentConfigMap[RevAiApiDeployment.US]['base_url']) ``` ### Sending a file diff --git a/src/rev_ai/__init__.py b/src/rev_ai/__init__.py index 34da121f..e540c97f 100644 --- a/src/rev_ai/__init__.py +++ b/src/rev_ai/__init__.py @@ -6,4 +6,5 @@ from .models import Job, JobStatus, Account, Transcript, Monologue, Element, MediaConfig, \ CaptionType, CustomVocabulary, TopicExtractionJob, TopicExtractionResult, Topic, Informant, \ SpeakerName, LanguageIdentificationJob, LanguageIdentificationResult, LanguageConfidence, \ - SentimentAnalysisResult, SentimentValue, SentimentMessage, SentimentAnalysisJob, CustomerUrlData + SentimentAnalysisResult, SentimentValue, SentimentMessage, SentimentAnalysisJob, CustomerUrlData, \ + RevAiApiDeploymentConfigMap, RevAiApiDeployment diff --git a/src/rev_ai/apiclient.py b/src/rev_ai/apiclient.py index 34bd483a..f2ffdde9 100644 --- a/src/rev_ai/apiclient.py +++ b/src/rev_ai/apiclient.py @@ -5,11 +5,12 @@ from . import utils from .baseclient import BaseClient -from .models import Account, CaptionType, Job, Transcript +from .models import Account, CaptionType, Job, Transcript, RevAiApiDeploymentConfigMap, RevAiApiDeployment from .models.asynchronous.summarization_options import SummarizationOptions from .models.asynchronous.summary import Summary from .models.asynchronous.translation_options import TranslationOptions + try: from urllib.parse import urljoin except ImportError: @@ -30,20 +31,25 @@ class RevAiAPIClient(BaseClient): # Default version of Rev AI version = 'v1' - # Default base url for Rev AI - base_url = 'https://api.rev.ai/speechtotext/{}/'.format(version) + # Default url for US Rev AI deployment + default_url = RevAiApiDeploymentConfigMap[RevAiApiDeployment.US]['base_url'] # Rev AI transcript format rev_json_content_type = 'application/vnd.rev.transcript.v1.0+json' - def __init__(self, access_token): + def __init__(self, access_token, url=None): """Constructor :param access_token: access token which authorizes all requests and links them to your account. Generated on the settings page of your account dashboard on Rev AI. + :param url: optional url of the Rev AI API deployment to use, defaults to the US + deployement, i.e. 'https://api.rev.ai', which can be referenced as + RevAiApiDeploymentConfigMap[RevAiApiDeployment.US]['base_url']. """ + # Default speech to text base url + self.base_url = '{0}/speechtotext/{1}/'.format(url if url else default_url, version) BaseClient.__init__(self, access_token) def submit_job_url( diff --git a/src/rev_ai/generic_api_client.py b/src/rev_ai/generic_api_client.py index e4db5996..0434c305 100644 --- a/src/rev_ai/generic_api_client.py +++ b/src/rev_ai/generic_api_client.py @@ -2,6 +2,8 @@ """Generic client used to interact with our newer style apis""" from .baseclient import BaseClient +from .models import RevAiApiDeploymentConfigMap, RevAiApiDeployment + try: from urllib.parse import urljoin @@ -13,7 +15,10 @@ class GenericApiClient(BaseClient): """Generic client which handles logic for making requests to almost any Rev AI Api. Intended to be inherited and extended by a specific client per API""" - def __init__(self, access_token, api_name, api_version, parse_job_info, parse_job_result): + # Default url for US Rev AI deployment + default_url = RevAiApiDeploymentConfigMap[RevAiApiDeployment.US]['base_url'] + + def __init__(self, access_token, api_name, api_version, parse_job_info, parse_job_result, url=None): """Constructor :param access_token: access token which authorizes all requests and links them to your @@ -23,10 +28,13 @@ def __init__(self, access_token, api_name, api_version, parse_job_info, parse_jo :param api_version: version of the api to submit to :param parse_job_info: method to be used to parse job information :param parse_job_result: method to be used to parse job results + :param url: optional url of the Rev AI API deployment to use, defaults to the US + deployement, i.e. 'https://api.rev.ai', which can be referenced as + RevAiApiDeploymentConfigMap[RevAiApiDeployment.US]['base_url']. """ BaseClient.__init__(self, access_token) - self.base_url = 'https://api.rev.ai/{0}/{1}/'.format(api_name, api_version) + self.base_url = '{0}/{1}/{2}/'.format(url if url else default_url, api_name, api_version) self.parse_job_info = parse_job_info self.parse_job_result = parse_job_result diff --git a/src/rev_ai/language_identification_client.py b/src/rev_ai/language_identification_client.py index 2968b5db..1e40ad9a 100644 --- a/src/rev_ai/language_identification_client.py +++ b/src/rev_ai/language_identification_client.py @@ -3,7 +3,7 @@ import json from .generic_api_client import GenericApiClient -from .models import LanguageIdentificationJob, LanguageIdentificationResult +from .models import LanguageIdentificationJob, LanguageIdentificationResult, RevAiApiDeploymentConfigMap, RevAiApiDeployment try: from urllib.parse import urljoin @@ -20,17 +20,20 @@ class LanguageIdentificationClient(GenericApiClient): # Default api name of Rev AI language identification api api_name = 'languageid' - def __init__(self, access_token): + def __init__(self, access_token, url=None): """Constructor :param access_token: access token which authorizes all requests and links them to your account. Generated on the settings page of your account dashboard on Rev AI. + :param url: optional url of the Rev AI API deployment to use, defaults to the US + deployement, i.e. 'https://api.rev.ai', which can be referenced as + RevAiApiDeploymentConfigMap[RevAiApiDeployment.US]['base_url']. """ GenericApiClient.__init__(self, access_token, self.api_name, self.api_version, LanguageIdentificationJob.from_json, - LanguageIdentificationResult.from_json) + LanguageIdentificationResult.from_json, url) def submit_job_url( self, diff --git a/src/rev_ai/models/__init__.py b/src/rev_ai/models/__init__.py index d6c0f07d..23398a11 100644 --- a/src/rev_ai/models/__init__.py +++ b/src/rev_ai/models/__init__.py @@ -9,3 +9,4 @@ SentimentAnalysisResult, SentimentValue, SentimentMessage, SentimentAnalysisJob from .language_id import LanguageIdentificationJob, LanguageIdentificationResult, LanguageConfidence from .customer_url_data import CustomerUrlData +from .revaiapi_deployment_config_constants import RevAiApiDeployment, RevAiApiDeploymentConfigMap diff --git a/src/rev_ai/models/revaiapi_deployment_config_constants.py b/src/rev_ai/models/revaiapi_deployment_config_constants.py new file mode 100644 index 00000000..8aa841d4 --- /dev/null +++ b/src/rev_ai/models/revaiapi_deployment_config_constants.py @@ -0,0 +1,10 @@ +from enum import Enum + +class RevAiApiDeployment(Enum): + US = 'US' + EU = 'EU' + +RevAiApiDeploymentConfigMap = { + RevAiApiDeployment.US: { 'base_url': 'https://api.rev.ai', 'base_websocket_url': 'wss://api.rev.ai' }, + RevAiApiDeployment.EU: { 'base_url': 'https://ec1.api.rev.ai', 'base_websocket_url': 'wss://ec1.api.rev.ai' } +}