diff options
author | Nate Sesti <sestinj@gmail.com> | 2023-06-28 14:19:28 -0700 |
---|---|---|
committer | Nate Sesti <sestinj@gmail.com> | 2023-06-28 14:19:28 -0700 |
commit | 60fd233ce3bbfedb92f217e96922002eb6726f54 (patch) | |
tree | 55d29551b5662e261a97db8227a531d104651198 | |
parent | fa687428cd1392deb5e73f440fbe190fbd961b27 (diff) | |
download | sncontinue-60fd233ce3bbfedb92f217e96922002eb6726f54.tar.gz sncontinue-60fd233ce3bbfedb92f217e96922002eb6726f54.tar.bz2 sncontinue-60fd233ce3bbfedb92f217e96922002eb6726f54.zip |
fix token counting
-rw-r--r-- | continuedev/src/continuedev/steps/core/core.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/continuedev/src/continuedev/steps/core/core.py b/continuedev/src/continuedev/steps/core/core.py index a7e2d8b3..a57b3726 100644 --- a/continuedev/src/continuedev/steps/core/core.py +++ b/continuedev/src/continuedev/steps/core/core.py @@ -160,10 +160,17 @@ class DefaultModelEditCodeStep(Step): return f"`{self.user_input}`\n\n" + description async def get_prompt_parts(self, rif: RangeInFileWithContents, sdk: ContinueSDK, full_file_contents: str): + # We don't know here all of the functions being passed in. + # We care because if this prompt itself goes over the limit, then the entire message will have to be cut from the completion. + # Overflow won't happen, but prune_chat_messages in count_tokens.py will cut out this whole thing, instead of us cutting out only as many lines as we need. + BUFFER_FOR_FUNCTIONS = 200 + total_tokens = model_to_use.count_tokens( + full_file_contents + self._prompt + self.user_input) + BUFFER_FOR_FUNCTIONS + DEFAULT_MAX_TOKENS + # If using 3.5 and overflows, upgrade to 3.5.16k model_to_use = sdk.models.default if model_to_use.name == "gpt-3.5-turbo": - if sdk.models.gpt35.count_tokens(full_file_contents) > MAX_TOKENS_FOR_MODEL["gpt-3.5-turbo"]: + if total_tokens > MAX_TOKENS_FOR_MODEL["gpt-3.5-turbo"]: model_to_use = sdk.models.gpt3516k # Remove tokens from the end first, and then the start to clear space @@ -174,9 +181,6 @@ class DefaultModelEditCodeStep(Step): cur_start_line = 0 cur_end_line = len(full_file_contents_lst) - 1 - total_tokens = model_to_use.count_tokens( - full_file_contents + self._prompt) - if total_tokens > MAX_TOKENS_FOR_MODEL[model_to_use.name]: while cur_end_line > min_end_line: total_tokens -= model_to_use.count_tokens( |