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

Commit f997336

Browse files
galz10parthea
andauthored
docs(samples): add set agent code sample (#370)
* Added Update Intent Snippet and Test * Deleted Setting Env Vars * Fixed Lint Issues * Fixed Lint and Build Issue * Fixed Build Issue * Changed tests to pytests * Removed delete and create agent from test * Fixed Import Order * Deleted unused import * Removed Language from update_intent Snippet * Added copyright * Changed intent name to random name * delete intent after testing * fix test * remove contains * Added Create Intent * fix lint * docs(samples): add set agent code sample * lint fix * Resolved comments * test and lint changes * Added Comments * lint fix Co-authored-by: Anthonios Partheniou <[email protected]>
1 parent 0855c80 commit f997336

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

samples/snippets/set_agent.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START dialogflow_set_agent_sample]
16+
17+
from google.cloud.dialogflow_v2 import Agent
18+
from google.cloud.dialogflow_v2 import AgentsClient
19+
20+
21+
def set_agent(project_id, display_name):
22+
23+
agents_client = AgentsClient()
24+
25+
parent = agents_client.common_project_path(project_id)
26+
27+
agent = Agent(
28+
parent=parent,
29+
display_name=display_name,
30+
default_language_code="en",
31+
time_zone="America/Los_Angeles",
32+
)
33+
34+
response = agents_client.set_agent(request={"agent": agent})
35+
36+
return response
37+
38+
39+
# [END dialogflow_set_agent_sample]

samples/snippets/set_agent_test.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import os
16+
17+
from google.api_core.exceptions import InvalidArgument
18+
19+
import pytest
20+
21+
from set_agent import set_agent
22+
23+
PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")
24+
25+
26+
# We cannot test setAgent because Dialogflow ES can only have one agent
27+
# and if we create a agent it will delete the exisitng testing agent and
28+
# would cause all tests to fail
29+
def test_set_agent():
30+
with pytest.raises(InvalidArgument):
31+
set_agent(PROJECT_ID, "")

0 commit comments

Comments
 (0)