Repository navigation
Conversation
`format_chat_model_input` only lifted a system message when it was the first message in the chat, and raised `ValueError: Unsupported role: system` for a system message in any other position. An empty-string system message was also silently dropped. Add system messages at the position they appear in, via the SDK's `Chat.add_system_prompt`. Consecutive system messages are joined, as the `lmstudio` SDK does not support multiple consecutive system prompts.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LMStudioTypeAdapter.format_chat_model_inputraisedValueError: Unsupported role: systemfor any system message that was not the first message of the chat, including chats that contain a second system message. A system message in first position with an empty-string content was silently dropped instead of being passed along.Why
The
Chatinput documents that each message's role "can be 'user', 'assistant', or 'system'" with no positional constraint (src/outlines/inputs.py:82). The Gemini adapter already follows that contract: it collects system messages regardless of their position and joins them (src/outlines/models/gemini.py:87-95, introduced in #1967).The LMStudio adapter instead only lifted a system message when it was the first message, and built the chat with
LMSChat(system_prompt) if system_prompt else LMSChat(). Any other system message fell through to the role check and raisedValueError: Unsupported role: system(src/outlines/models/lmstudio.py:122onmain). Theif system_prompttest also treated an empty-string system message as absent.Changes
src/outlines/models/lmstudio.py:format_chat_model_inputnow adds each system message at the position it appears in, via the SDK'sChat.add_system_prompt. Consecutive system messages are joined with"\n", becauselmstudio1.5.0 raisesLMStudioRuntimeError: Multi-part or consecutive system prompts are not supported.when two system prompts are added back to back. An empty-string system message is preserved rather than dropped.tests/models/test_lmstudio_type_adapter.py: regression tests for a system message in the middle of the chat, consecutive system messages, an empty-string system message, and a trailing system message.Testing
Run locally on Python 3.12 with
lmstudio1.5.0:Checklist:
maincommit;pre-commitis installed and configured on your machine, and you ran it before opening the PR;