Build a Text‑and‑Image Article with Alibaba Cloud AI Custom Plugin in 5 Steps
This tutorial shows how to use Alibaba Cloud's Baileian platform to create a workflow that generates a Xiaohongshu‑style article together with matching images by leveraging a custom large‑model plugin, Python script nodes, and image‑generation tools, complete with step‑by‑step configuration and code examples.
Introduction
This article is the second part of the series "5 Steps to Create a Large‑Model Custom Plugin" and demonstrates how to use an existing custom plugin that supports image generation to produce a richly illustrated article.
Implementation Idea
The workflow follows five main steps:
Use a large model to generate a Xiaohongshu‑style text based on a user‑provided title.
Extract key elements from the generated text to form an image prompt.
Invoke the custom image‑generation plugin to create pictures.
Combine the text and the generated images into a single document.
Return the final markdown‑formatted article to the user.
Building the Workflow
Log in to the Alibaba Cloud Baileian console ( https://bailian.console.aliyun.com/#/home ) and create a new conversational workflow.
1. Add a Large‑Model Node
Configure the node with the following settings:
Mode: Single‑turn processing
Model: Tongyi Qianwen‑Max‑Latest
Parameters: Increase the maximum response length slightly (default 1024) and enable search.
System Prompt: Use the provided simple prompt example.
User Prompt: Directly reference the user’s query.
2. Script Node – Extract Image Prompt
Insert a Python script node that parses the LLM result and outputs a JSON object containing prompt and negative_prompt fields.
def main():
import json
json_obj = json.loads(params["result"])
prompt = json_obj.get("prompt", "")
negative_prompt = json_obj.get("negative_prompt", "")
ret = {
"result": {
"input": {
"prompt": prompt,
"negative_prompt": negative_prompt + ",模糊扭曲的中文、英文"
},
"parameters": {
"size": "1024*1024",
"n": 4
}
}
}
return ret3. Custom Plugin – Image Generation
Select the previously created custom plugin and choose the "image generation" tool. Configure:
Model: wanx2.1‑t2i‑turbo
Input: Reference the prompt from the previous script node.
Parameters: Reference the parameters from the previous script node.
4. Script Node – Wait for Image Generation
Insert a script that pauses for 20 seconds to allow the image task to finish.
def main():
import time
time.sleep(20)
ret = {"result": {}}
return ret5. Custom Plugin – Query Image Result
Use the second tool of the custom plugin to query the generated image by providing the task_id from the previous step.
6. Script Node – Convert Image URLs to Markdown
This node receives the list of image URLs and builds a markdown string.
def main():
url_list = params["urlList"]
ret_string = ""
for url_data in url_list:
if url_data is not None:
ret_string += f"
"
ret = {"result": {"retString": ret_string}}
return ret7. End Node – Merge Text and Images
The final node outputs the combined markdown article containing both the generated text and the embedded images.
Testing
Enter a keyword or article title, run the workflow, and the system will output a complete article with accompanying images.
Extension – Interleaving Images with Paragraphs
To achieve a layout where each paragraph is paired with an image, the article is first split into paragraphs using a dedicated LLM. For each paragraph, a separate image‑prompt is generated and fed to the image‑generation plugin. The following additional steps are required:
Duplicate the original workflow.
Improve the LLM prompt to produce longer text suitable for paragraph splitting.
Add a script node that splits the article JSON into title, first_paragraph, and second_paragraph.
def main():
import json
json_obj = json.loads(params["result"])
title = json_obj.get("title", "")
first_paragraph = json_obj.get("first_paragraph", "")
second_paragraph = json_obj.get("second_paragraph", "")
ret = {"result": {"title": title, "first_paragraph": first_paragraph, "second_paragraph": second_paragraph}}
return retThen generate prompts for each paragraph, invoke the image plugin twice, and finally concatenate the markdown strings.
def main():
import json
json_obj = json.loads(params["result"])
first_prompt = json_obj.get("first_prompt", "")
first_negative_prompt = json_obj.get("first_negative_prompt", "")
second_prompt = json_obj.get("second_prompt", "")
second_negative_prompt = json_obj.get("second_negative_prompt", "")
ret = {"result": {"first_input": {"prompt": first_prompt, "negative_prompt": first_negative_prompt}, "second_input": {"prompt": second_prompt, "negative_prompt": second_negative_prompt}, "parameters": {"size": "1024*1024", "n": 1}}}
return retAfter generating both images, use a final script to merge all markdown parts into the complete article.
def main():
import json
json_obj = json.loads(params["result"])
# Assume retString from previous image nodes are available
# Combine title, paragraphs, and image markdown strings here
# (implementation omitted for brevity)
return {"result": {"final_markdown": "..."}}Running this extended workflow yields an article where each paragraph is accompanied by a relevant illustration.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Alibaba Cloud Developer
Alibaba's official tech channel, featuring all of its technology innovations.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
