post https://api.ai21.com/studio/v1/paraphrase
Suggest improvements to provided text
Overview
Paraphrases the entire text, or a specified subsection of the text, in the specified style. You should provide all the context that the model needs in order to properly understand the meaning of the text and make it fit smoothly within any containing text. The model returns 10 possibilities for the requested text.
Note that to improve fluency when paraphrasing a subsection within text
, the model can extend the start and end indexes to include an additional word at the start and end of the values indicated by startIndex
and endIndex
.
Learn more about using the Paraphrase model.
Examples
from ai21 import AI21Client
client = AI21Client(api_key=<<AI21_API_KEY>>)
def paraphrase():
TEXT = "Dear grandmother, it is with great pleasure and gratitude that I received your gift on Monday last."
response = client.paraphrase.create(
text=TEXT,
style="casual"
)
for i in response.suggestions:
print(i.text)
# This time, ensure that "Dear grandmother" is not changed
response = client.paraphrase.create(
text=TEXT,
style="casual",
start_index=18
)
for i in response.suggestions:
print(i.text)
# Response
I received your gift on Monday with great pleasure and gratitude.
On Monday last, I received your gift with great pleasure and gratitude.
Thank you so much for your gift on Monday, grandmother. I really appreciate it.
Grandma, I got your gift on Monday with great pleasure and gratitude.
Thank you so much for your gift, grandmother. It's with great pleasure and gratitude that I received it.
It was a pleasure receiving your gift on Monday. Thanks so much.
Grandmother, I got your gift last Monday with great pleasure and gratitude.
Your gift on Monday was greatly appreciated and I'm very happy to have it.
Grandma, I received your gift on Monday with great pleasure and gratitude.
Thank you very much for sending the gift on Monday. I really appreciate it.
# Try 2
Dear grandmother, I received your gift on Monday with great pleasure and gratitude.
Dear grandmother, I got your gift on Monday with great pleasure and gratitude.
Dear grandmother, I'm so happy and grateful to get your gift on Monday.
Dear grandmother, I was delighted to receive your gift last Monday.
Dear grandmother, I received your gift on Monday with much pleasure and gratitude.
Dear grandmother, I got your gift on Monday and am really grateful for it.
Dear grandmother, your gift on Monday brought me great pleasure and gratitude.
Dear grandmother, I am so grateful for your gift, I got it on Monday.
Dear grandmother, I got your gift on Monday, and it's filled with joy and gratitude.
Dear grandmother, I got the gift on Monday, and I am so grateful for it.
ROOT_URL = "https://api.ai21.com/studio/v1/"
def paraphrase():
url = ROOT_URL + "paraphrase"
response = requests.post(
url,
headers={"Authorization": f"Bearer {AI21_API_KEY}"},
json={
"text": "Dear grandmother, it is with great pleasure and gratitude that I received your gift on Monday last.",
"style": "casual",
"startIndex": 18
}
)
print(response.json())
# Response
{'id': '9a9c9f9f-cfbe-4184-7f5e-25104b9926c1',
'suggestions': [
{'text': 'Dear grandmother, I received your gift on Monday with great pleasure and gratitude.'},
{'text': 'Dear grandmother, I got your gift on Monday with great pleasure and gratitude.'},
{'text': "Dear grandmother, I got your gift on Monday and I'm so grateful."},
{'text': 'Dear grandmother, thank you for the gift last Monday. I really appreciate it.'},
{'text': "Dear grandmother, I'm so glad I received your gift last Monday."},
{'text': 'Dear grandmother, I received your gift last Monday with great pleasure.'},
{'text': 'Dear grandmother, I got your gift from you last week with much pleasure and gratitude.'},
{'text': 'Dear grandmother, thank you again for the gift you sent me on Monday.'},
{'text': 'Dear grandmother, I loved receiving your gift last Monday. I appreciate it very much.'},
{'text': 'Dear grandma, I received your gift on Monday with great pleasure and gratitude.'}]}