Borstch steps

Anton Ioffe - August 25th 2023 - 5 minutes read

Introduction

Borstch steps is a tool in the Borstch ecosystem that helps automate complex repetitive tasks (flows) consisting of multiple steps.

It is initially developed in the context of AI when you need a sequence of interactions with Chat GPT to achieve the final result. But it can also be applied to any other task where you need to process data in some way and generate the output.

Let's look at an example - writing articles. It is not a secret that advanced copywriters today heavily rely on AI in their work.

You can ask Chat GPT to write an article, and in some cases, even with a single prompt (especially if it is well-designed), you can get a decent output.

But if you want a solid result you need more than just one prompt, you need a flow of steps. On the high level, it could look like:

  1. Create an outline for the topic
  2. Self-analyze the possible improvements and generate recommendations for writing each section
  3. For each section: (3.1) generate the structure, (3.2) write the text, (3.3) check for possible improvements
  4. Write the title and description
  5. Combine all together
  6. Make the last adjustments on the whole text

Having a detailed flow would lead the AI to generate high-quality text in the end.

Let's analyze the flow that we described above.

  1. Each step relies on some context that was generated in the previous steps. For this, you either need a large context window or the possibility to use only the needed information in each prompt
  2. There is a "for each" loop - you need to iterate over each section and process it separately
  3. You need to combine the results of processing each section together

This outlines the high-level requirements for a tool that will help us automate this process.

I tried to implement them in Borstch steps. Let's look at its capabilities.

Create flows

You can create many flows. Each flow will be responsible for its task. Borstch steps flows

Configure the flow

A flow has a name. Use this field to indicate the purpose of the task.

There is also a global configuration (currently only Open AI Api Key) that will be used by for the flow steps. Borstch steps configuration

Flow steps

Steps are the main building blocks of the flow.

Each step represents its piece of logic. There are several predefined step types that you can choose from:

  • Custom input
  • Custom JS
  • GPT Prompt
  • For each

Steps run one after the other in a sequence. You can reorder steps using drag and drop.

A step can use data generated by steps that run before it.

Each step type has its configuration, defining how it will apply its logic.

Custom input

The custom input step allows you to input your data or create new data combining it with values generated in the previous steps.

Input step configuration is where you define the custom input.

If you check the Parse as JSON checkbox the input will be parsed as JSON. Make sure that the input is a valid JSON, otherwise, the step execution will fail.

Pay attention to the Name step configuration field. This is how you will be able to access the data from this step in the next steps.

To use data generated in a previous step you can use {{variable}} syntax.

Let's say you name one of the previous steps articleName. So you can create a custom input step that will generate a JSON using a value from the articleName step:

{
  name: "{{articleName}}"
}

or

{
  name: "{{results.articleName}}"
}

Borstch steps custom input

GPT Prompt

This step makes a request to Chat GPT with a prompt that you define in the step configuration.

Same as in the custom input step, the gpt prompt step can use data from previous steps.

The response from Chat GPT can be also parsed as JSON.

Borstch steps Chat GPT prompt

Custom JS

The custom JS step allows you to run your custom JS code to perform any action needed:

  • process data within the flow
  • fetch additional data from an API
  • etc

The code is asynchronous, you can use async/await syntax. The returned value will be used as the result of the step.

You can also use {{variables}} in the code. But remember that those will be just replaced with the values. If you expect a string make sure to surround the variable with quotes: '{{variable}}'.

But in custom JS steps a better way to reference values from previous steps would be to use built-in variables: results and globalResults. These are objects, properties of which are values generated by previous steps.

What is globalResults? Well, let's talk about this in the for each step type. But it is important to mention that globalResults is also available in the {{globalResults.myCustomInput}} syntax as well.

What if the result of a step is a JSON? In this case, you can use the value as actually a JSON object. For example:

Hey Chat GPT, let's outline an article on the topic "{{results.articleConfig.title}}"

or

const result = fetch(`${results.config.baseUrl}/article/topics`).json();
return result.topics;

Borstch steps custom JS

For each

This is a special step type. It allows us to perform iterations over the data.

For each step includes child steps inside forming a nested structure of the whole flow. And yes - you can nest for each steps inside other for each steps. It is up to you how deep it will be.

For each step requires input data to iterate over. It has a Data Path configuration property which represents the path to the data array with the results from the previous steps.

The path as in the variables mentioned above can be in one of the formats: myStepResult or results.myStepResult or globalResults.myStepResult.

The value that we are currently iterating over will be available as the data local value: data or results.data.

So now that we know about nesting it is time to talk about globalResults and local results.

  • results represent values of steps within the current nesting level.
  • If you write data it is the same as if you write results.data.
  • globalResults represent the root level.

Borstch steps for each

Sharing flows

You can publish a flow to make it available by the link and share it with your audience. Other users will not be able to modify your flow, but they will be able to clone it and adjust it for their goals.

It is important to mention that for security reasons the global flow configuration (Open AI Api Key) is not shared and the user who will clone your flow will have to insert his own Open AI Api Key.

You can unpublish the flow at any moment.

Borstch steps sharing

Login

Since the tool is a part of the Borstch ecosystem I implemented authorization via Botstch.

Click Login with Borstch and create a Borstch account.

Login with Borstch

Conclusion

This was an overview of the Borstch steps tool and its capabilities. In future articles, I will publish usage examples and share the flows for cloning.

Looking forward to seeing your examples of the tool usage!

Don't Get Left Behind:
The Top 5 Career-Ending Mistakes Software Developers Make
FREE Cheat Sheet for Software Developers