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(
engine=model_engine,
prompt=prompt,
max_tokens=60,
temperature=0.7,
n=1,
stop=“\n”,
)
if response.choices[0].text:
return response.choices[0].text.strip()
else:
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?