Minor change in prompt causing a return of no text using python

Hi I’m a beginner programmer trying to tinker and understand things, and was immediately shut down… The following code works with its current prompt of “:Please write a summary of the following text”. However any change to this seems to break it

import openai

Authenticate with the OpenAI API

openai.api_key = “API-KEY”
model_engine = “text-davinci-003”

Define a function to generate summaries using OpenAI’s GPT-3

def generate_summary(text):
prompt = (
f"Please write a summary of the following text:\n\n{text}\n\nSummary:"
response = openai.Completion.create(
if response.choices[0].text:
return response.choices[0].text.strip()
return None

Define a function to fetch news from a specific source

print(generate_summary(“With its balmy beaches, laid back lifestyles and holiday vibe, the tropical paradise of Bali has much to offer any world weary traveler”))

However if I change the prompt just slightly it will quickly break and return no text. Something like “elaborate on the following text” or “write a poem including words from the following text” or “summarize using the style of old Victorian English”

All of these things seem to be easy for chatgpt in the browser, but somehow im tripping up. Is there anyone out there that can shed some light?

Increase max_tokens. Your prompt is now much longer and there is no room for it to give a response.

Also (temporarily) remove the stop setting

1 Like

Thanks!.That did seem to work. I generated this script using chat-gpt actually so not entirely sure why it put the stop=“\n” in there.

1 Like

I think the reason is that your poem or text is starting with a new line, where your previous prompt didn’t include it at the start

1 Like