API Gợi ý văn bản tận dụng các công cụ AI tạo sinh của API Product Studio để tạo và tối ưu hoá tiêu đề và nội dung mô tả sản phẩm. Bạn có thể sử dụng tính năng này để cải thiện mức độ tương tác và lượt chuyển đổi của khách hàng.
Bạn có thể tạo nội dung gì bằng API này?
- Tiêu đề và nội dung mô tả sản phẩm được đề xuất dựa trên hình ảnh sản phẩm và/hoặc thuộc tính sản phẩm.
- Tiêu đề được tối ưu hoá cho công cụ tìm kiếm cho sản phẩm của bạn
- Tiêu đề được định dạng tuỳ chỉnh cho sản phẩm
- Nội dung mô tả sản phẩm trong nguồn cấp dữ liệu sản phẩm
Bạn cũng có thể chỉ định giọng điệu cho nội dung mô tả.
Bắt đầu nhanh
Phương thức GenerateProductTextSuggestions
có thể tạo hoặc tối ưu hoá tiêu đề và nội dung mô tả sản phẩm bằng cách sử dụng thông tin sản phẩm của bạn.
API chấp nhận:
- Thuộc tính sản phẩm (Từ điển JSON): Một đối tượng JSON chứa các thuộc tính sản phẩm (chẳng hạn như
{"title": "White Tee", "brand": "MyBrand", "size": "XL"}
) - Hình ảnh sản phẩm: URI trỏ đến hình ảnh sản phẩm (chẳng hạn như
{"uri": "https://my-store.com/img/1.png"}
) - Tuỳ chọn định dạng tiêu đề: Các thông số để tuỳ chỉnh việc tạo tiêu đề, bao gồm:
attribute_separator
: Chỉ định dấu phân cách giữa các thuộc tính.target_language
: Thiết lập ngôn ngữ đầu ra.attribute_order
: Xác định thứ tự của các thuộc tính trong tiêu đề được tạo.
- Ví dụ về việc gắn nhãn dữ liệu: Xem ví dụ về cách Tạo tiêu đề từ nội dung mô tả.
- Mã quy trình công việc (
output_spec.workflow_id
): Trườngworkflow_id
trong đối tượngoutput_spec
xác định loại văn bản được tạo:title
: Tạo hoặc tối ưu hoá tiêu đề sản phẩm.description
: Tạo hoặc tối ưu hoá nội dung mô tả sản phẩm.tide
: Tạo hoặc tối ưu hoá cả tiêu đề và nội dung mô tả sản phẩm.
Ví dụ
Sau đây là ví dụ về cách sử dụng API để tạo hoặc tối ưu hoá tiêu đề hoặc nội dung mô tả hoặc cả hai từ nhiều dữ liệu đầu vào về sản phẩm. Chúng tôi cũng trình bày Các lỗi và vấn đề thường gặp cũng như giải pháp khắc phục.
Tạo tiêu đề được tối ưu hoá
Ví dụ này cho thấy cách tạo tiêu đề tối ưu.
Yêu cầu
Nội dung yêu cầu chứa thông tin sản phẩm để sử dụng cho việc tối ưu hoá tiêu đề. Sau đây là ví dụ về cấu trúc yêu cầu:
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_attributes": {
"title": "Nike Mens shoes",
"description": "Give strength to your step with the Nike Air Zoom Pegasus 38 shoe for Men with shoe size 12. Ensuring the fit is loved by the runners. This shoes comes in Blue color.",
"brand": "Nike"
}
},
"output_spec": {
"workflow_id": "title"
}
}
Phản hồi
Bạn có thể nhận được câu trả lời như sau
{
"title": {
"text": "Nike Mens shoes Air Zoom Pegasus 38 Running Shoes, Blue, Size 12"
},
"metadata": {
"metadata": {
"attributes": {
"color": "Blue",
"size": "12",
"product": "Running shoes",
"model": "Air Zoom Pegasus 38"
},
}
}
}
Tạo tiêu đề chỉ từ một hình ảnh
Ví dụ này cho biết cách cung cấp hình ảnh sản phẩm và tạo tiêu đề tối ưu.
Yêu cầu
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_image":{
"uri": "https://cdn.shopify.com/s/files/1/0653/5879/0892/products/1672082339438_550x825.jpg?v=1672082415"
}
},
"output_spec": {
"workflow_id": "title",
"attribute_separator": "-"
}
}
Phản hồi
{
"title": {
"text": "Rustic Ceramic & Leather Leaves Necklace"
},
"metadata": {
"metadata": {
"attributes": {
"material": "Rustic Ceramic & Leather",
"pattern": "Leaves",
"product": "Necklace"
},
}
}
}
Tạo tiêu đề từ nội dung mô tả
Ví dụ này cho biết cách cung cấp nội dung mô tả sản phẩm và tạo tiêu đề tối ưu.
Yêu cầu
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_attributes": {
"description": "selling size 12 nike dunks. oh they are red by the way!"
}
},
"output_spec": {
"workflow_id": "title",
}
}
Phản hồi
{
"title": {
"text": "Nike Dunks Red Size 12"
},
"metadata": {
"metadata": {
"attributes": {
"brand": "Nike",
"color": "Red",
"size": "12",
"product": "Dunks"
},
}
}
}
Tối ưu hoá tiêu đề từ tiêu đề và nội dung mô tả (cùng với ví dụ tuỳ chỉnh)
Trong ví dụ này, chúng ta gắn nhãn rõ ràng các thuộc tính sản phẩm mà chúng ta muốn AI xác định và thứ tự thuộc tính trong kết quả.
Yêu cầu
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_attributes": {
"title": "Volumizing & Lengthening Mascara - Dark Brown",
"description": "This high-impact mascara delivers both voluptuous volume and dramatic length without clumping or smudging.",
"brand": "Luxe Beauty"
}
},
"output_spec": {
"workflow_id": "title"
}
"title_examples": [
{
"product_info": {
"title": "Lash Paradise Volumizing & Lengthening Mascara - Waterproof - Blackest Black",
"colour": "Black"
},
"title_format": "product",
"category": "mascara",
"final_product_info": {
"product": "Mascara",
"brand": "Lash Paradise",
"mascara_type": "Volumizing & Lengthening",
"colour": "Blackest Black",
"waterproof": "Waterproof",
}
},
{
"product_info": {
"title": "Hypnose Drama Instant Full Body Volume Mascara - Black",
"colour": "Black"
},
"title_format": "product",
"category": "mascara",
"final_product_info": {
"product": "Mascara",
"brand": "Hypnose",
"sub_brand": "Drama",
"mascara_type": "Full Body Volume",
"colour": "Black",
"eye_lash_type": "All lash types"
}
}
]
}
Phản hồi
{
"title": {
"text": "Luxe Beauty Dark Brown Volumizing & Lengthening Mascara"
},
"metadata": {
"metadata": {
"attributes": {
"brand": "Luxe Beauty",
"colour": "Dark Brown",
"mascara_type": "Volumizing & Lengthening",
"product": "Mascara"
},
}
}
}
Tạo nội dung mô tả từ tiêu đề
Ví dụ này cho thấy cách cung cấp tiêu đề sản phẩm và yêu cầu API tạo nội dung mô tả sản phẩm tương ứng.
Yêu cầu
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_attributes": {
"title": "Rustic Ceramic & Leather Leaves Necklace",
}
},
"output_spec": {
"workflow_id": "description"
}
}
Phản hồi
{
"description": {
"text": "Rustic Ceramic & Leather Leaves Necklace is a beautiful necklace made from high-quality ceramic and leather. It features a unique design that is sure to turn heads.
"
},
}
Tạo tiêu đề và nội dung mô tả từ các thuộc tính sản phẩm (như thương hiệu và màu sắc)
Ví dụ này minh hoạ cách cung cấp các thuộc tính sản phẩm để tạo tiêu đề và nội dung mô tả sản phẩm tối ưu.
Yêu cầu
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_attributes": {
"brand": "Mr. Beast",
"color": "purple",
},
"product_image":{
"uri": "https://mrbeast.store/cdn/shop/files/0015dlv_0000_327.jpg?v=1702754475&width=500"
}
},
"output_spec": {
"workflow_id": "description"
}
}
Phản hồi
{
"title": {
"text": "Pajamas - Mr. Beast | Purple"
},
"description": {
"text": "Slip into the ultimate comfort and style with these Mr. Beast pajamas in a vibrant shade of purple. Crafted from the softest materials, these pajamas will envelop you in a cozy embrace, ensuring a restful night's sleep. The shorts feature a relaxed fit, allowing for easy movement, while the top boasts a classic design with a comfortable neckline. Whether you're lounging at home or drifting off to dreamland, these Mr. Beast pajamas are the perfect choice for a peaceful and stylish slumber."
},
}
Hỗ trợ ngôn ngữ đích
Trường này chỉ định ngôn ngữ của văn bản mô tả được tạo trong phản hồi API. Bạn có thể thêm target_language
vào tham số output_spec
:
{
"output_spec": {
"target_language": "language"
}
}
Giá trị mẫu:
"korean" (Korean)
"english" (English)
"spanish" (Spanish)
"french" (French)
Yêu cầu mẫu
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_attributes": {
"title": "Granos de café negro",
"description": "Los granos de café negro en California",
"brand": "Parfums de Paris",
"scent": "Floral",
},
"product_image":{
"uri": "https://mrbeast.store/cdn/shop/files/0015dlv_0000_327.jpg?v=1702754475&width=500"
}
},
"output_spec": {
"workflow_id": "description",
"target_language": "japanese",
"attribute_order": ["scent", "product"],
"tone": "playful",
}
}
Phản hồi
{
"description": {
"text": "カリフォルニアの黒いコーヒー豆は、あなたの鼻をくすぐる、甘く、フローラルな香りです。この香りは、コーヒー豆の豊かな香りと、ジャスミンとバラの繊細な花の香りをブレンドしたものです。カリフォルニアの黒いコーヒー豆は、あなたの家を居心地の良いカフェに変え、あなたをリラックスした気分にさせてくれるでしょう。この香りは、コーヒー好きにも、フローラルな香り好きにも最適です。カリフォルニアの黒いコーヒー豆で、あなたの家を幸せな香りで満たしましょう!."
},
}
Cá nhân hoá giọng nói để tạo nội dung mô tả
Để giúp xây dựng thương hiệu và tạo sự khác biệt cho cửa hàng trực tuyến của mình so với các cửa hàng khác, bạn có thể cá nhân hoá tông giọng của nội dung mô tả được tạo. API Text (Văn bản) cung cấp hai tuỳ chọn:
- Chọn âm sắc được xác định trước: Bạn có thể chọn trong danh sách âm sắc để tạo nội dung mô tả mới. Danh sách này bao gồm các kiểu âm sắc sau:
- Mặc định: Đơn giản, rõ ràng và thanh lịch.
- Tính vui nhộn: Tươi vui, sử dụng ngôn từ tích cực, hài hước (trò đùa, từ đồng âm), và phóng đại (không có lời châm biếm, mỉa mai hoặc biểu tượng cảm xúc).
- Trang trọng: Tiếng Anh chuẩn, ngữ pháp chính xác, câu hoàn chỉnh, không sử dụng từ lóng hoặc từ viết tắt.
- Nội dung thuyết phục: Logic, súc tích và dựa trên lập luận để thuyết phục người đọc.
- Tự nhiên: Ngôn từ thân thiện, dễ hiểu, dùng trong cuộc sống hằng ngày.
- Giọng điệu dành riêng cho thương hiệu: Bạn có thể cung cấp nội dung mô tả hiện có hoặc các thành phần văn bản khác theo giọng điệu của thương hiệu. Mô hình AI tạo sinh sẽ phân tích giọng điệu của văn bản và tạo "tính năng mô tả kiểu viết" theo các khía cạnh sau:
- Mức độ trang trọng (chẳng hạn như trang trọng, thân thiện)
- Độ chi tiết (chẳng hạn như ngắn gọn, rất chi tiết)
- Văn phong (chẳng hạn như chuyên nghiệp, giàu thông tin, tích cực, thuyết phục)
- Cấu trúc câu (chẳng hạn như "câu đơn giản với ít từ nối")
- Những từ và cụm từ được sử dụng thường xuyên nhất
Thư viện ứng dụng
Bạn nên sử dụng thư viện ứng dụng để gửi yêu cầu. Chúng tôi sẽ chia sẻ với bạn các thư viện ứng dụng mà bạn có thể cài đặt trong dự án Maven.
Mã mẫu
Chọn phương thức xác thực và thiết lập các mã mẫu này bằng hướng dẫn sau. Dưới đây là một mẫu bạn có thể sử dụng để tạo nội dung đề xuất văn bản.
Java
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.productstudio.v1alpha.GenerateProductTextSuggestionsRequest;
import com.google.shopping.merchant.productstudio.v1alpha.GenerateProductTextSuggestionsResponse;
import com.google.shopping.merchant.productstudio.v1alpha.OutputSpec;
import com.google.shopping.merchant.productstudio.v1alpha.ProductInfo;
import com.google.shopping.merchant.productstudio.v1alpha.TextSuggestionsServiceClient;
import com.google.shopping.merchant.productstudio.v1alpha.TextSuggestionsServiceSettings;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to generate product text suggestions. */
public class GenerateProductTextSuggestionsSample {
private static String getName(String accountId) {
return String.format("accounts/%s", accountId);
}
public static void generateProductTextSuggestions(Config config) throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
TextSuggestionsServiceSettings textSuggestionsServiceSettings =
TextSuggestionsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
String name = getName(config.getAccountId().toString());
// Calls the API and catches and prints any network failures/errors.
try (TextSuggestionsServiceClient textSuggestionsServiceClient =
TextSuggestionsServiceClient.create(textSuggestionsServiceSettings)) {
ProductInfo productInfo =
ProductInfo.newBuilder()
.putProductAttributes("title", "Mens shirt")
.putProductAttributes("description", "A blue shirt for men in size S")
.build();
OutputSpec outputSpec = OutputSpec.newBuilder().setWorkflowId("title").build();
GenerateProductTextSuggestionsRequest request =
GenerateProductTextSuggestionsRequest.newBuilder()
.setName(name)
.setProductInfo(productInfo)
.setOutputSpec(outputSpec)
.build();
System.out.println("Sending GenerateProductTextSuggestions request: " + name);
GenerateProductTextSuggestionsResponse response =
textSuggestionsServiceClient.generateProductTextSuggestions(request);
System.out.println("Generated product text suggestions response below:");
System.out.println(response);
} catch (Exception e) {
System.out.println("An error has occured: ");
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
generateProductTextSuggestions(config);
}
}
Các lỗi và vấn đề thường gặp
Sau đây là một số lỗi thường gặp và giải pháp khắc phục.
Bạn phải có thông tin sản phẩm để tạo nội dung đề xuất dạng văn bản
Nếu bạn nhận được thông báo lỗi sau
Error message:
"error": {
"code": 400,
"message": "[product_info] Product info is required to generate text suggestions.",
"status": "INVALID_ARGUMENT",
...
}
thêm product_info
vào phần nội dung yêu cầu và điền chính xác ít nhất một trong các giá trị product_attributes
hoặc product_image
.
Ví dụ: việc đăng nội dung này sẽ dẫn đến lỗi.
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"output_spec": {
"workflow_id": "title"
}
}
Bạn phải có ít nhất một trường product_info để tạo nội dung gợi ý
Lỗi này
{
"error": {
"code": 400,
"message": "[product_info.product_attributes] At least one field of product_info is required to generate text suggestions.",
"status": "INVALID_ARGUMENT",
...
}
là dấu hiệu cho thấy bạn cần thêm ít nhất một trường product_info
vào phần nội dung yêu cầu.
Ví dụ: việc đăng nội dung này sẽ gây ra lỗi.
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
},
"output_spec": {
"workflow_id": "title"
}
}
Thay vào đó, hãy sử dụng một đoạn mã như
"product_info": {
"product_attributes": {
"description": "Selling size 12 Nike dunks. Oh they are red by the way!"
}
}
hoặc
"product_info": {
"product_image":{
"uri": "https://cdn.shopify.com/s/files/1/0653/5879/0892/products/1672082339438_550x825.jpg?v=1672082415"
}
}
(Something) là phần bắt buộc trong mỗi title_example
Các lỗi như 4 ví dụ sau
{
"error": {
"code": 400,
"message": "[title_examples.product_info] At least one field of product_info is required in each title_example.",
"status": "INVALID_ARGUMENT",
...
}
hoặc
{
...
"message": "[title_examples.category] Category is required in each title_example.",
...
}
hoặc
{
...
"message": "[title_examples.title_format] Title format is required in each title_example.",
...
}
hoặc
{
...
"message": "[title_examples.final_product_info] At least one field of final_product_info is required in each title_example.",
...
}
cho biết bạn chưa điền vào một trường phụ bắt buộc.
Ví dụ: yêu cầu sau đây sẽ tạo ra lỗi.
POST
https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_attributes": {
"description": "selling size 12 nike dunks. oh they are red by the way!"
}
},
"output_spec": {
"workflow_id": "title"
},
"title_examples": []
}
Để giải quyết vấn đề này, đối với mỗi title_example được chỉ định trong yêu cầu, hãy điền tất cả các trường phụ sau:
product_info
category
title_format
final_product_info
Sau đây là ví dụ hoạt động:
{
"product_info": {
"product_attributes": {
"title": "Volumizing & Lengthening Mascara - Dark Brown",
"description": "This high-impact mascara delivers both voluptuous volume and dramatic length without clumping or smudging.",
}
},
"output_spec": {
"workflow_id": "title"
},
"title_examples": [
{
"product_info": {
"title": "Lash Paradise Volumizing & Lengthening Mascara - Waterproof - Blackest Black",
"colour": "Black"
},
"title_format": "product",
"category": "mascara",
"final_product_info": {
"product": "Mascara",
"brand": "Lash Paradise",
"mascara_type": "Volumizing & Lengthening",
"colour": "Blackest Black",
"waterproof": "Waterproof",
}
}
]
}
workflow_id không được hỗ trợ
Loại lỗi này
{
"error": {
"code": 400,
"message": "[\u003ceye3 title='/ProductStudioTextGenerationService.GenerateProductText, INVALID_ARGUMENT'/\u003e APPLICATION_ERROR; ... ;Unsupported workflow_id: attributes. Supported workflows are: [\"title\", \"description\", \"tide\"];AppErrorCode=3;StartTimeMs=1740696804045;unknown;ResFormat=uncompressed;ServerTimeSec=0.005976589;LogBytes=256;Non-FailFast;EffSecLevel=none;ReqFormat=uncompressed;ReqID=4d1786f59faa3ea7;GlobalID=0;Server=[2002:a05:6e16:618:b0:2c2:7cfc:bebd]:14001] Invalid value",
"status": "INVALID_ARGUMENT",
...
}
sẽ là kết quả của một yêu cầu như
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_attributes": {
"title": "Volumizing & Lengthening Mascara - Dark Brown",
"description": "This high-impact mascara delivers both voluptuous volume and dramatic length without clumping or smudging.",
},
"output_spec": {
"workflow_id": "attributes"
}
}
Yêu cầu đặt workflow_id
thành "thuộc tính", nhưng trường này chỉ hỗ trợ một trong các giá trị sau:
- title: Tạo hoặc tối ưu hoá tiêu đề sản phẩm.
- description: Tạo hoặc tối ưu hoá nội dung mô tả sản phẩm.
- tide: Tạo hoặc tối ưu hoá cả tiêu đề và nội dung mô tả sản phẩm.
Tông màu không được hỗ trợ
Lỗi "Tone không được hỗ trợ", chẳng hạn như
{
"error": {
"code": 400,
"message": "[\u003ceye3 title='/ProductStudioTextGenerationService.GenerateProductText, INVALID_ARGUMENT'/\u003e APPLICATION_ERROR; ... ; Unsupported tone: 'asdf'. Supported tones are: [\"default\", \"playful\", \"formal\", \"persuasive\", \"conversational\"];AppErrorCode=3;StartTimeMs=1740697325058;unknown;ResFormat=uncompressed;ServerTimeSec=7.45346E-4;LogBytes=256;Non-FailFast;EffSecLevel=none;ReqFormat=uncompressed;ReqID=f7d9bbbc73a1d342;GlobalID=0;Server=[2002:a05:6918:3486:b0:2bc:ccd4:79e6]:14001] Invalid value",
"status": "INVALID_ARGUMENT",
...
}
sẽ là kết quả của một yêu cầu như
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_attributes": {
"title": "Volumizing & Lengthening Mascara - Dark Brown",
"description": "This high-impact mascara delivers both voluptuous volume and dramatic length without clumping or smudging.",
},
"output_spec": {
"workflow_id": "description"
"tone": "cheerful"
}
}
Lưu ý rằng tone
đang được đặt thành "vui vẻ", nhưng trường này chỉ hỗ trợ một trong các giá trị sau:
- mặc định: Đơn giản, rõ ràng và thanh lịch.
- vui nhộn: Tươi vui, sử dụng ngôn từ tích cực, hài hước (trò đùa, từ đồng âm) và phóng đại (không có lời châm biếm, mỉa mai hoặc biểu tượng cảm xúc).
- chính thức: Tiếng Anh chuẩn, ngữ pháp chính xác, câu hoàn chỉnh, không sử dụng tiếng lóng hoặc từ viết tắt.
- có sức thuyết phục: Logic, súc tích và dựa trên lập luận để thuyết phục người đọc.
- giao tiếp: Ngôn từ thân thiện, dễ hiểu, dùng trong cuộc sống hằng ngày.