Isn't this just some loops and joining with some changes in prompts?
Can't you write this in a for loop calling the open AI API directly?