Skip to content

Commit 1edae76

Browse files
authored
fix(TA): fix for tone when given model (#513)
1 parent 6f79c0f commit 1edae76

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

examples/tone_analyzer_v3.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
from os.path import join, dirname
44
from watson_developer_cloud import ToneAnalyzerV3
5+
from watson_developer_cloud.tone_analyzer_v3 import ToneInput
56

67
tone_analyzer = ToneAnalyzerV3(
78
username='YOUR SERVICE USERNAME',
@@ -55,3 +56,11 @@
5556
print(tone)
5657
print(tone.get_headers())
5758
print(tone.get_result())
59+
tone_analyzer.set_detailed_response(False)
60+
61+
print("\ntone() example 7:\n")
62+
tone_input = ToneInput('I am very happy. It is a good day.')
63+
tone = tone_analyzer.tone(
64+
tone_input=tone_input,
65+
content_type="application/json")
66+
print(json.dumps(tone, indent=2))

watson_developer_cloud/tone_analyzer_v3.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ def tone(self,
170170
raise ValueError('tone_input must be provided')
171171
if content_type is None:
172172
raise ValueError('content_type must be provided')
173+
if isinstance(tone_input, ToneInput):
174+
tone_input = self._convert_model(tone_input, ToneInput)
173175
headers = {
174176
'Content-Type': content_type,
175177
'Content-Language': content_language,

0 commit comments

Comments
 (0)