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

Commit 7bf5926

Browse files
feat: add environments client (#217)
1 parent edfa928 commit 7bf5926

File tree

134 files changed

+22294
-6766
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+22294
-6766
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Apache License
1+
Apache License
22
Version 2.0, January 2004
33
https://www.apache.org/licenses/
44

dialogflow_v2/__init__.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@
2424
from dialogflow_v2.gapic import contexts_client
2525
from dialogflow_v2.gapic import entity_types_client
2626
from dialogflow_v2.gapic import enums
27+
from dialogflow_v2.gapic import environments_client
2728
from dialogflow_v2.gapic import intents_client
2829
from dialogflow_v2.gapic import session_entity_types_client
2930
from dialogflow_v2.gapic import sessions_client
3031

3132

3233
if sys.version_info[:2] == (2, 7):
3334
message = (
34-
"A future version of this library will drop support for Python 2.7."
35-
"More details about Python 2 support for Google Cloud Client Libraries"
35+
"A future version of this library will drop support for Python 2.7. "
36+
"More details about Python 2 support for Google Cloud Client Libraries "
3637
"can be found at https://cloud.google.com/python/docs/python2-sunset/"
3738
)
3839
warnings.warn(message, DeprecationWarning)
@@ -53,6 +54,11 @@ class EntityTypesClient(entity_types_client.EntityTypesClient):
5354
enums = enums
5455

5556

57+
class EnvironmentsClient(environments_client.EnvironmentsClient):
58+
__doc__ = environments_client.EnvironmentsClient.__doc__
59+
enums = enums
60+
61+
5662
class IntentsClient(intents_client.IntentsClient):
5763
__doc__ = intents_client.IntentsClient.__doc__
5864
enums = enums
@@ -74,6 +80,7 @@ class SessionsClient(sessions_client.SessionsClient):
7480
"AgentsClient",
7581
"ContextsClient",
7682
"EntityTypesClient",
83+
"EnvironmentsClient",
7784
"IntentsClient",
7885
"SessionEntityTypesClient",
7986
"SessionsClient",

dialogflow_v2/gapic/agents_client.py

+78-86
Original file line numberDiff line numberDiff line change
@@ -50,32 +50,7 @@
5050

5151

5252
class AgentsClient(object):
53-
"""
54-
Agents are best described as Natural Language Understanding (NLU)
55-
modules that transform user requests into actionable data. You can
56-
include agents in your app, product, or service to determine user intent
57-
and respond to the user in a natural way.
58-
59-
After you create an agent, you can add ``Intents``, ``Contexts``,
60-
``Entity Types``, ``Webhooks``, and so on to manage the flow of a
61-
conversation and match user input to predefined intents and actions.
62-
63-
You can create an agent using both Dialogflow Standard Edition and
64-
Dialogflow Enterprise Edition. For details, see `Dialogflow
65-
Editions <https://cloud.google.com/dialogflow/docs/editions>`__.
66-
67-
You can save your agent for backup or versioning by exporting the agent
68-
by using the ``ExportAgent`` method. You can import a saved agent by
69-
using the ``ImportAgent`` method.
70-
71-
Dialogflow provides several `prebuilt
72-
agents <https://cloud.google.com/dialogflow/docs/agents-prebuilt>`__ for
73-
common conversation scenarios such as determining a date and time,
74-
converting currency, and so on.
75-
76-
For more information about agents, see the `Dialogflow
77-
documentation <https://cloud.google.com/dialogflow/docs/agents-overview>`__.
78-
"""
53+
"""Service for managing ``Agents``."""
7954

8055
SERVICE_ADDRESS = "dialogflow.googleapis.com:443"
8156
"""The default address of the service."""
@@ -224,36 +199,28 @@ def __init__(
224199
self._inner_api_calls = {}
225200

226201
# Service calls
227-
def set_agent(
202+
def get_agent(
228203
self,
229-
agent,
230-
update_mask=None,
204+
parent,
231205
retry=google.api_core.gapic_v1.method.DEFAULT,
232206
timeout=google.api_core.gapic_v1.method.DEFAULT,
233207
metadata=None,
234208
):
235209
"""
236-
Creates/updates the specified agent.
210+
Retrieves the specified agent.
237211
238212
Example:
239213
>>> import dialogflow_v2
240214
>>>
241215
>>> client = dialogflow_v2.AgentsClient()
242216
>>>
243-
>>> # TODO: Initialize `agent`:
244-
>>> agent = {}
217+
>>> parent = client.project_path('[PROJECT]')
245218
>>>
246-
>>> response = client.set_agent(agent)
219+
>>> response = client.get_agent(parent)
247220
248221
Args:
249-
agent (Union[dict, ~google.cloud.dialogflow_v2.types.Agent]): Required. The agent to update.
250-
251-
If a dict is provided, it must be of the same form as the protobuf
252-
message :class:`~google.cloud.dialogflow_v2.types.Agent`
253-
update_mask (Union[dict, ~google.cloud.dialogflow_v2.types.FieldMask]): Optional. The mask to control which fields get updated.
254-
255-
If a dict is provided, it must be of the same form as the protobuf
256-
message :class:`~google.cloud.dialogflow_v2.types.FieldMask`
222+
parent (str): Required. The project that the agent to fetch is associated with.
223+
Format: ``projects/<Project ID>``.
257224
retry (Optional[google.api_core.retry.Retry]): A retry object used
258225
to retry requests. If ``None`` is specified, requests will
259226
be retried using a default configuration.
@@ -274,22 +241,22 @@ def set_agent(
274241
ValueError: If the parameters are invalid.
275242
"""
276243
# Wrap the transport method to add retry and timeout logic.
277-
if "set_agent" not in self._inner_api_calls:
244+
if "get_agent" not in self._inner_api_calls:
278245
self._inner_api_calls[
279-
"set_agent"
246+
"get_agent"
280247
] = google.api_core.gapic_v1.method.wrap_method(
281-
self.transport.set_agent,
282-
default_retry=self._method_configs["SetAgent"].retry,
283-
default_timeout=self._method_configs["SetAgent"].timeout,
248+
self.transport.get_agent,
249+
default_retry=self._method_configs["GetAgent"].retry,
250+
default_timeout=self._method_configs["GetAgent"].timeout,
284251
client_info=self._client_info,
285252
)
286253

287-
request = agent_pb2.SetAgentRequest(agent=agent, update_mask=update_mask)
254+
request = agent_pb2.GetAgentRequest(parent=parent)
288255
if metadata is None:
289256
metadata = []
290257
metadata = list(metadata)
291258
try:
292-
routing_header = [("agent.parent", agent.parent)]
259+
routing_header = [("parent", parent)]
293260
except AttributeError:
294261
pass
295262
else:
@@ -298,32 +265,40 @@ def set_agent(
298265
)
299266
metadata.append(routing_metadata)
300267

301-
return self._inner_api_calls["set_agent"](
268+
return self._inner_api_calls["get_agent"](
302269
request, retry=retry, timeout=timeout, metadata=metadata
303270
)
304271

305-
def delete_agent(
272+
def set_agent(
306273
self,
307-
parent,
274+
agent,
275+
update_mask=None,
308276
retry=google.api_core.gapic_v1.method.DEFAULT,
309277
timeout=google.api_core.gapic_v1.method.DEFAULT,
310278
metadata=None,
311279
):
312280
"""
313-
Deletes the specified agent.
281+
Creates/updates the specified agent.
314282
315283
Example:
316284
>>> import dialogflow_v2
317285
>>>
318286
>>> client = dialogflow_v2.AgentsClient()
319287
>>>
320-
>>> parent = client.project_path('[PROJECT]')
288+
>>> # TODO: Initialize `agent`:
289+
>>> agent = {}
321290
>>>
322-
>>> client.delete_agent(parent)
291+
>>> response = client.set_agent(agent)
323292
324293
Args:
325-
parent (str): Required. The project that the agent to delete is associated with.
326-
Format: ``projects/<Project ID>``.
294+
agent (Union[dict, ~google.cloud.dialogflow_v2.types.Agent]): Required. The agent to update.
295+
296+
If a dict is provided, it must be of the same form as the protobuf
297+
message :class:`~google.cloud.dialogflow_v2.types.Agent`
298+
update_mask (Union[dict, ~google.cloud.dialogflow_v2.types.FieldMask]): Optional. The mask to control which fields get updated.
299+
300+
If a dict is provided, it must be of the same form as the protobuf
301+
message :class:`~google.cloud.dialogflow_v2.types.FieldMask`
327302
retry (Optional[google.api_core.retry.Retry]): A retry object used
328303
to retry requests. If ``None`` is specified, requests will
329304
be retried using a default configuration.
@@ -333,6 +308,9 @@ def delete_agent(
333308
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
334309
that is provided to the method.
335310
311+
Returns:
312+
A :class:`~google.cloud.dialogflow_v2.types.Agent` instance.
313+
336314
Raises:
337315
google.api_core.exceptions.GoogleAPICallError: If the request
338316
failed for any reason.
@@ -341,22 +319,22 @@ def delete_agent(
341319
ValueError: If the parameters are invalid.
342320
"""
343321
# Wrap the transport method to add retry and timeout logic.
344-
if "delete_agent" not in self._inner_api_calls:
322+
if "set_agent" not in self._inner_api_calls:
345323
self._inner_api_calls[
346-
"delete_agent"
324+
"set_agent"
347325
] = google.api_core.gapic_v1.method.wrap_method(
348-
self.transport.delete_agent,
349-
default_retry=self._method_configs["DeleteAgent"].retry,
350-
default_timeout=self._method_configs["DeleteAgent"].timeout,
326+
self.transport.set_agent,
327+
default_retry=self._method_configs["SetAgent"].retry,
328+
default_timeout=self._method_configs["SetAgent"].timeout,
351329
client_info=self._client_info,
352330
)
353331

354-
request = agent_pb2.DeleteAgentRequest(parent=parent)
332+
request = agent_pb2.SetAgentRequest(agent=agent, update_mask=update_mask)
355333
if metadata is None:
356334
metadata = []
357335
metadata = list(metadata)
358336
try:
359-
routing_header = [("parent", parent)]
337+
routing_header = [("agent.parent", agent.parent)]
360338
except AttributeError:
361339
pass
362340
else:
@@ -365,19 +343,19 @@ def delete_agent(
365343
)
366344
metadata.append(routing_metadata)
367345

368-
self._inner_api_calls["delete_agent"](
346+
return self._inner_api_calls["set_agent"](
369347
request, retry=retry, timeout=timeout, metadata=metadata
370348
)
371349

372-
def get_agent(
350+
def delete_agent(
373351
self,
374352
parent,
375353
retry=google.api_core.gapic_v1.method.DEFAULT,
376354
timeout=google.api_core.gapic_v1.method.DEFAULT,
377355
metadata=None,
378356
):
379357
"""
380-
Retrieves the specified agent.
358+
Deletes the specified agent.
381359
382360
Example:
383361
>>> import dialogflow_v2
@@ -386,10 +364,10 @@ def get_agent(
386364
>>>
387365
>>> parent = client.project_path('[PROJECT]')
388366
>>>
389-
>>> response = client.get_agent(parent)
367+
>>> client.delete_agent(parent)
390368
391369
Args:
392-
parent (str): Required. The project that the agent to fetch is associated with.
370+
parent (str): Required. The project that the agent to delete is associated with.
393371
Format: ``projects/<Project ID>``.
394372
retry (Optional[google.api_core.retry.Retry]): A retry object used
395373
to retry requests. If ``None`` is specified, requests will
@@ -400,9 +378,6 @@ def get_agent(
400378
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
401379
that is provided to the method.
402380
403-
Returns:
404-
A :class:`~google.cloud.dialogflow_v2.types.Agent` instance.
405-
406381
Raises:
407382
google.api_core.exceptions.GoogleAPICallError: If the request
408383
failed for any reason.
@@ -411,17 +386,17 @@ def get_agent(
411386
ValueError: If the parameters are invalid.
412387
"""
413388
# Wrap the transport method to add retry and timeout logic.
414-
if "get_agent" not in self._inner_api_calls:
389+
if "delete_agent" not in self._inner_api_calls:
415390
self._inner_api_calls[
416-
"get_agent"
391+
"delete_agent"
417392
] = google.api_core.gapic_v1.method.wrap_method(
418-
self.transport.get_agent,
419-
default_retry=self._method_configs["GetAgent"].retry,
420-
default_timeout=self._method_configs["GetAgent"].timeout,
393+
self.transport.delete_agent,
394+
default_retry=self._method_configs["DeleteAgent"].retry,
395+
default_timeout=self._method_configs["DeleteAgent"].timeout,
421396
client_info=self._client_info,
422397
)
423398

424-
request = agent_pb2.GetAgentRequest(parent=parent)
399+
request = agent_pb2.DeleteAgentRequest(parent=parent)
425400
if metadata is None:
426401
metadata = []
427402
metadata = list(metadata)
@@ -435,7 +410,7 @@ def get_agent(
435410
)
436411
metadata.append(routing_metadata)
437412

438-
return self._inner_api_calls["get_agent"](
413+
self._inner_api_calls["delete_agent"](
439414
request, retry=retry, timeout=timeout, metadata=metadata
440415
)
441416

@@ -654,7 +629,10 @@ def export_agent(
654629
>>>
655630
>>> parent = client.project_path('[PROJECT]')
656631
>>>
657-
>>> response = client.export_agent(parent)
632+
>>> # TODO: Initialize `agent_uri`:
633+
>>> agent_uri = ''
634+
>>>
635+
>>> response = client.export_agent(parent, agent_uri)
658636
>>>
659637
>>> def callback(operation_future):
660638
... # Handle result.
@@ -741,9 +719,15 @@ def import_agent(
741719
742720
Uploads new intents and entity types without deleting the existing ones.
743721
Intents and entity types with the same name are replaced with the new
744-
versions from ImportAgentRequest.
722+
versions from ``ImportAgentRequest``. After the import, the imported
723+
draft agent will be trained automatically (unless disabled in agent
724+
settings). However, once the import is done, training may not be
725+
completed yet. Please call ``TrainAgent`` and wait for the operation it
726+
returns in order to train explicitly.
745727
746-
Operation <response: ``google.protobuf.Empty``>
728+
Operation <response: ``google.protobuf.Empty``> An operation which
729+
tracks when importing is complete. It only tracks when the draft agent
730+
is updated not when it is done training.
747731
748732
Example:
749733
>>> import dialogflow_v2
@@ -844,9 +828,15 @@ def restore_agent(
844828
Restores the specified agent from a ZIP file.
845829
846830
Replaces the current agent version with a new one. All the intents and
847-
entity types in the older version are deleted.
831+
entity types in the older version are deleted. After the restore, the
832+
restored draft agent will be trained automatically (unless disabled in
833+
agent settings). However, once the restore is done, training may not be
834+
completed yet. Please call ``TrainAgent`` and wait for the operation it
835+
returns in order to train explicitly.
848836
849-
Operation <response: ``google.protobuf.Empty``>
837+
Operation <response: ``google.protobuf.Empty``> An operation which
838+
tracks when restoring is complete. It only tracks when the draft agent
839+
is updated not when it is done training.
850840
851841
Example:
852842
>>> import dialogflow_v2
@@ -951,13 +941,15 @@ def get_validation_result(
951941
>>>
952942
>>> client = dialogflow_v2.AgentsClient()
953943
>>>
954-
>>> response = client.get_validation_result()
944+
>>> parent = client.project_path('[PROJECT]')
945+
>>>
946+
>>> response = client.get_validation_result(parent)
955947
956948
Args:
957949
parent (str): Required. The project that the agent is associated with. Format:
958950
``projects/<Project ID>``.
959-
language_code (str): Optional. The language for which you want a validation result. If not
960-
specified, the agent's default language is used. `Many
951+
language_code (str): Optional. The language for which you want a validation result. If
952+
not specified, the agent's default language is used. `Many
961953
languages <https://cloud.google.com/dialogflow/docs/reference/language>`__
962954
are supported. Note: languages must be enabled in the agent before they
963955
can be used.

0 commit comments

Comments
 (0)