agentic icon indicating copy to clipboard operation
agentic copied to clipboard

Feature/limit fix: maximum context length limit #580

Open CooperJiang opened this issue 1 year ago • 0 comments

There is a scenario where, assuming our model supports 4096 tokens, we set _maxModelTokens to 3096 and _maxResponseTokens to 1000. Before we check prompt && !isValidPrompt, we have already assigned a value to the message variable, which means that our context will definitely exceed the _maxModelTokens limit. If _maxModelTokens exceeds by a lot, for example, up to 3880, any subsequent response in the conversation that exceeds 400 tokens will result in a context error. Therefore, when we detect this, we need to remove the first item from the context, which is the second item in the systemMessage array, and calculate whether it still exceeds the limit. We need to recursively remove items until the context length is within our set safe limit, in order to ensure that no context errors occur.

[https://github.com/https://github.com/transitive-bullshit/chatgpt-api/issues/542](Make maximum context length limit )

CooperJiang avatar Jun 02 '23 16:06 CooperJiang