This repository has been archived by the owner on Sep 5, 2023. It is now read-only.
/
catalog.py
237 lines (204 loc) · 9.27 KB
/
catalog.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
# -*- 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.cloud.recommendationengine_v1beta1.types import common
__protobuf__ = proto.module(
package="google.cloud.recommendationengine.v1beta1",
manifest={"CatalogItem", "ProductCatalogItem", "Image",},
)
class CatalogItem(proto.Message):
r"""CatalogItem captures all metadata information of items to be
recommended.
Attributes:
id (str):
Required. Catalog item identifier. UTF-8
encoded string with a length limit of 128 bytes.
This id must be unique among all catalog items
within the same catalog. It should also be used
when logging user events in order for the user
events to be joined with the Catalog.
category_hierarchies (Sequence[google.cloud.recommendationengine_v1beta1.types.CatalogItem.CategoryHierarchy]):
Required. Catalog item categories. This field is repeated
for supporting one catalog item belonging to several
parallel category hierarchies.
For example, if a shoes product belongs to both ["Shoes &
Accessories" -> "Shoes"] and ["Sports & Fitness" ->
"Athletic Clothing" -> "Shoes"], it could be represented as:
::
"categoryHierarchies": [
{ "categories": ["Shoes & Accessories", "Shoes"]},
{ "categories": ["Sports & Fitness", "Athletic Clothing", "Shoes"] }
]
title (str):
Required. Catalog item title. UTF-8 encoded
string with a length limit of 1 KiB.
description (str):
Optional. Catalog item description. UTF-8
encoded string with a length limit of 5 KiB.
item_attributes (google.cloud.recommendationengine_v1beta1.types.FeatureMap):
Optional. Highly encouraged. Extra catalog
item attributes to be included in the
recommendation model. For example, for retail
products, this could include the store name,
vendor, style, color, etc. These are very strong
signals for recommendation model, thus we highly
recommend providing the item attributes here.
language_code (str):
Optional. Language of the title/description/item_attributes.
Use language tags defined by BCP 47.
https://www.rfc-editor.org/rfc/bcp/bcp47.txt. Our supported
language codes include 'en', 'es', 'fr', 'de', 'ar', 'fa',
'zh', 'ja', 'ko', 'sv', 'ro', 'nl'. For other languages,
contact your Google account manager.
tags (Sequence[str]):
Optional. Filtering tags associated with the
catalog item. Each tag should be a UTF-8 encoded
string with a length limit of 1 KiB.
This tag can be used for filtering
recommendation results by passing the tag as
part of the predict request filter.
item_group_id (str):
Optional. Variant group identifier for prediction results.
UTF-8 encoded string with a length limit of 128 bytes.
This field must be enabled before it can be used. `Learn
more </recommendations-ai/docs/catalog#item-group-id>`__.
product_metadata (google.cloud.recommendationengine_v1beta1.types.ProductCatalogItem):
Optional. Metadata specific to retail
products.
"""
class CategoryHierarchy(proto.Message):
r"""Category represents catalog item category hierarchy.
Attributes:
categories (Sequence[str]):
Required. Catalog item categories. Each
category should be a UTF-8 encoded string with a
length limit of 2 KiB.
Note that the order in the list denotes the
specificity (from least to most specific).
"""
categories = proto.RepeatedField(proto.STRING, number=1,)
id = proto.Field(proto.STRING, number=1,)
category_hierarchies = proto.RepeatedField(
proto.MESSAGE, number=2, message=CategoryHierarchy,
)
title = proto.Field(proto.STRING, number=3,)
description = proto.Field(proto.STRING, number=4,)
item_attributes = proto.Field(proto.MESSAGE, number=5, message=common.FeatureMap,)
language_code = proto.Field(proto.STRING, number=6,)
tags = proto.RepeatedField(proto.STRING, number=8,)
item_group_id = proto.Field(proto.STRING, number=9,)
product_metadata = proto.Field(
proto.MESSAGE,
number=10,
oneof="recommendation_type",
message="ProductCatalogItem",
)
class ProductCatalogItem(proto.Message):
r"""ProductCatalogItem captures item metadata specific to retail
products.
Attributes:
exact_price (google.cloud.recommendationengine_v1beta1.types.ProductCatalogItem.ExactPrice):
Optional. The exact product price.
price_range (google.cloud.recommendationengine_v1beta1.types.ProductCatalogItem.PriceRange):
Optional. The product price range.
costs (Sequence[google.cloud.recommendationengine_v1beta1.types.ProductCatalogItem.CostsEntry]):
Optional. A map to pass the costs associated with the
product.
For example: {"manufacturing": 45.5} The profit of selling
this item is computed like so:
- If 'exactPrice' is provided, profit = displayPrice -
sum(costs)
- If 'priceRange' is provided, profit = minPrice -
sum(costs)
currency_code (str):
Optional. Only required if the price is set.
Currency code for price/costs. Use three-
character ISO-4217 code.
stock_state (google.cloud.recommendationengine_v1beta1.types.ProductCatalogItem.StockState):
Optional. Online stock state of the catalog item. Default is
``IN_STOCK``.
available_quantity (int):
Optional. The available quantity of the item.
canonical_product_uri (str):
Optional. Canonical URL directly linking to
the item detail page with a length limit of 5
KiB..
images (Sequence[google.cloud.recommendationengine_v1beta1.types.Image]):
Optional. Product images for the catalog
item.
"""
class StockState(proto.Enum):
r"""Item stock state. If this field is unspecified, the item is
assumed to be in stock.
"""
_pb_options = {"allow_alias": True}
STOCK_STATE_UNSPECIFIED = 0
IN_STOCK = 0
OUT_OF_STOCK = 1
PREORDER = 2
BACKORDER = 3
class ExactPrice(proto.Message):
r"""Exact product price.
Attributes:
display_price (float):
Optional. Display price of the product.
original_price (float):
Optional. Price of the product without any
discount. If zero, by default set to be the
'displayPrice'.
"""
display_price = proto.Field(proto.FLOAT, number=1,)
original_price = proto.Field(proto.FLOAT, number=2,)
class PriceRange(proto.Message):
r"""Product price range when there are a range of prices for
different variations of the same product.
Attributes:
min_ (float):
Required. The minimum product price.
max_ (float):
Required. The maximum product price.
"""
min_ = proto.Field(proto.FLOAT, number=1,)
max_ = proto.Field(proto.FLOAT, number=2,)
exact_price = proto.Field(
proto.MESSAGE, number=1, oneof="price", message=ExactPrice,
)
price_range = proto.Field(
proto.MESSAGE, number=2, oneof="price", message=PriceRange,
)
costs = proto.MapField(proto.STRING, proto.FLOAT, number=3,)
currency_code = proto.Field(proto.STRING, number=4,)
stock_state = proto.Field(proto.ENUM, number=5, enum=StockState,)
available_quantity = proto.Field(proto.INT64, number=6,)
canonical_product_uri = proto.Field(proto.STRING, number=7,)
images = proto.RepeatedField(proto.MESSAGE, number=8, message="Image",)
class Image(proto.Message):
r"""Catalog item thumbnail/detail image.
Attributes:
uri (str):
Required. URL of the image with a length
limit of 5 KiB.
height (int):
Optional. Height of the image in number of
pixels.
width (int):
Optional. Width of the image in number of
pixels.
"""
uri = proto.Field(proto.STRING, number=1,)
height = proto.Field(proto.INT32, number=2,)
width = proto.Field(proto.INT32, number=3,)
__all__ = tuple(sorted(__protobuf__.manifest))