Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jennywong2129 committed Oct 24, 2024
1 parent d1ddb4a commit 241081c
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 12 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/rev_ai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 10 additions & 4 deletions src/rev_ai/apiclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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(
Expand Down
12 changes: 10 additions & 2 deletions src/rev_ai/generic_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down
9 changes: 6 additions & 3 deletions src/rev_ai/language_identification_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/rev_ai/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions src/rev_ai/models/revaiapi_deployment_config_constants.py
Original file line number Diff line number Diff line change
@@ -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' }
}

0 comments on commit 241081c

Please sign in to comment.