Text Suggestions API memanfaatkan alat AI generatif Product Studio API untuk membuat dan mengoptimalkan judul dan deskripsi produk. Anda dapat menggunakannya untuk meningkatkan interaksi dan konversi pelanggan, serta menyederhanakan proses pengelolaan dan pembaruan informasi produk. Fitur Product Studio API dapat membantu Anda mengoptimalkan performa retail.
Apa yang dapat Anda buat menggunakan API?
Text Suggestions API membantu Anda melakukan hal berikut:
- Saran judul dan deskripsi produk berdasarkan gambar produk dan/atau atribut produk Anda.
- Judul yang dioptimalkan untuk SEO produk Anda
- Judul yang diformat khusus untuk produk Anda
- Deskripsi produk dari feed produk Anda
Anda juga dapat menentukan gaya bahasa untuk deskripsi dan menjaga konsistensi di semua listingan produk Anda.
Panduan memulai
Metode GenerateProductTextSuggestions
dapat membuat atau mengoptimalkan judul dan deskripsi produk menggunakan
informasi produk Anda.
API menerima:
- Atribut Produk (Kamus JSON): Objek JSON yang berisi atribut produk (seperti,
{"title": "White Tee", "brand": "MyBrand", "size": "XL"}
) - Gambar Produk: URI yang mengarah ke gambar produk (seperti,
{"uri": "https://my-store.com/img/1.png"}
) - Opsi Pemformatan Judul: Parameter untuk menyesuaikan pembuatan judul, termasuk:
attribute_separator
: Menentukan pemisah antar-atribut.target_language
: Menetapkan bahasa output.attribute_order
: Menentukan urutan atribut dalam judul yang dibuat.
- Contoh pelabelan data: Lihat contoh cara Membuat judul dari deskripsi.
- ID Alur Kerja (
output_spec.workflow_id
): Kolomworkflow_id
dalam objekoutput_spec
menentukan jenis pembuatan teks:title
: Membuat atau mengoptimalkan judul produk.description
: Membuat atau mengoptimalkan deskripsi produk.tide
: Membuat atau mengoptimalkan judul dan deskripsi produk.
Contoh
Berikut adalah contoh penggunaan API untuk membuat atau mengoptimalkan judul atau deskripsi atau keduanya dari berbagai input data produk. Kami juga menyajikan Kesalahan dan masalah umum serta solusinya.
Pembuatan judul yang dioptimalkan
Contoh ini menunjukkan cara membuat judul yang optimal.
Permintaan
Isi permintaan berisi informasi produk yang akan digunakan untuk pengoptimalan judul. Berikut adalah contoh struktur permintaan:
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"
}
}
Respons
Anda akan menerima respons seperti
{
"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"
},
}
}
}
Membuat judul hanya dari gambar
Contoh ini menunjukkan cara memberikan gambar produk dan membuat judul yang optimal.
Permintaan
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": "-"
}
}
Respons
{
"title": {
"text": "Rustic Ceramic & Leather Leaves Necklace"
},
"metadata": {
"metadata": {
"attributes": {
"material": "Rustic Ceramic & Leather",
"pattern": "Leaves",
"product": "Necklace"
},
}
}
}
Membuat judul dari deskripsi
Contoh ini menunjukkan cara memberikan deskripsi produk dan membuat judul yang optimal.
Permintaan
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",
}
}
Respons
{
"title": {
"text": "Nike Dunks Red Size 12"
},
"metadata": {
"metadata": {
"attributes": {
"brand": "Nike",
"color": "Red",
"size": "12",
"product": "Dunks"
},
}
}
}
Mengoptimalkan judul dari judul dan deskripsi (beserta contoh kustom)
Dalam contoh ini, kami secara eksplisit memberi label pada atribut produk yang ingin diidentifikasi AI dan urutan atribut dalam output.
Permintaan
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"
}
}
]
}
Respons
{
"title": {
"text": "Luxe Beauty Dark Brown Volumizing & Lengthening Mascara"
},
"metadata": {
"metadata": {
"attributes": {
"brand": "Luxe Beauty",
"colour": "Dark Brown",
"mascara_type": "Volumizing & Lengthening",
"product": "Mascara"
},
}
}
}
Membuat deskripsi dari judul
Contoh ini menunjukkan cara memberikan judul produk dan meminta API membuat deskripsi produk yang sesuai.
Permintaan
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"
}
}
Respons
{
"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.
"
},
}
Membuat judul dan deskripsi dari atribut produk (seperti merek dan warna)
Contoh ini menunjukkan cara memberikan atribut produk untuk membuat judul dan deskripsi produk yang optimal.
Permintaan
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"
}
}
Respons
{
"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."
},
}
Dukungan Bahasa Target
Kolom ini menentukan bahasa teks deskripsi yang dihasilkan dalam respons API. Anda dapat menambahkan target_language
sebagai bagian dari parameter output_spec
:
{
"output_spec": {
"target_language": "language"
}
}
Contoh Nilai:
"korean" (Korean)
"english" (English)
"spanish" (Spanish)
"french" (French)
Contoh Permintaan
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",
}
}
Respons
{
"description": {
"text": "カリフォルニアの黒いコーヒー豆は、あなたの鼻をくすぐる、甘く、フローラルな香りです。この香りは、コーヒー豆の豊かな香りと、ジャスミンとバラの繊細な花の香りをブレンドしたものです。カリフォルニアの黒いコーヒー豆は、あなたの家を居心地の良いカフェに変え、あなたをリラックスした気分にさせてくれるでしょう。この香りは、コーヒー好きにも、フローラルな香り好きにも最適です。カリフォルニアの黒いコーヒー豆で、あなたの家を幸せな香りで満たしましょう!."
},
}
Personalisasi Gaya Bahasa untuk Pembuatan Deskripsi
Untuk membantu membangun merek Anda dan membedakan toko online Anda dari toko lainnya, Anda dapat mempersonalisasi gaya bahasa deskripsi yang dibuat. Text API menawarkan dua opsi:
- Pemilihan Nada yang Telah Ditentukan: Anda dapat memilih dari daftar nada untuk membuat deskripsi baru. Daftar ini mencakup gaya bahasa berikut:
- Default: Sederhana, jelas, dan elegan.
- Menyenangkan: Ringan, menggunakan bahasa positif, humor (lelucon, permainan kata), dan hiperbola (tanpa ironi, sarkasme, atau emoji).
- Formal: Bahasa Inggris standar, tata bahasa yang tepat, kalimat lengkap, tidak ada bahasa gaul atau kontraksi.
- Persuasif: Logis, ringkas, dan didorong oleh argumen untuk meyakinkan pembaca.
- Percakapan: Bahasa sehari-hari yang ramah dan mudah dipahami.
- Gaya Bahasa Khusus Brand: Anda dapat memberikan deskripsi yang ada atau aset teks lainnya dalam gaya bahasa brand Anda. Model AI Generatif akan menganalisis
nada teks dan membuat "deskriptor gaya penulisan" sesuai dengan
aspek berikut:
- Formalitas (seperti, formal, kasual)
- Verbositas (misalnya, ringkas, sangat bertele-tele)
- Gaya bahasa (seperti profesional, informatif, positif, persuasif)
- Struktur kalimat (seperti, "kalimat sederhana dengan sedikit konjungsi")
- Kata dan frasa yang paling sering digunakan
Library klien
Sebaiknya gunakan library klien untuk mengirimkan permintaan Anda. Kami akan membagikan library klien kepada Anda yang dapat diinstal di project Maven Anda.
Contoh kode
Pilih metode autentikasi Anda, lalu siapkan contoh kode ini menggunakan petunjuk ini. Berikut contoh yang dapat Anda gunakan untuk membuat saran teks.
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);
}
}
Error dan masalah umum
Berikut beberapa kesalahan umum dan solusinya.
Info produk diperlukan untuk membuat saran teks
Jika Anda menerima pesan error berikut
Error message:
"error": {
"code": 400,
"message": "[product_info] Product info is required to generate text suggestions.",
"status": "INVALID_ARGUMENT",
...
}
Tambahkan product_info
di isi permintaan dan isi dengan benar setidaknya salah satu dari
product_attributes
atau product_image
.
Misalnya, memposting ini akan menghasilkan error.
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"output_spec": {
"workflow_id": "title"
}
}
Setidaknya satu kolom product_info diperlukan untuk membuat saran teks
Error ini
{
"error": {
"code": 400,
"message": "[product_info.product_attributes] At least one field of product_info is required to generate text suggestions.",
"status": "INVALID_ARGUMENT",
...
}
menunjukkan bahwa Anda perlu menyertakan setidaknya satu kolom product_info
dalam
isi permintaan.
Misalnya, memposting ini akan menghasilkan error.
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
},
"output_spec": {
"workflow_id": "title"
}
}
Gunakan sesuatu seperti
"product_info": {
"product_attributes": {
"description": "Selling size 12 Nike dunks. Oh they are red by the way!"
}
}
atau
"product_info": {
"product_image":{
"uri": "https://cdn.shopify.com/s/files/1/0653/5879/0892/products/1672082339438_550x825.jpg?v=1672082415"
}
}
(Sesuatu) wajib ada di setiap title_example
Error seperti empat contoh berikut
{
"error": {
"code": 400,
"message": "[title_examples.product_info] At least one field of product_info is required in each title_example.",
"status": "INVALID_ARGUMENT",
...
}
atau
{
...
"message": "[title_examples.category] Category is required in each title_example.",
...
}
atau
{
...
"message": "[title_examples.title_format] Title format is required in each title_example.",
...
}
atau
{
...
"message": "[title_examples.final_product_info] At least one field of final_product_info is required in each title_example.",
...
}
menunjukkan bahwa Anda belum mengisi sub-kolom yang wajib diisi.
Misalnya, permintaan berikut akan menghasilkan error.
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": []
}
Untuk mengatasinya, untuk setiap title_example yang ditentukan dalam permintaan, isi semua sub-kolom berikut:
product_info
category
title_format
final_product_info
Berikut contoh yang berfungsi:
{
"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 tidak didukung
Jenis error ini
{
"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",
...
}
akan dihasilkan dari permintaan seperti
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"
}
}
Permintaan menetapkan workflow_id
ke "attributes", tetapi kolom ini hanya mendukung salah satu
nilai berikut:
- title: Membuat atau mengoptimalkan judul produk.
- description: Membuat atau mengoptimalkan deskripsi produk.
- tide: Membuat atau mengoptimalkan judul dan deskripsi produk.
Gaya bahasa tidak didukung
Error "Gaya bahasa tidak didukung" seperti
{
"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",
...
}
akan dihasilkan dari permintaan seperti
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"
}
}
Perhatikan bahwa tone
disetel ke "cheerful", tetapi kolom ini hanya mendukung salah satu
nilai berikut:
- default: Sederhana, jelas, dan elegan.
- menyenangkan: Ringan, menggunakan bahasa positif, humor (lelucon, permainan kata), dan melebih-lebihkan (tanpa ironi, sarkasme, atau emoji).
- formal: Bahasa Inggris standar, tata bahasa yang tepat, kalimat lengkap, tidak ada bahasa gaul atau kontraksi.
- persuasif: Logis, ringkas, dan didorong oleh argumen untuk meyakinkan pembaca.
- percakapan: Bahasa sehari-hari yang ramah dan mudah dipahami.