Repository navigation
Conversation
gen(stop="...") builds a LiteralNode for the stop condition, but the sglang and litellm rule() methods read node.stop.regex, which only exists on the RegexNode built by gen(stop_regex=...). Any string stop raised AttributeError before a request could be built. Read .value for LiteralNode stops and keep sending .regex for stop_regex, preserving the xai list-wrapping behavior.
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
gen(stop="...")crashed withAttributeError: 'LiteralNode' object has no attribute 'regex'on the experimentalSglangModelandLiteLLMadapters, before any request could be built. Resolve the stop text by node type so a string stop is sent as thestoprequest parameter, whilestop_regexkeeps sending the regex as before.Fixes #1542
Why
For a string stop,
gen()buildsRuleNode.stop = LiteralNode(stop)and onlystop_regexbuilds aRegexNode(guidance/_grammar.py:41-45).LiteralNodestores its text in.value(guidance/_ast.py:317-318) and has no.regexattribute, but both adapters'rule()implementations readnode.stop.regexunconditionally:guidance/models/experimental/_sglang.py:44guidance/models/experimental/_litellm.py:124(xai branch:isinstance(node.stop.regex, str))guidance/models/experimental/_litellm.py:127(else branch)String
stopis a first-classgen()parameter, and both adapters explicitly claim stop support ("Disable this check for now as all the supported endpoints have 'stop' support",_sglang.py:32,_litellm.py:110-112), so the adapters should send it rather than crash.Changes
guidance/models/experimental/_sglang.py: readnode.stop.valuewhen the stop is aLiteralNode, keepingnode.stop.regexforRegexNode(thestop_regexpath).guidance/models/experimental/_litellm.py: same resolution, preserving the existing xai behavior of wrapping a string stop in a list.tests/unit/test_experimental_adapters.py: new tests that stub the client packages (no network) and assert thestopvalue sent in the request for bothstopandstop_regex, across the sglang adapter and the litellmopenai/hosted_vllm/xaiendpoint types.Testing
pytest tests/unit/test_experimental_adapters.py→4 failed, 3 passed, withAttributeError: 'LiteralNode' object has no attribute 'regex'atguidance/models/experimental/_sglang.py:44andguidance/models/experimental/_litellm.py:124/127.pytest tests/unit/test_experimental_adapters.py→7 passed.pytest ./tests/unit→1644 passed, 1 skipped, 220 xfailed.ruff format --check→151 files already formatted;ruff check --select I,RUF022→All checks passed!;ruff check→All checks passed!.