API を使用すると、利用可能な商品情報を使用して商品タイトルと説明文を生成できます。この API は次のものを受け取ります。
- 商品属性を含む省略可能な JSON 辞書。例:
{"brand": "MyBrand", "title": "White Tee", "size": "XL"}
。 - 省略可能な商品画像。例:
{"uri": "https://my-store.com/img/1.png"}
。 - タイトルの書式設定オプション(
attribute_separator
、target_language
、attribute_order
。 - データラベル付けの例。(下記を参照)
まず、前提条件を設定します。
import requests
API_KEY=""
API_ENDPOINT=""
画像のみから提案されたタイトルを取得して、商品の作成をスピードアップします。
my_product_image = 'https://cdn.shopify.com/s/files/1/0653/5879/0892/products/1672082339438_550x825.jpg?v=1672082415'
payload = {}
payload |= {'output_spec': {'workflow_id': 'title', 'attribute_separator': '-'}}
payload |= {'product_info':{}}
payload['product_info'] |= {'product_image':{'uri': my_product_image}}
response = requests.post(API_ENDPOINT, params={'key': API_KEY}, json=payload)
suggested_title = response.json()['title']['text']
print(suggested_title)
Rustic Ceramic & Leather Leaves Necklace
説明文から提案されたタイトルを取得して、商品の作成を迅速に行うことができます。
商品作成フローでユーザーに画像と簡単な説明の入力を求める場合は、次のパターンを使用して商品タイトルを提案できます。
my_product_description = 'selling size 12 nike dunks. oh they are red by the way!'
payload = {}
payload |= {'output_spec': {'workflow_id': 'title'}}
payload |= {'product_info':{'product_attributes': {'description': my_product_description}}}
response = requests.post(API_ENDPOINT, params={'key': API_KEY}, json=payload)
print(response.json()['title']['text'])
Nike Dunks Red Size 12
タイトルと説明からタイトルの候補を取得して、商品の作成をスピードアップします。
この例では、AI に識別させたい商品属性を明示的にラベル付けしています。
title = 'Volumizing & Lengthening Mascara - Dark Brown'
description = "This high-impact mascara delivers both voluptuous volume and dramatic length without clumping or smudging."
payload = {}
payload |= {'output_spec': {'workflow_id': 'title'}}
payload |= {'product_info':{'product_attributes': {'title': title, 'description': description, 'brand': 'Luxe Beauty'}}}
payload |= {
"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"
}
}
]
}
response = requests.post(API_ENDPOINT, params={'key': API_KEY}, json=payload)
print(response.json())
{
"title": {
"text": "Luxe Beauty Dark Brown Volumizing & Lengthening Mascara"
},
"metadata": {
"metadata": {
"attributes": {
"brand": "Luxe Beauty",
"colour": "Dark Brown",
"mascara_type": "Volumizing & Lengthening",
"product": "Mascara"
},
}
}
}
タイトルから提案された説明を取得して、商品の作成を迅速に行うことができます。
商品作成フローでユーザーに画像とタイトルを入力するよう求める場合は、次のパターンを使用して商品説明を提案できます。
my_product_title = 'Rustic Ceramic & Leather Leaves Necklace'
payload = {}
payload |= {'output_spec': {'workflow_id': 'description'}}
payload |= {'product_info':{'product_attributes': {'title': my_product_title}}}
response = requests.post(API_ENDPOINT, params={'key': API_KEY}, json=payload)
print(response.json()['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.
ブランドと色からタイトルと説明の両方を取得して、商品の作成を迅速化します。
この例では、workflow_id
を "tide"
に設定して、タイトルと説明の両方を取得しています。
payload = {}
payload |= {'output_spec': {'workflow_id': 'tide'}}
payload |= {'product_info':{'product_attributes': {'brand': 'Mr. Beast', 'color': 'purple'}}}
payload['product_info'] |= {'product_image':{'uri':'https://mrbeast.store/cdn/shop/files/0015dlv_0000_327.jpg?v=1702754475&width=500'}}
response = requests.post(API_ENDPOINT, params={'key': API_KEY}, json=payload)
print(response.text)
{
"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."
},
}
ターゲット言語のサポート
このフィールドは、API レスポンスで生成される説明テキストの言語を指定します。これは output_spec パラメータの一部として追加されます。
{"output_spec": {"target_language": "language"}}
値の例:
"korean" (Korean)
"english" (English)
"spanish" (Spanish)
"french" (French)
"pirate" (Pirate)
ペイロードの JSON の例
title = "Granos de café negro"
description = "Los granos de café negro en California"
payload = {}
payload |= {"output_spec":
{
"workflow_id": "description",
"target_language":"japanese", # specify language here
"attribute_order": ["scent", "product"],
"tone":"playful"}
}
payload |= {"product_info":{"product_attributes": {"description": description, "brand": "Parfums de Paris", "scent": "Floral"}}}
出力例
{
"description": {
"text": "カリフォルニアの黒いコーヒー豆は、あなたの鼻をくすぐる、甘く、フローラルな香りです。この香りは、コーヒー豆の豊かな香りと、ジャスミンとバラの繊細な花の香りをブレンドしたものです。カリフォルニアの黒いコーヒー豆は、あなたの家を居心地の良いカフェに変え、あなたをリラックスした気分にさせてくれるでしょう。この香りは、コーヒー好きにも、フローラルな香り好きにも最適です。カリフォルニアの黒いコーヒー豆で、あなたの家を幸せな香りで満たしましょう!"
}
}
言語コードを間違って入力すると、エラーが発生する可能性があります。
言語または値がサポートされていない場合、説明テキストはデフォルトで英語になります。
説明生成のトーンのパーソナライズ
ブランドを確立し、オンライン ストアを他と差別化するために、生成された説明のトーンをパーソナライズできます。Text API には次の 2 つのオプションがあります。
トーンのリストから選択して、新しい説明を生成できます。このリストには、次のトーン スタイルが含まれています。
- デフォルト
- 遊び心たっぷり
- フォーマル
- 訴求力が高い
- 会話型
ブランドのトーンに合わせて、既存の説明文やその他のテキスト アセットを指定できます。LLM は、テキストのトーンを分析し、次の側面に従って「ライティング スタイル記述子」を生成します。
- フォーマル度(フォーマル、カジュアルなど)
- 読み上げの詳細設定(簡潔、非常に詳細など)
- トーン(プロフェッショナル、有益、ポジティブ、説得力があるなど)
- 文の構造(例: 「接続詞が少ない単純な文」)
- 最も頻繁に使用される単語とフレーズ