I have a template prompt similar to this one:
prompt = f"""
Write a poem about the topic delimited by triple backticks if it starts with a consonant,
otherwise say
"foo".
Topic: ```{topic}```
"""
and a list of topics:
topics = ['cuddly pandas', 'ugly bears', 'sketchy Elons']
I would like to query the OpenAI API with the same base prompt, for each topic in topics
. How can I do that? This works, but it seems a bit inelegant to have to redefine the f-string at each iteration of the for loop:
for topic in topics:
prompt = f"""
Write a poem about the topic delimited by triple backticks if the first word of the topic starts with a
consonant,
otherwise say
"foo".
Topic: ```{topic}```
"""
print(prompt)