How to
Cross-Platform Copywriting with Dify
Aug 1, 2023
·
Sep 14, 2024
Cross-Platform Copywriting is a common work scenario for social media influencers and companies. The usual process involves gathering copy and images from the company's blog or public webpages, then rewriting the copy to fit the styles of different social media platforms while also selecting appropriate images for the posts. Finally, these are published on social media because if content has already been created, why not reach a larger audience?
Let’s break down this process step by step to show you how to design this chat flow. Let's dive in!
Chatflow Overview
First, we need to obtain the authorization for the LLM and tools required in this chatflow:
LLM KEY (e.g., Claude)
The entire process can be divided into two parts. First, web scraping is conducted from a specified webpage, developing a rewriting strategy based on predefined tones while simultaneously generating copy for Redbook, Instagram, and Twitter/threads. The second part involves organizing the images from the webpage as links and finally using the tweet copy to output content with images in link form for future use. With this, the entire process is complete.
Configure the Starting Node and Conversation Opener
The feature is a universal configuration provided for each application type in Dify. Click on the "Features" in the upper right corner -> Enable the "Conversation Launcher" feature -> Enter the English text "When you’re ready, click the Start button below 👇", and then set the default reply to just "Start". This way, it looks like a "Start button."
You can add form variables to the start form for input parameters at the beginning of the chatflow. This way, you can constrain/standardize user behavior while ensuring stable input. Since we will be web scraping in subsequent nodes, it's necessary to provide a URL right from the start. The tone is used in the Basic strategy node to determine the style of the copy.
Using the Jina AI Tool for Web Scraping
Using the Jina AI tool, you can parse text with complex layout formats from a URL into markdown format for easier processing later. The parsed text also serves as foundational material for multi-platform publishing.
It's also very easy to use; just authorize, input the URL, and configure the page to open image captioning and gather all images at the end.
Cross-platform style rewrite
Here you can use the parallel execution feature added in version 0.8.0 of dify to start the operation of four branches simultaneously, which helps avoid long waiting times caused by running five LLM nodes consecutively. Don't forget to add an interesting "reply placeholder buffer" after the LLM node, especially when generation time is longer, as this can reduce the discomfort and anxiety associated with waiting.
Such techniques can be used before any nodes that require a long loading time in the process with an answer node; this is a great way to enhance user experience in the dify web app.
We can take Twitter as a typical example to look at the prompts: this prompt can be used to generate copy in the style of Twitter threads. For information that is highly time-sensitive, we can use this application to quickly sync web news to major social media platforms.
Sometimes, using models concurrently can lead to reaching the API RPM rate limit. This issue can be resolved by employing model load balancing(professional feature) or configuring different models on the nodes.
Extract Other Materials
The upstream node returned a markdown format image URL reference link. We can use the code node in Dify to extract the URL from the string and return it to an answer node. This way, we can output all the image links returned from the original website.
Here, you can have the LLM output tags with <twitter_thread></twitter_thread>, and then use the code node r'<tweet\d+>(.*?)</tweet\d+>' to split it out using a regular expression to get each tweet's text for easier use in an iterator. Then, output it as an array for input into the iterator. This is a very common and frequent usage.
In the iterator, you can iterate through inner nodes by referencing the iterable array of upstream output using items and index. Additionally, if you want to reference a variable from the n-th iteration in the n+1-th round (where the current iteration depends on previous outputs), you can do this by assigning the variable to a conversation variable and then referencing that conversation variable (globally) to access earlier variables.
The LLM takes the iterative variable "item" as input to generate a stylized description prompt for an image, then outputs it and uses that as input for text2image. The output format of text2image is set to URL, allowing us to access the image via a link.
Use the code node to extract the URL as a string and write it into a preset conversation variable using the variable assignment node, selecting the write mode as append.
The effect is shown in the image, making it easy to obtain the corresponding links for tweet thread images.
Similarly, the iterator will process the input item according to a predefined flow within the iteration and output the processed result. The iterator output variable can achieve the same effect.
You can also set the interaction output to any of the three nodes in the iterator shown in the image, allowing you to flexibly obtain intermediate results during the iteration process.
Because both the output of the iterator and our predefined conversation variable types are arrays, in this case, we can easily escape the node's output using a template conversion node, eliminating the need to implement it through a code node. By the way, the long-awaited custom output type will greatly optimize this part of the process. Additionally, concurrent execution of iterative tasks is also in development! At that time, Dify will bring greater flexibility.
Summary
This is a very comprehensive chatflow use case that covers iteration, conversation variables, template transformation, the use of code nodes, and the applications of two tools: Jina.ai and getimg.ai. Techniques such as parallel processing and using the answer node as a reply placeholder buffer can enhance user experience. I hope this Cross-Platform Copywriting helps you learn more tips and boundaries regarding Dify.