Skip to content

Commit 67e27cd

Browse files
Merge branch 'master' into fix-add-custom-word-method
2 parents ba62ca2 + 3699298 commit 67e27cd

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

test/test_speech_to_text_v1.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ def _decode_body(body):
6565
@responses.activate
6666
def test_custom_model():
6767
customization_url = 'https://stream.watsonplatform.net/speech-to-text/api/v1/customizations'
68+
train_url = "{0}/{1}/train".format(customization_url,'customid')
69+
6870
responses.add(responses.GET, customization_url,
6971
body='{"get response": "yep"}', status=200,
7072
content_type='application/json')
@@ -81,6 +83,9 @@ def test_custom_model():
8183
body='{"bogus_response": "yep"}', status=200,
8284
content_type='application/json')
8385

86+
responses.add(responses.POST, train_url, body='{"bogus_response": "yep"}',
87+
status=200, content_type='application/json')
88+
8489
speech_to_text = watson_developer_cloud.SpeechToTextV1(
8590
username="username", password="password")
8691

@@ -99,10 +104,11 @@ def test_custom_model():
99104
assert parsed_body['description'] == ''
100105
assert parsed_body['base_model_name'] == 'en-US_BroadbandModel'
101106

107+
speech_to_text.train_custom_model('customid')
102108
speech_to_text.get_custom_model(modelid='modelid')
103109
speech_to_text.delete_custom_model(modelid='modelid')
104110

105-
assert len(responses.calls) == 5
111+
assert len(responses.calls) == 6
106112

107113

108114
def test_custom_corpora():

watson_developer_cloud/speech_to_text_v1.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,20 @@ def create_custom_model(self, name, description="",
8686
headers={'content-type': 'application/json'},
8787
data=json_body, accept_json=True)
8888

89+
def train_custom_model(self, customization_id,
90+
customization_weight=None,
91+
word_type=None):
92+
"""
93+
Trains a custom language model
94+
"""
95+
params = {'customization_weight': customization_weight,
96+
'word_type': word_type}
97+
98+
return self.request(method='POST',
99+
url=('/v1/customizations/{0}/train'
100+
.format(customization_id)), params=params,
101+
accept_json=True)
102+
89103
def list_custom_models(self):
90104
return self.request(method='GET', url='/v1/customizations',
91105
accept_json=True)

0 commit comments

Comments
 (0)