Krazal / nppopenai

OpenAI (aka. ChatGPT) plugin for Notepad++
GNU General Public License v2.0
47 stars 12 forks source link

Long responses truncated #2

Closed vinsworldcom closed 1 year ago

vinsworldcom commented 1 year ago

Using Notepad++ 8.5, 64-bit and your latest plugin. First off - amazing! There is an issue I see with longer responses getting truncated.

Enter a pretty open ended question:

"write me a bedtime story about killer swans"

and the response back to Scintilla is:

Once upon a time, in a faraway kingdom, there lived a group of swans. They were beautiful, graceful creatures that everyone loved to watch as they glided across the lake. However, something strange was happening to these swans. They had developed a taste for human flesh and were now known as killer swans.

One day, a young boy named Jack was playing by the lake when he saw the killer swans swimming towards him. He tried to run, but they were too fast. They surrounded him and started pecking at his skin. Jack screamed for help, but no one could hear him. Just as he thought it was the end, a wise old man appeared out of nowhere.

The old man knew how to handle the killer swans. He told Jack to stay still and not make any sudden movements. The old man then took out a bag of bread crumbs and threw them towards the swans. The swans were distracted by the bread crumbs, and Jack was able to escape.

The old man explained to Jack that the killer swans had been cursed by an evil sorcerer. The curse made them crave human flesh. The only way to break the curse was to find the sorcerer and make him reverse the spell.

Jack was determined

and it just ends there - the answer being 1,143 characters according to Notepad++ selection counter. I tried the same query with curl direct from my command line:

curl https://api.openai.com/v1/chat/completions -H "Authorization: Bearer sk-mysecretkeygoeshere" -H "Content-Type: application/json" -d '{ "model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "write me a bedtime story about killer swans"}] }'

and the story completes - obviously different, but complete - 2,072 characters worth.

Cheers.

Krazal commented 1 year ago

Thank you for your feedback and using plugin!

It seems, you've reached an OpenAI token limit. Please go to Plugins » NppOpenAI » Edit Config and set max_tokens=4096 (recommended maximum value). Save file, and click Plugins » NppOpenAI » Load Config or restart Notepad++.

You can find more information about token usage at OpenAI: https://openai.com/pricing

vinsworldcom commented 1 year ago

Just FYI, setting to 4096 returns this error:

image

Seems 4080 is the maximum value you can use without generating that error. And that does appear to fix the issue.

Maybe adding a comment in the INI file about max_tokens in case others have issue?

Cheers.

vinsworldcom commented 1 year ago

Actually, the reason 4080 worked for me was because of the size of my question is included as well, shorter question allows more tokens, longer question will generate that error again if using 4080. I've settled on:

max_tokens=3584

Which allows for a pretty long question and I haven't seen a truncated response yet.

Cheers.

Krazal commented 1 year ago

First of all: I am sorry for the inactivity in the last weeks (months)! :(

I have updated the OpenAI response handling, so if the finish_reason is "length", then "The answer may be incomplete." message will be appear. Additionally, if the finish_reason is "content_filter" (moderation), another alert will pop up.

truncated_answer