-
-
Notifications
You must be signed in to change notification settings - Fork 76
/
test_rest.py
37 lines (32 loc) 路 981 Bytes
/
test_rest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# mypy: ignore-errors
import pytest
import spacy
PIPE_CFG = {
"backend": {
"@llm_backends": "spacy.REST.v1",
"api": "OpenAI",
"config": {"temperature": 0.3, "model": "text-davinci-003"},
},
"task": {"@llm_tasks": "spacy.NoOp.v1"},
}
@pytest.mark.external
def test_initialization():
"""Test initialization and simple run"""
nlp = spacy.blank("en")
nlp.add_pipe("llm", config=PIPE_CFG)
nlp("This is a test.")
@pytest.mark.external
def test_rest_backend_error_handling():
"""Test error handling for default/minimal REST backend."""
nlp = spacy.blank("en")
with pytest.raises(ValueError) as err:
nlp.add_pipe(
"llm",
config={
"task": {"@llm_tasks": "spacy.NoOp.v1"},
"backend": {"config": {"model": "x-text-davinci-003"}},
},
)
assert "The specified model 'x-text-davinci-003' is not available." in str(
err.value
)