Skip to content

Commit 9d9a85a

Browse files
committed
feat(assistantv2): DialogRuntimeResponseGeneric model has new params header and results
1 parent c2a4c35 commit 9d9a85a

File tree

1 file changed

+306
-5
lines changed

1 file changed

+306
-5
lines changed

ibm_watson/assistant_v2.py

Lines changed: 306 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,10 @@ class DialogRuntimeResponseGeneric(object):
722722
the possible matching dialog nodes from which the user can choose.
723723
**Note:** The **suggestions** property is part of the disambiguation feature, which is
724724
only available for Premium users.
725+
:attr str header: (optional) The title or introductory text to show before the
726+
response. This text is defined in the search skill configuration.
727+
:attr list[SearchResult] results: (optional) An array of objects containing search
728+
results.
725729
"""
726730

727731
def __init__(self,
@@ -736,7 +740,9 @@ def __init__(self,
736740
options=None,
737741
message_to_human_agent=None,
738742
topic=None,
739-
suggestions=None):
743+
suggestions=None,
744+
header=None,
745+
results=None):
740746
"""
741747
Initialize a DialogRuntimeResponseGeneric object.
742748
@@ -763,6 +769,10 @@ def __init__(self,
763769
describing the possible matching dialog nodes from which the user can choose.
764770
**Note:** The **suggestions** property is part of the disambiguation feature,
765771
which is only available for Premium users.
772+
:param str header: (optional) The title or introductory text to show before the
773+
response. This text is defined in the search skill configuration.
774+
:param list[SearchResult] results: (optional) An array of objects containing
775+
search results.
766776
"""
767777
self.response_type = response_type
768778
self.text = text
@@ -776,6 +786,8 @@ def __init__(self,
776786
self.message_to_human_agent = message_to_human_agent
777787
self.topic = topic
778788
self.suggestions = suggestions
789+
self.header = header
790+
self.results = results
779791

780792
@classmethod
781793
def _from_dict(cls, _dict):
@@ -784,7 +796,7 @@ def _from_dict(cls, _dict):
784796
validKeys = [
785797
'response_type', 'text', 'time', 'typing', 'source', 'title',
786798
'description', 'preference', 'options', 'message_to_human_agent',
787-
'topic', 'suggestions'
799+
'topic', 'suggestions', 'header', 'results'
788800
]
789801
badKeys = set(_dict.keys()) - set(validKeys)
790802
if badKeys:
@@ -825,6 +837,12 @@ def _from_dict(cls, _dict):
825837
DialogSuggestion._from_dict(x)
826838
for x in (_dict.get('suggestions'))
827839
]
840+
if 'header' in _dict:
841+
args['header'] = _dict.get('header')
842+
if 'results' in _dict:
843+
args['results'] = [
844+
SearchResult._from_dict(x) for x in (_dict.get('results'))
845+
]
828846
return cls(**args)
829847

830848
def _to_dict(self):
@@ -855,6 +873,10 @@ def _to_dict(self):
855873
_dict['topic'] = self.topic
856874
if hasattr(self, 'suggestions') and self.suggestions is not None:
857875
_dict['suggestions'] = [x._to_dict() for x in self.suggestions]
876+
if hasattr(self, 'header') and self.header is not None:
877+
_dict['header'] = self.header
878+
if hasattr(self, 'results') and self.results is not None:
879+
_dict['results'] = [x._to_dict() for x in self.results]
858880
return _dict
859881

860882
def __str__(self):
@@ -1811,14 +1833,14 @@ def __ne__(self, other):
18111833

18121834
class RuntimeEntity(object):
18131835
"""
1814-
A term from the request that was identified as an entity.
1836+
The entity value that was recognized in the user input.
18151837
18161838
:attr str entity: An entity detected in the input.
18171839
:attr list[int] location: An array of zero-based character offsets that indicate where
18181840
the detected entity values begin and end in the input text.
18191841
:attr str value: The term in the input text that was recognized as an entity value.
18201842
:attr float confidence: (optional) A decimal percentage that represents Watson's
1821-
confidence in the entity.
1843+
confidence in the recognized entity.
18221844
:attr dict metadata: (optional) Any metadata for the entity.
18231845
:attr list[CaptureGroup] groups: (optional) The recognized capture groups for the
18241846
entity, as defined by the entity pattern.
@@ -1840,7 +1862,7 @@ def __init__(self,
18401862
:param str value: The term in the input text that was recognized as an entity
18411863
value.
18421864
:param float confidence: (optional) A decimal percentage that represents Watson's
1843-
confidence in the entity.
1865+
confidence in the recognized entity.
18441866
:param dict metadata: (optional) Any metadata for the entity.
18451867
:param list[CaptureGroup] groups: (optional) The recognized capture groups for the
18461868
entity, as defined by the entity pattern.
@@ -1991,6 +2013,285 @@ def __ne__(self, other):
19912013
return not self == other
19922014

19932015

2016+
class SearchResult(object):
2017+
"""
2018+
SearchResult.
2019+
2020+
:attr str id: The unique identifier of the document in the Discovery service
2021+
collection.
2022+
This property is included in responses from search skills, which are a beta feature
2023+
available only to Plus or Premium plan users.
2024+
:attr SearchResultMetadata result_metadata: An object containing search result
2025+
metadata from the Discovery service.
2026+
:attr str body: (optional) A description of the search result. This is taken from an
2027+
abstract, summary, or highlight field in the Discovery service response, as specified
2028+
in the search skill configuration.
2029+
:attr str title: (optional) The title of the search result. This is taken from a title
2030+
or name field in the Discovery service response, as specified in the search skill
2031+
configuration.
2032+
:attr str url: (optional) The URL of the original data object in its native data
2033+
source.
2034+
:attr SearchResultHighlight highlight: (optional) An object containing segments of
2035+
text from search results with query-matching text highlighted using HTML <em> tags.
2036+
"""
2037+
2038+
def __init__(self,
2039+
id,
2040+
result_metadata,
2041+
body=None,
2042+
title=None,
2043+
url=None,
2044+
highlight=None):
2045+
"""
2046+
Initialize a SearchResult object.
2047+
2048+
:param str id: The unique identifier of the document in the Discovery service
2049+
collection.
2050+
This property is included in responses from search skills, which are a beta
2051+
feature available only to Plus or Premium plan users.
2052+
:param SearchResultMetadata result_metadata: An object containing search result
2053+
metadata from the Discovery service.
2054+
:param str body: (optional) A description of the search result. This is taken from
2055+
an abstract, summary, or highlight field in the Discovery service response, as
2056+
specified in the search skill configuration.
2057+
:param str title: (optional) The title of the search result. This is taken from a
2058+
title or name field in the Discovery service response, as specified in the search
2059+
skill configuration.
2060+
:param str url: (optional) The URL of the original data object in its native data
2061+
source.
2062+
:param SearchResultHighlight highlight: (optional) An object containing segments
2063+
of text from search results with query-matching text highlighted using HTML <em>
2064+
tags.
2065+
"""
2066+
self.id = id
2067+
self.result_metadata = result_metadata
2068+
self.body = body
2069+
self.title = title
2070+
self.url = url
2071+
self.highlight = highlight
2072+
2073+
@classmethod
2074+
def _from_dict(cls, _dict):
2075+
"""Initialize a SearchResult object from a json dictionary."""
2076+
args = {}
2077+
validKeys = [
2078+
'id', 'result_metadata', 'body', 'title', 'url', 'highlight'
2079+
]
2080+
badKeys = set(_dict.keys()) - set(validKeys)
2081+
if badKeys:
2082+
raise ValueError(
2083+
'Unrecognized keys detected in dictionary for class SearchResult: '
2084+
+ ', '.join(badKeys))
2085+
if 'id' in _dict:
2086+
args['id'] = _dict.get('id')
2087+
else:
2088+
raise ValueError(
2089+
'Required property \'id\' not present in SearchResult JSON')
2090+
if 'result_metadata' in _dict:
2091+
args['result_metadata'] = SearchResultMetadata._from_dict(
2092+
_dict.get('result_metadata'))
2093+
else:
2094+
raise ValueError(
2095+
'Required property \'result_metadata\' not present in SearchResult JSON'
2096+
)
2097+
if 'body' in _dict:
2098+
args['body'] = _dict.get('body')
2099+
if 'title' in _dict:
2100+
args['title'] = _dict.get('title')
2101+
if 'url' in _dict:
2102+
args['url'] = _dict.get('url')
2103+
if 'highlight' in _dict:
2104+
args['highlight'] = SearchResultHighlight._from_dict(
2105+
_dict.get('highlight'))
2106+
return cls(**args)
2107+
2108+
def _to_dict(self):
2109+
"""Return a json dictionary representing this model."""
2110+
_dict = {}
2111+
if hasattr(self, 'id') and self.id is not None:
2112+
_dict['id'] = self.id
2113+
if hasattr(self,
2114+
'result_metadata') and self.result_metadata is not None:
2115+
_dict['result_metadata'] = self.result_metadata._to_dict()
2116+
if hasattr(self, 'body') and self.body is not None:
2117+
_dict['body'] = self.body
2118+
if hasattr(self, 'title') and self.title is not None:
2119+
_dict['title'] = self.title
2120+
if hasattr(self, 'url') and self.url is not None:
2121+
_dict['url'] = self.url
2122+
if hasattr(self, 'highlight') and self.highlight is not None:
2123+
_dict['highlight'] = self.highlight._to_dict()
2124+
return _dict
2125+
2126+
def __str__(self):
2127+
"""Return a `str` version of this SearchResult object."""
2128+
return json.dumps(self._to_dict(), indent=2)
2129+
2130+
def __eq__(self, other):
2131+
"""Return `true` when self and other are equal, false otherwise."""
2132+
if not isinstance(other, self.__class__):
2133+
return False
2134+
return self.__dict__ == other.__dict__
2135+
2136+
def __ne__(self, other):
2137+
"""Return `true` when self and other are not equal, false otherwise."""
2138+
return not self == other
2139+
2140+
2141+
class SearchResultHighlight(object):
2142+
"""
2143+
An object containing segments of text from search results with query-matching text
2144+
highlighted using HTML <em> tags.
2145+
2146+
:attr list[str] body: (optional) An array of strings containing segments taken from
2147+
body text in the search results, with query-matching substrings highlighted.
2148+
:attr list[str] title: (optional) An array of strings containing segments taken from
2149+
title text in the search results, with query-matching substrings highlighted.
2150+
:attr list[str] url: (optional) An array of strings containing segments taken from
2151+
URLs in the search results, with query-matching substrings highlighted.
2152+
"""
2153+
2154+
def __init__(self, body=None, title=None, url=None, **kwargs):
2155+
"""
2156+
Initialize a SearchResultHighlight object.
2157+
2158+
:param list[str] body: (optional) An array of strings containing segments taken
2159+
from body text in the search results, with query-matching substrings highlighted.
2160+
:param list[str] title: (optional) An array of strings containing segments taken
2161+
from title text in the search results, with query-matching substrings highlighted.
2162+
:param list[str] url: (optional) An array of strings containing segments taken
2163+
from URLs in the search results, with query-matching substrings highlighted.
2164+
:param **kwargs: (optional) Any additional properties.
2165+
"""
2166+
self.body = body
2167+
self.title = title
2168+
self.url = url
2169+
for _key, _value in kwargs.items():
2170+
setattr(self, _key, _value)
2171+
2172+
@classmethod
2173+
def _from_dict(cls, _dict):
2174+
"""Initialize a SearchResultHighlight object from a json dictionary."""
2175+
args = {}
2176+
xtra = _dict.copy()
2177+
if 'body' in _dict:
2178+
args['body'] = _dict.get('body')
2179+
del xtra['body']
2180+
if 'title' in _dict:
2181+
args['title'] = _dict.get('title')
2182+
del xtra['title']
2183+
if 'url' in _dict:
2184+
args['url'] = _dict.get('url')
2185+
del xtra['url']
2186+
args.update(xtra)
2187+
return cls(**args)
2188+
2189+
def _to_dict(self):
2190+
"""Return a json dictionary representing this model."""
2191+
_dict = {}
2192+
if hasattr(self, 'body') and self.body is not None:
2193+
_dict['body'] = self.body
2194+
if hasattr(self, 'title') and self.title is not None:
2195+
_dict['title'] = self.title
2196+
if hasattr(self, 'url') and self.url is not None:
2197+
_dict['url'] = self.url
2198+
if hasattr(self, '_additionalProperties'):
2199+
for _key in self._additionalProperties:
2200+
_value = getattr(self, _key, None)
2201+
if _value is not None:
2202+
_dict[_key] = _value
2203+
return _dict
2204+
2205+
def __setattr__(self, name, value):
2206+
properties = {'body', 'title', 'url'}
2207+
if not hasattr(self, '_additionalProperties'):
2208+
super(SearchResultHighlight, self).__setattr__(
2209+
'_additionalProperties', set())
2210+
if name not in properties:
2211+
self._additionalProperties.add(name)
2212+
super(SearchResultHighlight, self).__setattr__(name, value)
2213+
2214+
def __str__(self):
2215+
"""Return a `str` version of this SearchResultHighlight object."""
2216+
return json.dumps(self._to_dict(), indent=2)
2217+
2218+
def __eq__(self, other):
2219+
"""Return `true` when self and other are equal, false otherwise."""
2220+
if not isinstance(other, self.__class__):
2221+
return False
2222+
return self.__dict__ == other.__dict__
2223+
2224+
def __ne__(self, other):
2225+
"""Return `true` when self and other are not equal, false otherwise."""
2226+
return not self == other
2227+
2228+
2229+
class SearchResultMetadata(object):
2230+
"""
2231+
An object containing search result metadata from the Discovery service.
2232+
2233+
:attr float confidence: (optional) The confidence score for the given result. For more
2234+
information about how the confidence is calculated, see the Discovery service
2235+
[documentation](../discovery#query-your-collection).
2236+
:attr float score: (optional) An unbounded measure of the relevance of a particular
2237+
result, dependent on the query and matching document. A higher score indicates a
2238+
greater match to the query parameters.
2239+
"""
2240+
2241+
def __init__(self, confidence=None, score=None):
2242+
"""
2243+
Initialize a SearchResultMetadata object.
2244+
2245+
:param float confidence: (optional) The confidence score for the given result. For
2246+
more information about how the confidence is calculated, see the Discovery service
2247+
[documentation](../discovery#query-your-collection).
2248+
:param float score: (optional) An unbounded measure of the relevance of a
2249+
particular result, dependent on the query and matching document. A higher score
2250+
indicates a greater match to the query parameters.
2251+
"""
2252+
self.confidence = confidence
2253+
self.score = score
2254+
2255+
@classmethod
2256+
def _from_dict(cls, _dict):
2257+
"""Initialize a SearchResultMetadata object from a json dictionary."""
2258+
args = {}
2259+
validKeys = ['confidence', 'score']
2260+
badKeys = set(_dict.keys()) - set(validKeys)
2261+
if badKeys:
2262+
raise ValueError(
2263+
'Unrecognized keys detected in dictionary for class SearchResultMetadata: '
2264+
+ ', '.join(badKeys))
2265+
if 'confidence' in _dict:
2266+
args['confidence'] = _dict.get('confidence')
2267+
if 'score' in _dict:
2268+
args['score'] = _dict.get('score')
2269+
return cls(**args)
2270+
2271+
def _to_dict(self):
2272+
"""Return a json dictionary representing this model."""
2273+
_dict = {}
2274+
if hasattr(self, 'confidence') and self.confidence is not None:
2275+
_dict['confidence'] = self.confidence
2276+
if hasattr(self, 'score') and self.score is not None:
2277+
_dict['score'] = self.score
2278+
return _dict
2279+
2280+
def __str__(self):
2281+
"""Return a `str` version of this SearchResultMetadata object."""
2282+
return json.dumps(self._to_dict(), indent=2)
2283+
2284+
def __eq__(self, other):
2285+
"""Return `true` when self and other are equal, false otherwise."""
2286+
if not isinstance(other, self.__class__):
2287+
return False
2288+
return self.__dict__ == other.__dict__
2289+
2290+
def __ne__(self, other):
2291+
"""Return `true` when self and other are not equal, false otherwise."""
2292+
return not self == other
2293+
2294+
19942295
class SessionResponse(object):
19952296
"""
19962297
SessionResponse.

0 commit comments

Comments
 (0)