Skip to content
This repository was archived by the owner on Oct 19, 2023. It is now read-only.

Commit 1e11f3a

Browse files
committed
google-assistant-sdk: add support for new conversation
- reset conversation on startup Bug: 69230966 Change-Id: I4005798dace021d51f9d78f5ad97f38a107f829c
1 parent fd3f3cb commit 1e11f3a

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

google-assistant-sdk/googlesamples/assistant/grpc/pushtotalk.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ def __init__(self, language_code, device_model_id, device_id,
8888
# This value, along with MicrophoneMode, supports a more natural
8989
# "conversation" with the Assistant.
9090
self.conversation_state = None
91+
# Force reset of first conversation.
92+
self.is_new_conversation = True
9193

9294
# Create Google Assistant API gRPC client.
9395
self.assistant = embedded_assistant_pb2_grpc.EmbeddedAssistantStub(
@@ -185,13 +187,6 @@ def iter_log_assist_requests():
185187
def gen_assist_requests(self):
186188
"""Yields: AssistRequest messages to send to the API."""
187189

188-
dialog_state_in = embedded_assistant_pb2.DialogStateIn(
189-
language_code=self.language_code,
190-
conversation_state=b''
191-
)
192-
if self.conversation_state:
193-
logging.debug('Sending conversation state.')
194-
dialog_state_in.conversation_state = self.conversation_state
195190
config = embedded_assistant_pb2.AssistConfig(
196191
audio_in_config=embedded_assistant_pb2.AudioInConfig(
197192
encoding='LINEAR16',
@@ -202,15 +197,20 @@ def gen_assist_requests(self):
202197
sample_rate_hertz=self.conversation_stream.sample_rate,
203198
volume_percentage=self.conversation_stream.volume_percentage,
204199
),
205-
dialog_state_in=dialog_state_in,
200+
dialog_state_in=embedded_assistant_pb2.DialogStateIn(
201+
language_code=self.language_code,
202+
conversation_state=self.conversation_state,
203+
is_new_conversation=self.is_new_conversation,
204+
),
206205
device_config=embedded_assistant_pb2.DeviceConfig(
207206
device_id=self.device_id,
208207
device_model_id=self.device_model_id,
209208
)
210209
)
211210
if self.display:
212211
config.screen_out_config.screen_mode = PLAYING
213-
212+
# Continue current conversation with later requests.
213+
self.is_new_conversation = False
214214
# The first AssistRequest must contain the AssistConfig
215215
# and no audio data.
216216
yield embedded_assistant_pb2.AssistRequest(config=config)

google-assistant-sdk/googlesamples/assistant/grpc/textinput.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def __init__(self, language_code, device_model_id, device_id,
6262
self.device_model_id = device_model_id
6363
self.device_id = device_id
6464
self.conversation_state = None
65+
# Force reset of first conversation.
66+
self.is_new_conversation = True
6567
self.display = display
6668
self.assistant = embedded_assistant_pb2_grpc.EmbeddedAssistantStub(
6769
channel
@@ -79,25 +81,25 @@ def assist(self, text_query):
7981
"""Send a text request to the Assistant and playback the response.
8082
"""
8183
def iter_assist_requests():
82-
dialog_state_in = embedded_assistant_pb2.DialogStateIn(
83-
language_code=self.language_code,
84-
conversation_state=b''
85-
)
86-
if self.conversation_state:
87-
dialog_state_in.conversation_state = self.conversation_state
8884
config = embedded_assistant_pb2.AssistConfig(
8985
audio_out_config=embedded_assistant_pb2.AudioOutConfig(
9086
encoding='LINEAR16',
9187
sample_rate_hertz=16000,
9288
volume_percentage=0,
9389
),
94-
dialog_state_in=dialog_state_in,
90+
dialog_state_in=embedded_assistant_pb2.DialogStateIn(
91+
language_code=self.language_code,
92+
conversation_state=self.conversation_state,
93+
is_new_conversation=self.is_new_conversation,
94+
),
9595
device_config=embedded_assistant_pb2.DeviceConfig(
9696
device_id=self.device_id,
9797
device_model_id=self.device_model_id,
9898
),
9999
text_query=text_query,
100100
)
101+
# Continue current conversation with later requests.
102+
self.is_new_conversation = False
101103
if self.display:
102104
config.screen_out_config.screen_mode = PLAYING
103105
req = embedded_assistant_pb2.AssistRequest(config=config)

0 commit comments

Comments
 (0)