How to

Cross-Platform Copywriting with Dify

In Dify, not all nodes have a low entry threshold. Some nodes may be overlooked during the process of orchestrating flows, but combining them will unlock more possibilities for Dify in complex tasks. This blog will use the scenario of Cross-Platform Copywriting to demonstrate how to use template conversion nodes for type conversion, write session variables during iterations, accelerate flow processing in parallel, optimize streaming output experiences with multiple answer nodes, and explore more uses of code nodes.

Evan Chen

Product Manager

Lyson

Dify Contributor

Written on

Sep 14, 2024

Share

Share to Twitter
Share to LinkedIn
Share to Hacker News

How to

·

Sep 14, 2024

Cross-Platform Copywriting with Dify

In Dify, not all nodes have a low entry threshold. Some nodes may be overlooked during the process of orchestrating flows, but combining them will unlock more possibilities for Dify in complex tasks. This blog will use the scenario of Cross-Platform Copywriting to demonstrate how to use template conversion nodes for type conversion, write session variables during iterations, accelerate flow processing in parallel, optimize streaming output experiences with multiple answer nodes, and explore more uses of code nodes.

Evan Chen

Product Manager

Lyson

Dify Contributor

Share to Twitter
Share to LinkedIn
Share to Hacker News

How to

Cross-Platform Copywriting with Dify

In Dify, not all nodes have a low entry threshold. Some nodes may be overlooked during the process of orchestrating flows, but combining them will unlock more possibilities for Dify in complex tasks. This blog will use the scenario of Cross-Platform Copywriting to demonstrate how to use template conversion nodes for type conversion, write session variables during iterations, accelerate flow processing in parallel, optimize streaming output experiences with multiple answer nodes, and explore more uses of code nodes.

Evan Chen

Product Manager

Lyson

Dify Contributor

Written on

Sep 14, 2024

Share

Share to Twitter
Share to LinkedIn
Share to Hacker News

How to

·

Sep 14, 2024

Cross-Platform Copywriting with Dify

Share to Twitter
Share to LinkedIn
Share to Hacker News

How to

·

Sep 14, 2024

Cross-Platform Copywriting with Dify

Share to Twitter
Share to LinkedIn
Share to Hacker News

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:

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.

You are tasked with creating a Twitter thread based on a given article. Your goal is to summarize the main points of the article in a series of tweets while maintaining the original style and avoiding marketing language. Here's how to approach this task:

First, carefully read the following original text:

<original_text>


</original_text>

Now, follow these instructions to create the Twitter thread:

1. Analyze the text and identify the main points and key ideas.

2. Break down the content into a series of concise tweets. Each tweet should be self-contained and convey a complete thought or idea.

3. Aim for 5-8 tweets in total, depending on the length and complexity of the original text.

4. Keep each tweet within the 280-character limit.

5. Number each tweet at the end, indicating its position in the thread. For example, "2/8" for the second tweet in a thread of eight tweets. Place this number on a new line at the end of each tweet.

6. Maintain the style and tone of the original text. Do not use marketing language or try to sensationalize the content.

7. For the first tweet, create an engaging opening that encourages users to read the entire thread. End this tweet with "Here are the details 👇🧵" to indicate that more information follows.

8. In the last tweet, provide a brief conclusion or summary of the main takeaway from the article.

When you're ready to present the Twitter thread, format your response as follows:

<twitter_thread>
<tweet1>
[Content of first tweet]

1/[total number of tweets]
</tweet1>

<tweet2>
[Content of second tweet]

2/[total number of tweets]
</tweet2>

[Continue with remaining tweets]

<tweet[n]>
[Content of last tweet]

[n]/[total number of tweets]
</tweet[n]>
</twitter_thread>

Remember to maintain the original style and avoid marketing language throughout the thread. Focus on accurately conveying the information from the original text in a concise and engaging manner

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.

On this page

    Related articles

    The Innovation Engine for Generative AI Applications

    The Innovation Engine for Generative AI Applications

    The Innovation Engine for Generative AI Applications