Skip to content

Commit

Permalink
Trim leading whitespace when processing (jupyterlab#900)
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski authored Jul 17, 2024
1 parent 83c0cf8 commit 12d069e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ def post_process_suggestion(suggestion: str, request: InlineCompletionRequest) -
for identifier in markdown_identifiers.get(language, [language])
] + ["```"]
for opening in bad_openings:
if suggestion.startswith(opening):
suggestion = suggestion[len(opening) :].lstrip()
# ollama models tend to add spurious whitespace
if suggestion.lstrip().startswith(opening):
suggestion = suggestion.lstrip()[len(opening) :].lstrip()
# check for the prefix inclusion (only if there was a bad opening)
if suggestion.startswith(request.prefix):
suggestion = suggestion[len(request.prefix) :]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ async def test_handle_request(inline_handler):
("```python\nTest python code\n```", "Test python code"),
("```\ntest\n```\n \n", "test"),
("```hello```world```", "hello```world"),
(" ```\nprint(test)\n```", "print(test)"),
("``` \nprint(test)\n```", "print(test)"),
]


Expand Down

0 comments on commit 12d069e

Please sign in to comment.