Skip to content

Commit 05b80b7

Browse files
committed
Minor cleanups
1 parent 2855b71 commit 05b80b7

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

src/lmstudio/plugin/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# * [DONE] refactor hook registration to be data driven instead of hardcoded in the runner
1616
# * refactor to allow "Abort" request handling to be common across hook invocation tasks
1717
# * refactor to allow hook invocation error handling to be common across hook invocation tasks
18-
# * gracefully handle app termination while a dev plugin is still running (handle "None" on rx_stream)
18+
# * [DONE] gracefully handle app termination while a dev plugin is still running
1919
# * [DONE] gracefully handle using Ctrl-C to terminate a running dev plugin
2020
#
2121
# Controller APIs (may be limited to relevant hook controllers)

src/lmstudio/plugin/hooks/prompt_preprocessor.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""Invoking and supporting prompt preprocessor hook implementations."""
22

3-
import asyncio
4-
53
from traceback import format_tb
64

75
from typing import (
@@ -23,7 +21,6 @@
2321
ChannelEndpoint,
2422
ChannelFinishedEvent,
2523
ChannelRxEvent,
26-
LMStudioChannelClosedError,
2724
load_struct,
2825
)
2926
from ..._sdk_models import (
@@ -74,7 +71,7 @@ class PromptPreprocessingRequestEvent(ChannelRxEvent[PromptPreprocessingRequest]
7471
class PromptPreprocessingEndpoint(
7572
ChannelEndpoint[tuple[str, str], PromptPreprocessingRxEvent, EmptyDict]
7673
):
77-
"""API channel endpoint to register a development plugin and receive credentials."""
74+
"""API channel endpoint to accept prompt preprocessing requests."""
7875

7976
_API_ENDPOINT = "setPromptPreprocessor"
8077
_NOTICE_PREFIX = "Prompt preprocessing"
@@ -87,9 +84,8 @@ def iter_message_events(
8784
) -> Iterable[PromptPreprocessingRxEvent]:
8885
match contents:
8986
case None:
90-
raise LMStudioChannelClosedError(
91-
"Server failed to complete development plugin registration."
92-
)
87+
# Server can only terminate the link by closing the websocket
88+
pass
9389
case {"type": "abort", "task_id": str(task_id)}:
9490
yield PromptPreprocessingAbortEvent(task_id)
9591
case {"type": "preprocess"} as request_dict:
@@ -217,14 +213,10 @@ async def _invoke_hook(request: PromptPreprocessingRequest) -> None:
217213
response_dict: UserMessageDict
218214
try:
219215
response = await hook_impl(hook_controller, message)
220-
except asyncio.CancelledError:
221-
# Cancellation is a regular exception, so explicitly
222-
# reraise it to avoid blocking Ctrl-C processing
223-
raise
224216
except Exception as exc:
225217
err_msg = "Error calling prompt preprocessing hook"
226218
logger.error(err_msg, exc_info=True, exc=repr(exc))
227-
# TODO: Determine if it's practical to emit a stack trace the server can display
219+
# TODO: Determine if it's worth sending the stack trace to the server
228220
ui_cause = f"{err_msg}\n({type(exc).__name__}: {exc})"
229221
error_details = SerializedLMSExtendedErrorDict(
230222
cause=ui_cause, stack="\n".join(format_tb(exc.__traceback__))

0 commit comments

Comments
 (0)