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

Commit

Permalink
Integrate Python GAPIC Microgenerator in googleapis. This PR uses usi…
Browse files Browse the repository at this point in the history
…ng documentai as an example. Depends on googleapis/gapic-generator-python#402

PiperOrigin-RevId: 309824146

Source-Author: Google APIs <noreply@google.com>
Source-Date: Mon May 4 15:06:44 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: e0f9d9e1f9de890db765be46f45ca8490723e3eb
Source-Link: googleapis/googleapis@e0f9d9e
  • Loading branch information
yoshi-automation committed Aug 13, 2020
1 parent edfa928 commit 3ad188d
Show file tree
Hide file tree
Showing 99 changed files with 15,638 additions and 5,199 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Apache License
Apache License
Version 2.0, January 2004
https://www.apache.org/licenses/

Expand Down
7 changes: 7 additions & 0 deletions dialogflow_v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from dialogflow_v2.gapic import contexts_client
from dialogflow_v2.gapic import entity_types_client
from dialogflow_v2.gapic import enums
from dialogflow_v2.gapic import environments_client
from dialogflow_v2.gapic import intents_client
from dialogflow_v2.gapic import session_entity_types_client
from dialogflow_v2.gapic import sessions_client
Expand Down Expand Up @@ -53,6 +54,11 @@ class EntityTypesClient(entity_types_client.EntityTypesClient):
enums = enums


class EnvironmentsClient(environments_client.EnvironmentsClient):
__doc__ = environments_client.EnvironmentsClient.__doc__
enums = enums


class IntentsClient(intents_client.IntentsClient):
__doc__ = intents_client.IntentsClient.__doc__
enums = enums
Expand All @@ -74,6 +80,7 @@ class SessionsClient(sessions_client.SessionsClient):
"AgentsClient",
"ContextsClient",
"EntityTypesClient",
"EnvironmentsClient",
"IntentsClient",
"SessionEntityTypesClient",
"SessionsClient",
Expand Down
215 changes: 110 additions & 105 deletions dialogflow_v2/gapic/agents_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,76 +369,6 @@ def delete_agent(
request, retry=retry, timeout=timeout, metadata=metadata
)

