我正在使用 Python OpenAI API 生成来自 GPT-4 的响应。问题是有时回复中的最后一句话会被删掉。如果最后一句话被删掉,我想把它删掉。例如,
This is a full sentence. A second sentence. This sentence is cu
应生成 This is a full sentence. A second sentence.
,This is another example. Here the last punctuation is missing
应生成 This is another example.
此外,Here we are again. How are you doing?
不应被剪切。
如何实现这一目标?这可以使用 nltk 或正则表达式来实现吗?
text='This is a full sentence. A second sentence. hello'
text=text.strip()+' '
text=text.replace('. ','. <new_line>')
sentences=text.split('<new_line>')
if '. ' not in sentences[-1]:
sentences.pop()
out=''.join(sentences)