Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a64ad8d

Browse files
committed
Add a test for slow-starting completion provider
1 parent e95f1a6 commit a64ad8d

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

tests/fake_llm.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
from time import sleep
23

34
try:
45
from jupyter_ai_magics import BaseProvider
@@ -87,3 +88,16 @@ async def _stream(self, sentence, request_number, token, start_with=""):
8788
reply_to=request_number,
8889
done=True,
8990
)
91+
92+
93+
class SlowStartingCompletionProvider(BaseProvider, FakeListLLM): # type: ignore[misc, valid-type]
94+
id = "slow_provider"
95+
name = "Slow Provider"
96+
model_id_key = "model"
97+
models = ["model_a"]
98+
99+
def __init__(self, **kwargs):
100+
kwargs["responses"] = ["This fake response will be used for completion"]
101+
kwargs["model_id"] = "model_a"
102+
sleep(10)
103+
super().__init__(**kwargs)

tests/test_shortcuts.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
import time
23
from IPython.terminal.interactiveshell import PtkHistoryAdapter
34
from IPython.terminal.shortcuts.auto_suggest import (
45
accept,
@@ -61,6 +62,17 @@ async def test_llm_autosuggestion():
6162
assert event.current_buffer.suggestion.text == FIBONACCI[len(text) :]
6263

6364

65+
def test_slow_llm_provider_should_not_block_init():
66+
ip = get_ipython()
67+
provider = NavigableAutoSuggestFromHistory()
68+
ip.auto_suggest = provider
69+
start = time.perf_counter()
70+
ip.llm_provider_class = "tests.fake_llm.SlowStartingCompletionProvider"
71+
end = time.perf_counter()
72+
elapsed = end - start
73+
assert elapsed < 0.1
74+
75+
6476
@pytest.mark.parametrize(
6577
"text, suggestion, expected",
6678
[

0 commit comments

Comments
 (0)