def get_agent(
self,
parent,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Retrieves the specified agent.
Example:
>>> import dialogflow_v2
>>>
>>> client = dialogflow_v2.AgentsClient()
>>>
>>> parent = client.project_path('[PROJECT]')
>>>
>>> response = client.get_agent(parent)
Args:
parent (str): Required. The project that the agent to fetch is associated with.
Format: ``projects/<Project ID>``.
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will
be retried using a default configuration.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
that is provided to the method.
Returns:
A :class:`~google.cloud.dialogflow_v2.types.Agent` instance.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
"""
# Wrap the transport method to add retry and timeout logic.
if "get_agent" not in self._inner_api_calls:
self._inner_api_calls[
"get_agent"
] = google.api_core.gapic_v1.method.wrap_method(
self.transport.get_agent,
default_retry=self._method_configs["GetAgent"].retry,
default_timeout=self._method_configs["GetAgent"].timeout,
client_info=self._client_info,
)

request = agent_pb2.GetAgentRequest(parent=parent)
if metadata is None:
metadata = []
metadata = list(metadata)
try:
routing_header = [("parent", parent)]
except AttributeError:
pass
else:
routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata(
routing_header
)
metadata.append(routing_metadata)

return self._inner_api_calls["get_agent"](
request, retry=retry, timeout=timeout, metadata=metadata
)

def search_agents(
self,
parent,
Expand Down Expand Up @@ -637,7 +567,7 @@ def train_agent(
def export_agent(
self,
parent,
agent_uri=None,
agent_uri,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
Expand All @@ -654,7 +584,10 @@ def export_agent(
>>>
>>> parent = client.project_path('[PROJECT]')
>>>
>>> response = client.export_agent(parent)
>>> # TODO: Initialize `agent_uri`:
>>> agent_uri = ''
>>>
>>> response = client.export_agent(parent, agent_uri)
>>>
>>> def callback(operation_future):
... # Handle result.
Expand Down Expand Up @@ -727,7 +660,7 @@ def export_agent(
metadata_type=struct_pb2.Struct,
)

def import_agent(
def restore_agent(
self,
parent,
agent_uri=None,
Expand All @@ -737,11 +670,10 @@ def import_agent(
metadata=None,
):
"""
Imports the specified agent from a ZIP file.
Restores the specified agent from a ZIP file.
Uploads new intents and entity types without deleting the existing ones.
Intents and entity types with the same name are replaced with the new
versions from ImportAgentRequest.
Replaces the current agent version with a new one. All the intents and
entity types in the older version are deleted.
Operation <response: ``google.protobuf.Empty``>
Expand All @@ -752,7 +684,7 @@ def import_agent(
>>>
>>> parent = client.project_path('[PROJECT]')
>>>
>>> response = client.import_agent(parent)
>>> response = client.restore_agent(parent)
>>>
>>> def callback(operation_future):
... # Handle result.
Expand All @@ -764,9 +696,9 @@ def import_agent(
>>> metadata = response.metadata()
Args:
parent (str): Required. The project that the agent to import is associated with.
parent (str): Required. The project that the agent to restore is associated with.
Format: ``projects/<Project ID>``.
agent_uri (str): The URI to a Google Cloud Storage file containing the agent to import.
agent_uri (str): The URI to a Google Cloud Storage file containing the agent to restore.
Note: The URI must start with "gs://".
agent_content (bytes): Zip compressed raw byte content for agent.
retry (Optional[google.api_core.retry.Retry]): A retry object used
Expand All @@ -789,13 +721,13 @@ def import_agent(
ValueError: If the parameters are invalid.
"""
# Wrap the transport method to add retry and timeout logic.
if "import_agent" not in self._inner_api_calls:
if "restore_agent" not in self._inner_api_calls:
self._inner_api_calls[
"import_agent"
"restore_agent"
] = google.api_core.gapic_v1.method.wrap_method(
self.transport.import_agent,
default_retry=self._method_configs["ImportAgent"].retry,
default_timeout=self._method_configs["ImportAgent"].timeout,
self.transport.restore_agent,
default_retry=self._method_configs["RestoreAgent"].retry,
default_timeout=self._method_configs["RestoreAgent"].timeout,
client_info=self._client_info,
)

Expand All @@ -805,7 +737,7 @@ def import_agent(
agent_uri=agent_uri, agent_content=agent_content
)

request = agent_pb2.ImportAgentRequest(
request = agent_pb2.RestoreAgentRequest(
parent=parent, agent_uri=agent_uri, agent_content=agent_content
)
if metadata is None:
Expand All @@ -821,7 +753,7 @@ def import_agent(
)
metadata.append(routing_metadata)

operation = self._inner_api_calls["import_agent"](
operation = self._inner_api_calls["restore_agent"](
request, retry=retry, timeout=timeout, metadata=metadata
)
return google.api_core.operation.from_gapic(
Expand All @@ -831,7 +763,77 @@ def import_agent(
metadata_type=struct_pb2.Struct,
)

def restore_agent(
def get_agent(
self,
parent,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Retrieves the specified agent.
Example:
>>> import dialogflow_v2
>>>
>>> client = dialogflow_v2.AgentsClient()
>>>
>>> parent = client.project_path('[PROJECT]')
>>>
>>> response = client.get_agent(parent)
Args:
parent (str): Required. The project that the agent to fetch is associated with.
Format: ``projects/<Project ID>``.
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will
be retried using a default configuration.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
that is provided to the method.
Returns:
A :class:`~google.cloud.dialogflow_v2.types.Agent` instance.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
"""
# Wrap the transport method to add retry and timeout logic.
if "get_agent" not in self._inner_api_calls:
self._inner_api_calls[
"get_agent"
] = google.api_core.gapic_v1.method.wrap_method(
self.transport.get_agent,
default_retry=self._method_configs["GetAgent"].retry,
default_timeout=self._method_configs["GetAgent"].timeout,
client_info=self._client_info,
)

request = agent_pb2.GetAgentRequest(parent=parent)
if metadata is None:
metadata = []
metadata = list(metadata)
try:
routing_header = [("parent", parent)]
except AttributeError:
pass
else:
routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata(
routing_header
)
metadata.append(routing_metadata)

return self._inner_api_calls["get_agent"](
request, retry=retry, timeout=timeout, metadata=metadata
)

def import_agent(
self,
parent,
agent_uri=None,
Expand All @@ -841,10 +843,11 @@ def restore_agent(
metadata=None,
):
"""
Restores the specified agent from a ZIP file.
Imports the specified agent from a ZIP file.
Replaces the current agent version with a new one. All the intents and
entity types in the older version are deleted.
Uploads new intents and entity types without deleting the existing ones.
Intents and entity types with the same name are replaced with the new
versions from ImportAgentRequest.
Operation <response: ``google.protobuf.Empty``>
Expand All @@ -855,7 +858,7 @@ def restore_agent(
>>>
>>> parent = client.project_path('[PROJECT]')
>>>
>>> response = client.restore_agent(parent)
>>> response = client.import_agent(parent)
>>>
>>> def callback(operation_future):
... # Handle result.
Expand All @@ -867,9 +870,9 @@ def restore_agent(
>>> metadata = response.metadata()
Args:
parent (str): Required. The project that the agent to restore is associated with.
parent (str): Required. The project that the agent to import is associated with.
Format: ``projects/<Project ID>``.
agent_uri (str): The URI to a Google Cloud Storage file containing the agent to restore.
agent_uri (str): The URI to a Google Cloud Storage file containing the agent to import.
Note: The URI must start with "gs://".
agent_content (bytes): Zip compressed raw byte content for agent.
retry (Optional[google.api_core.retry.Retry]): A retry object used
Expand All @@ -892,13 +895,13 @@ def restore_agent(
ValueError: If the parameters are invalid.
"""
# Wrap the transport method to add retry and timeout logic.
if "restore_agent" not in self._inner_api_calls:
if "import_agent" not in self._inner_api_calls:
self._inner_api_calls[
"restore_agent"
"import_agent"
] = google.api_core.gapic_v1.method.wrap_method(
self.transport.restore_agent,
default_retry=self._method_configs["RestoreAgent"].retry,
default_timeout=self._method_configs["RestoreAgent"].timeout,
self.transport.import_agent,
default_retry=self._method_configs["ImportAgent"].retry,
default_timeout=self._method_configs["ImportAgent"].timeout,
client_info=self._client_info,
)

Expand All @@ -908,7 +911,7 @@ def restore_agent(
agent_uri=agent_uri, agent_content=agent_content
)

request = agent_pb2.RestoreAgentRequest(
request = agent_pb2.ImportAgentRequest(
parent=parent, agent_uri=agent_uri, agent_content=agent_content
)
if metadata is None:
Expand All @@ -924,7 +927,7 @@ def restore_agent(
)
metadata.append(routing_metadata)

operation = self._inner_api_calls["restore_agent"](
operation = self._inner_api_calls["import_agent"](
request, retry=retry, timeout=timeout, metadata=metadata
)
return google.api_core.operation.from_gapic(
Expand All @@ -936,7 +939,7 @@ def restore_agent(

def get_validation_result(
self,
parent=None,
parent,
language_code=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
Expand All @@ -951,13 +954,15 @@ def get_validation_result(
>>>
>>> client = dialogflow_v2.AgentsClient()
>>>
>>> response = client.get_validation_result()
>>> parent = client.project_path('[PROJECT]')
>>>
>>> response = client.get_validation_result(parent)
Args:
parent (str): Required. The project that the agent is associated with. Format:
``projects/<Project ID>``.
language_code (str): Optional. The language for which you want a validation result. If not
specified, the agent's default language is used. `Many
language_code (str): Optional. The language for which you want a validation result. If
not specified, the agent's default language is used. `Many
languages <https://cloud.google.com/dialogflow/docs/reference/language>`__
are supported. Note: languages must be enabled in the agent before they
can be used.
Expand Down
Loading

0 comments on commit 3ad188d

Please sign in to comment.