This repository has been archived by the owner on Jan 6, 2024. It is now read-only.
/
experiment.py
514 lines (442 loc) · 21 KB
/
experiment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
# -*- coding: utf-8 -*-
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import proto # type: ignore
from google.protobuf import duration_pb2 # type: ignore
from google.protobuf import field_mask_pb2 # type: ignore
from google.protobuf import timestamp_pb2 # type: ignore
__protobuf__ = proto.module(
package="google.cloud.dialogflow.cx.v3beta1",
manifest={
"Experiment",
"VersionVariants",
"RolloutConfig",
"RolloutState",
"VariantsHistory",
"ListExperimentsRequest",
"ListExperimentsResponse",
"GetExperimentRequest",
"CreateExperimentRequest",
"UpdateExperimentRequest",
"DeleteExperimentRequest",
"StartExperimentRequest",
"StopExperimentRequest",
},
)
class Experiment(proto.Message):
r"""Represents an experiment in an environment.
Attributes:
name (str):
The name of the experiment.
Format: projects/<Project
ID>/locations/<Location ID>/agents/<Agent
ID>/environments/<Environment
ID>/experiments/<Experiment ID>..
display_name (str):
Required. The human-readable name of the
experiment (unique in an environment). Limit of
64 characters.
description (str):
The human-readable description of the
experiment.
state (google.cloud.dialogflowcx_v3beta1.types.Experiment.State):
The current state of the experiment.
Transition triggered by
Experiments.StartExperiment: DRAFT->RUNNING.
Transition triggered by
Experiments.CancelExperiment: DRAFT->DONE or
RUNNING->DONE.
definition (google.cloud.dialogflowcx_v3beta1.types.Experiment.Definition):
The definition of the experiment.
rollout_config (google.cloud.dialogflowcx_v3beta1.types.RolloutConfig):
The configuration for auto rollout. If set,
there should be exactly two variants in the
experiment (control variant being the default
version of the flow), the traffic allocation for
the non-control variant will gradually increase
to 100% when conditions are met, and eventually
replace the control variant to become the
default version of the flow.
rollout_state (google.cloud.dialogflowcx_v3beta1.types.RolloutState):
State of the auto rollout process.
rollout_failure_reason (str):
The reason why rollout has failed. Should only be set when
state is ROLLOUT_FAILED.
result (google.cloud.dialogflowcx_v3beta1.types.Experiment.Result):
Inference result of the experiment.
create_time (google.protobuf.timestamp_pb2.Timestamp):
Creation time of this experiment.
start_time (google.protobuf.timestamp_pb2.Timestamp):
Start time of this experiment.
end_time (google.protobuf.timestamp_pb2.Timestamp):
End time of this experiment.
last_update_time (google.protobuf.timestamp_pb2.Timestamp):
Last update time of this experiment.
experiment_length (google.protobuf.duration_pb2.Duration):
Maximum number of days to run the experiment.
If auto-rollout is not enabled, default value
and maximum will be 30 days. If auto-rollout is
enabled, default value and maximum will be 6
days.
variants_history (Sequence[google.cloud.dialogflowcx_v3beta1.types.VariantsHistory]):
The history of updates to the experiment
variants.
"""
class State(proto.Enum):
r"""The state of the experiment."""
STATE_UNSPECIFIED = 0
DRAFT = 1
RUNNING = 2
DONE = 3
ROLLOUT_FAILED = 4
class Definition(proto.Message):
r"""Definition of the experiment.
Attributes:
condition (str):
The condition defines which subset of sessions are selected
for this experiment. If not specified, all sessions are
eligible. E.g. "query_input.language_code=en" See the
`conditions
reference <https://cloud.google.com/dialogflow/cx/docs/reference/condition>`__.
version_variants (google.cloud.dialogflowcx_v3beta1.types.VersionVariants):
The flow versions as the variants of this
experiment.
"""
condition = proto.Field(proto.STRING, number=1,)
version_variants = proto.Field(
proto.MESSAGE, number=2, oneof="variants", message="VersionVariants",
)
class Result(proto.Message):
r"""The inference result which includes an objective metric to
optimize and the confidence interval.
Attributes:
version_metrics (Sequence[google.cloud.dialogflowcx_v3beta1.types.Experiment.Result.VersionMetrics]):
Version variants and metrics.
last_update_time (google.protobuf.timestamp_pb2.Timestamp):
The last time the experiment's stats data was
updated. Will have default value if stats have
never been computed for this experiment.
"""
class MetricType(proto.Enum):
r"""Types of ratio-based metric for Dialogflow experiment."""
METRIC_UNSPECIFIED = 0
CONTAINED_SESSION_NO_CALLBACK_RATE = 1
LIVE_AGENT_HANDOFF_RATE = 2
CALLBACK_SESSION_RATE = 3
ABANDONED_SESSION_RATE = 4
SESSION_END_RATE = 5
class CountType(proto.Enum):
r"""types of count-based metric for Dialogflow experiment."""
COUNT_TYPE_UNSPECIFIED = 0
TOTAL_NO_MATCH_COUNT = 1
TOTAL_TURN_COUNT = 2
AVERAGE_TURN_COUNT = 3
class ConfidenceInterval(proto.Message):
r"""A confidence interval is a range of possible values for the
experiment objective you are trying to measure.
Attributes:
confidence_level (float):
The confidence level used to construct the
interval, i.e. there is X% chance that the true
value is within this interval.
ratio (float):
The percent change between an experiment
metric's value and the value for its control.
lower_bound (float):
Lower bound of the interval.
upper_bound (float):
Upper bound of the interval.
"""
confidence_level = proto.Field(proto.DOUBLE, number=1,)
ratio = proto.Field(proto.DOUBLE, number=2,)
lower_bound = proto.Field(proto.DOUBLE, number=3,)
upper_bound = proto.Field(proto.DOUBLE, number=4,)
class Metric(proto.Message):
r"""Metric and corresponding confidence intervals.
Attributes:
type_ (google.cloud.dialogflowcx_v3beta1.types.Experiment.Result.MetricType):
Ratio-based metric type. Only one of type or count_type is
specified in each Metric.
count_type (google.cloud.dialogflowcx_v3beta1.types.Experiment.Result.CountType):
Count-based metric type. Only one of type or count_type is
specified in each Metric.
ratio (float):
Ratio value of a metric.
count (float):
Count value of a metric.
confidence_interval (google.cloud.dialogflowcx_v3beta1.types.Experiment.Result.ConfidenceInterval):
The probability that the treatment is better
than all other treatments in the experiment
"""
type_ = proto.Field(
proto.ENUM, number=1, enum="Experiment.Result.MetricType",
)
count_type = proto.Field(
proto.ENUM, number=5, enum="Experiment.Result.CountType",
)
ratio = proto.Field(proto.DOUBLE, number=2, oneof="value",)
count = proto.Field(proto.DOUBLE, number=4, oneof="value",)
confidence_interval = proto.Field(
proto.MESSAGE, number=3, message="Experiment.Result.ConfidenceInterval",
)
class VersionMetrics(proto.Message):
r"""Version variant and associated metrics.
Attributes:
version (str):
The name of the flow
[Version][google.cloud.dialogflow.cx.v3beta1.Version].
Format:
``projects/<Project ID>/locations/<Location ID>/agents/<Agent ID>/flows/<Flow ID>/versions/<Version ID>``.
metrics (Sequence[google.cloud.dialogflowcx_v3beta1.types.Experiment.Result.Metric]):
The metrics and corresponding confidence
intervals in the inference result.
session_count (int):
Number of sessions that were allocated to
this version.
"""
version = proto.Field(proto.STRING, number=1,)
metrics = proto.RepeatedField(
proto.MESSAGE, number=2, message="Experiment.Result.Metric",
)
session_count = proto.Field(proto.INT32, number=3,)
version_metrics = proto.RepeatedField(
proto.MESSAGE, number=1, message="Experiment.Result.VersionMetrics",
)
last_update_time = proto.Field(
proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,
)
name = proto.Field(proto.STRING, number=1,)
display_name = proto.Field(proto.STRING, number=2,)
description = proto.Field(proto.STRING, number=3,)
state = proto.Field(proto.ENUM, number=4, enum=State,)
definition = proto.Field(proto.MESSAGE, number=5, message=Definition,)
rollout_config = proto.Field(proto.MESSAGE, number=14, message="RolloutConfig",)
rollout_state = proto.Field(proto.MESSAGE, number=15, message="RolloutState",)
rollout_failure_reason = proto.Field(proto.STRING, number=16,)
result = proto.Field(proto.MESSAGE, number=6, message=Result,)
create_time = proto.Field(proto.MESSAGE, number=7, message=timestamp_pb2.Timestamp,)
start_time = proto.Field(proto.MESSAGE, number=8, message=timestamp_pb2.Timestamp,)
end_time = proto.Field(proto.MESSAGE, number=9, message=timestamp_pb2.Timestamp,)
last_update_time = proto.Field(
proto.MESSAGE, number=10, message=timestamp_pb2.Timestamp,
)
experiment_length = proto.Field(
proto.MESSAGE, number=11, message=duration_pb2.Duration,
)
variants_history = proto.RepeatedField(
proto.MESSAGE, number=12, message="VariantsHistory",
)
class VersionVariants(proto.Message):
r"""A list of flow version variants.
Attributes:
variants (Sequence[google.cloud.dialogflowcx_v3beta1.types.VersionVariants.Variant]):
A list of flow version variants.
"""
class Variant(proto.Message):
r"""A single flow version with specified traffic allocation.
Attributes:
version (str):
The name of the flow version. Format:
``projects/<Project ID>/locations/<Location ID>/agents/<Agent ID>/flows/<Flow ID>/versions/<Version ID>``.
traffic_allocation (float):
Percentage of the traffic which should be
routed to this version of flow. Traffic
allocation for a single flow must sum up to 1.0.
is_control_group (bool):
Whether the variant is for the control group.
"""
version = proto.Field(proto.STRING, number=1,)
traffic_allocation = proto.Field(proto.FLOAT, number=2,)
is_control_group = proto.Field(proto.BOOL, number=3,)
variants = proto.RepeatedField(proto.MESSAGE, number=1, message=Variant,)
class RolloutConfig(proto.Message):
r"""The configuration for auto rollout.
Attributes:
rollout_steps (Sequence[google.cloud.dialogflowcx_v3beta1.types.RolloutConfig.RolloutStep]):
Steps to roll out a flow version. Steps
should be sorted by percentage in ascending
order.
rollout_condition (str):
The conditions that are used to evaluate the success of a
rollout step. If not specified, all rollout steps will
proceed to the next one unless failure conditions are met.
E.g. "containment_rate > 60% AND callback_rate < 20%". See
the `conditions
reference <https://cloud.google.com/dialogflow/cx/docs/reference/condition>`__.
failure_condition (str):
The conditions that are used to evaluate the failure of a
rollout step. If not specified, no rollout steps will fail.
E.g. "containment_rate < 10% OR average_turn_count < 3". See
the `conditions
reference <https://cloud.google.com/dialogflow/cx/docs/reference/condition>`__.
"""
class RolloutStep(proto.Message):
r"""A single rollout step with specified traffic allocation.
Attributes:
display_name (str):
The name of the rollout step;
traffic_percent (int):
The percentage of traffic allocated to the flow version of
this rollout step. (0%, 100%].
min_duration (google.protobuf.duration_pb2.Duration):
The minimum time that this step should last.
Should be longer than 1 hour. If not set, the
default minimum duration for each step will be 1
hour.
"""
display_name = proto.Field(proto.STRING, number=1,)
traffic_percent = proto.Field(proto.INT32, number=2,)
min_duration = proto.Field(
proto.MESSAGE, number=3, message=duration_pb2.Duration,
)
rollout_steps = proto.RepeatedField(proto.MESSAGE, number=1, message=RolloutStep,)
rollout_condition = proto.Field(proto.STRING, number=2,)
failure_condition = proto.Field(proto.STRING, number=3,)
class RolloutState(proto.Message):
r"""State of the auto-rollout process.
Attributes:
step (str):
Display name of the current auto rollout
step.
step_index (int):
Index of the current step in the auto rollout
steps list.
start_time (google.protobuf.timestamp_pb2.Timestamp):
Start time of the current step.
"""
step = proto.Field(proto.STRING, number=1,)
step_index = proto.Field(proto.INT32, number=3,)
start_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,)
class VariantsHistory(proto.Message):
r"""The history of variants update.
Attributes:
version_variants (google.cloud.dialogflowcx_v3beta1.types.VersionVariants):
The flow versions as the variants.
update_time (google.protobuf.timestamp_pb2.Timestamp):
Update time of the variants.
"""
version_variants = proto.Field(
proto.MESSAGE, number=1, oneof="variants", message="VersionVariants",
)
update_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,)
class ListExperimentsRequest(proto.Message):
r"""The request message for
[Experiments.ListExperiments][google.cloud.dialogflow.cx.v3beta1.Experiments.ListExperiments].
Attributes:
parent (str):
Required. The
[Environment][google.cloud.dialogflow.cx.v3beta1.Environment]
to list all environments for. Format:
``projects/<Project ID>/locations/<Location ID>/agents/<Agent ID>/environments/<Environment ID>``.
page_size (int):
The maximum number of items to return in a
single page. By default 20 and at most 100.
page_token (str):
The next_page_token value returned from a previous list
request.
"""
parent = proto.Field(proto.STRING, number=1,)
page_size = proto.Field(proto.INT32, number=2,)
page_token = proto.Field(proto.STRING, number=3,)
class ListExperimentsResponse(proto.Message):
r"""The response message for
[Experiments.ListExperiments][google.cloud.dialogflow.cx.v3beta1.Experiments.ListExperiments].
Attributes:
experiments (Sequence[google.cloud.dialogflowcx_v3beta1.types.Experiment]):
The list of experiments. There will be a maximum number of
items returned based on the page_size field in the request.
The list may in some cases be empty or contain fewer entries
than page_size even if this isn't the last page.
next_page_token (str):
Token to retrieve the next page of results,
or empty if there are no more results in the
list.
"""
@property
def raw_page(self):
return self
experiments = proto.RepeatedField(proto.MESSAGE, number=1, message="Experiment",)
next_page_token = proto.Field(proto.STRING, number=2,)
class GetExperimentRequest(proto.Message):
r"""The request message for
[Experiments.GetExperiment][google.cloud.dialogflow.cx.v3beta1.Experiments.GetExperiment].
Attributes:
name (str):
Required. The name of the
[Environment][google.cloud.dialogflow.cx.v3beta1.Environment].
Format:
``projects/<Project ID>/locations/<Location ID>/agents/<Agent ID>/environments/<Environment ID>/experiments/<Experiment ID>``.
"""
name = proto.Field(proto.STRING, number=1,)
class CreateExperimentRequest(proto.Message):
r"""The request message for
[Experiments.CreateExperiment][google.cloud.dialogflow.cx.v3beta1.Experiments.CreateExperiment].
Attributes:
parent (str):
Required. The
[Agent][google.cloud.dialogflow.cx.v3beta1.Agent] to create
an
[Environment][google.cloud.dialogflow.cx.v3beta1.Environment]
for. Format:
``projects/<Project ID>/locations/<Location ID>/agents/<Agent ID>/environments/<Environment ID>``.
experiment (google.cloud.dialogflowcx_v3beta1.types.Experiment):
Required. The experiment to create.
"""
parent = proto.Field(proto.STRING, number=1,)
experiment = proto.Field(proto.MESSAGE, number=2, message="Experiment",)
class UpdateExperimentRequest(proto.Message):
r"""The request message for
[Experiments.UpdateExperiment][google.cloud.dialogflow.cx.v3beta1.Experiments.UpdateExperiment].
Attributes:
experiment (google.cloud.dialogflowcx_v3beta1.types.Experiment):
Required. The experiment to update.
update_mask (google.protobuf.field_mask_pb2.FieldMask):
Required. The mask to control which fields
get updated.
"""
experiment = proto.Field(proto.MESSAGE, number=1, message="Experiment",)
update_mask = proto.Field(
proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask,
)
class DeleteExperimentRequest(proto.Message):
r"""The request message for
[Experiments.DeleteExperiment][google.cloud.dialogflow.cx.v3beta1.Experiments.DeleteExperiment].
Attributes:
name (str):
Required. The name of the
[Environment][google.cloud.dialogflow.cx.v3beta1.Environment]
to delete. Format:
``projects/<Project ID>/locations/<Location ID>/agents/<Agent ID>/environments/<Environment ID>/experiments/<Experiment ID>``.
"""
name = proto.Field(proto.STRING, number=1,)
class StartExperimentRequest(proto.Message):
r"""The request message for
[Experiments.StartExperiment][google.cloud.dialogflow.cx.v3beta1.Experiments.StartExperiment].
Attributes:
name (str):
Required. Resource name of the experiment to start. Format:
``projects/<Project ID>/locations/<Location ID>/agents/<Agent ID>/environments/<Environment ID>/experiments/<Experiment ID>``.
"""
name = proto.Field(proto.STRING, number=1,)
class StopExperimentRequest(proto.Message):
r"""The request message for
[Experiments.StopExperiment][google.cloud.dialogflow.cx.v3beta1.Experiments.StopExperiment].
Attributes:
name (str):
Required. Resource name of the experiment to stop. Format:
``projects/<Project ID>/locations/<Location ID>/agents/<Agent ID>/environments/<Environment ID>/experiments/<Experiment ID>``.
"""
name = proto.Field(proto.STRING, number=1,)
__all__ = tuple(sorted(__protobuf__.manifest))