solved streaming off-by-one issue

This commit is contained in:
Nate Sesti 2023-07-02 18:23:46 -07:00
parent b1da2682c9
commit 0b46f205fa
3 changed files with 10 additions and 5 deletions

View file

@ -199,7 +199,7 @@ class ContinueSDK(AbstractContinueSDK):
# Don't insert after latest user message or function call
i = -1
if history_context[i].role == "user" or history_context[i].role == "function":
if len(history_context) > 0 and (history_context[i].role == "user" or history_context[i].role == "function"):
i -= 1
history_context.insert(i, msg)

View file

@ -8,8 +8,14 @@ def dedent_and_get_common_whitespace(s: str) -> Tuple[str, str]:
# Longest common whitespace prefix
lcp = lines[0].split(lines[0].strip())[0]
# Iterate through the lines
for i in range(1, len(lines)):
# Empty lines are wildcards
if lines[i].strip() == "":
continue
# Iterate through the leading whitespace characters of the current line
for j in range(0, len(lcp)):
# If it doesn't have the same whitespace as lcp, then update lcp
if j >= len(lines[i]) or lcp[j] != lines[i][j]:
lcp = lcp[:j]
if lcp == "":

View file

@ -368,7 +368,7 @@ class DefaultModelEditCodeStep(Step):
# Insert the suggestion
replacement = "\n".join(current_block_lines)
start_line = current_block_start + 1
start_line = current_block_start
end_line = current_block_start + index_of_last_line_in_block
await sdk.ide.showSuggestion(FileEdit(
filepath=rif.filepath,
@ -376,10 +376,9 @@ class DefaultModelEditCodeStep(Step):
start_line, 0, end_line, 0),
replacement=replacement
))
if replacement == "":
current_line_in_file += 1
# Reset current block / update variables
current_line_in_file += 1
offset_from_blocks += len(current_block_lines)
original_lines_below_previous_blocks = original_lines_below_previous_blocks[
index_of_last_line_in_block + 1:]
@ -501,7 +500,7 @@ class DefaultModelEditCodeStep(Step):
await sdk.ide.showSuggestion(FileEdit(
filepath=rif.filepath,
range=Range.from_shorthand(
current_block_start + 1, 0, current_block_start + len(original_lines_below_previous_blocks), 0),
current_block_start, 0, current_block_start + len(original_lines_below_previous_blocks), 0),
replacement="\n".join(current_block_lines)
))