Skip to content

Commit 0af8ee2

Browse files
feat: add meaningful LMStudioPredictionError subclasses and session-scoped model loading fixture
1 parent 65a510b commit 0af8ee2

30 files changed

+91
-29
lines changed

.vscode/tasks.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"type": "shell",
6+
"label": "Run chatbot example",
7+
"command": "python3 examples/chatbot.py"
8+
}
9+
]
10+
}

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ addopts = "--strict-markers"
9292
markers = [
9393
"slow: marks tests as slow (deselect with '-m \"not slow\"')",
9494
"lmstudio: marks tests as needing LM Studio (deselect with '-m \"not lmstudio\"')",
95-
"wip: marks tests as a work-in-progress (select with '-m \"wip\"')"
95+
"wip: marks tests as a work-in-progress (select with '-m \"wip\"')",
96+
"asyncio: marks tests as asyncio-based",
9697
]
9798
# Warnings should only be emitted when being specifically tested
9899
filterwarnings = [
@@ -102,7 +103,6 @@ filterwarnings = [
102103
log_format = "%(asctime)s %(levelname)s %(message)s"
103104
log_date_format = "%Y-%m-%d %H:%M:%S"
104105
# Each async test case gets a fresh event loop by default
105-
asyncio_default_fixture_loop_scope = "function"
106106

107107
[tool.coverage.run]
108108
relative_files = true

src/lmstudio/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
from .schemas import *
1818
from .history import *
1919
from .json_api import *
20+
from .json_api import (
21+
LMStudioPredictionError,
22+
LMStudioModelLoadError,
23+
LMStudioInputValidationError,
24+
LMStudioPredictionTimeoutError,
25+
LMStudioPredictionCancelledError,
26+
LMStudioPredictionRuntimeError,
27+
)
2028
from .async_api import *
2129
from .sync_api import *
2230

src/lmstudio/json_api.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,32 @@ def __init__(self, message: str) -> None:
418418
super().__init__(message, None)
419419

420420

421+
@sdk_public_type
422+
421423
@sdk_public_type
422424
class LMStudioPredictionError(LMStudioServerError):
423425
"""Problems reported by the LM Studio instance during a model prediction."""
424426

427+
@sdk_public_type
428+
class LMStudioModelLoadError(LMStudioPredictionError):
429+
"""Raised when a model fails to load for a prediction."""
430+
431+
@sdk_public_type
432+
class LMStudioInputValidationError(LMStudioPredictionError):
433+
"""Raised when input to a prediction is invalid (e.g., bad prompt, bad parameters)."""
434+
435+
@sdk_public_type
436+
class LMStudioPredictionTimeoutError(LMStudioPredictionError):
437+
"""Raised when a prediction times out before completion."""
438+
439+
@sdk_public_type
440+
class LMStudioPredictionCancelledError(LMStudioPredictionError):
441+
"""Raised when a prediction is cancelled before completion."""
442+
443+
@sdk_public_type
444+
class LMStudioPredictionRuntimeError(LMStudioPredictionError):
445+
"""Raised for unexpected runtime errors during prediction."""
446+
425447

426448
@sdk_public_type
427449
class LMStudioClientError(LMStudioError):

tests/async/test_embedding_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from lmstudio import AsyncClient, EmbeddingLoadModelConfig, LMStudioModelNotFoundError
1010

11-
from ..support import (
11+
from tests.support import (
1212
EXPECTED_EMBEDDING,
1313
EXPECTED_EMBEDDING_CONTEXT_LENGTH,
1414
EXPECTED_EMBEDDING_ID,

tests/async/test_images_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from lmstudio import AsyncClient, Chat, FileHandle, LMStudioServerError
1111

12-
from ..support import (
12+
from tests.support import (
1313
EXPECTED_VLM_ID,
1414
IMAGE_FILEPATH,
1515
SHORT_PREDICTION_CONFIG,

tests/async/test_inference_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
ToolCallRequest,
2929
)
3030

31-
from ..support import (
31+
from tests.support import (
3232
ADDITION_TOOL_SPEC,
3333
EXPECTED_LLM_ID,
3434
GBNF_GRAMMAR,

tests/async/test_llm_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
history,
1414
)
1515

16-
from ..support import EXPECTED_LLM, EXPECTED_LLM_ID, check_sdk_error
16+
from tests.support import EXPECTED_LLM, EXPECTED_LLM_ID, check_sdk_error
1717

1818

1919
@pytest.mark.asyncio

tests/async/test_model_catalog_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from lmstudio import AsyncClient, LMStudioModelNotFoundError, LMStudioServerError
1313
from lmstudio.json_api import DownloadedModelBase, ModelHandleBase
1414

15-
from ..support import (
15+
from tests.support import (
1616
LLM_LOAD_CONFIG,
1717
EXPECTED_LLM,
1818
EXPECTED_LLM_ID,

tests/async/test_model_handles_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from lmstudio import AsyncClient, PredictionResult
1414

15-
from ..support import (
15+
from tests.support import (
1616
EXPECTED_EMBEDDING,
1717
EXPECTED_EMBEDDING_ID,
1818
EXPECTED_EMBEDDING_LENGTH,

0 commit comments

Comments
 (0)