教戰手冊

你可以使用 API,根據現有的產品資訊生成產品名稱和說明。這個 API 接受:

  • 包含產品屬性的選用 JSON 字典。例如:{"brand": "MyBrand", "title": "White Tee", "size": "XL"}
  • 選填產品圖片。例如 {"uri": "https://my-store.com/img/1.png"}
  • 標題格式選項,例如 attribute_separatortarget_languageattribute_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 提供兩種選項:

你可以從語氣清單中選取,生成新的說明。清單中包括以下語氣風格:

  • 預設
  • 調皮
  • 正式
  • 有說服力
  • 對話

你可以提供現有的說明或其他文字素材資源,並使用品牌語氣。LLM 會分析文字的語氣,並根據下列幾點生成「寫作風格描述符」:

  • 正式程度 (例如正式、休閒)
  • 詳細程度 (例如簡潔、非常詳細)
  • 語氣 (例如專業、資訊性、正面、說服力)
  • 句子結構 (例如「simple sentence with few conjunctions」(使用少量連接詞的簡單句子)
  • 最常使用的字詞和片語