How to prompt the API to enhance/rephrase a specific section of a larger article

Imagine having an article of 1,000+ words. The user doesn’t like a specific phrasing of a paragraph or a sentence and he wants to rephrase/enhance it.

What would be the best prompt using Chat model to get the full context of the article and tell to just replace that specific part? What are best practices in this, so I don’t waste too much tokens in including whole context? So far, what I tried did not work, did always get much more text back than just a simple rephrasal/improvement

I am using gpt-4 and the prompt is

messages: [
{role: 'system', content: 'You are the best article writer'},
{role: 'assistant', content: 'This is the article:' + article.content},
{role: 'user', content: `From the article, rephrase and improve this text: '${query?.input}' and return just the improved part`}

How can I improve my prompt to just get what I want and to spare as much tokens as possible?

Welcome @damir.secki

If you don’t want the cost of tokens of the entire article, simply let the user paste the part they want rephrased along with the description of the manner they want the rephrase in.

well, than it would fairly possible that the rephrased text would be repeated from somewhere else in the article (not verbatim obviously) … I want to avoid repetition if possible.

If I cannot avoid including the context, that is fine… my question is more how to form the correct prompt to give me just the rephrase and not the more - with my current (above mentioned prompt) if I select some simple text… like a title… I than get couple of paragraphs out instead of just that title rephrased

Id guess what you need to do is tell gpt in the system prompt to only return the sentence selected by the user. Gpt 3.5 won’t do as well with this instruction, gpt4 will do better.

I’ve had success by literally asking it something like “Use the whole article as context, but only return the re-written version of the specified section. Don’t respond with the entire article.”

Yeah, something like “Here is the full article: article. Please output an alternative phrasing of only the following paragraph: repeat paragraph to rephrase.”