Handle non-list LangServe /invoke output in langchain_serve generator#1916
Open
WatchTree-19 wants to merge 1 commit into
Open
Handle non-list LangServe /invoke output in langchain_serve generator#1916WatchTree-19 wants to merge 1 commit into
WatchTree-19 wants to merge 1 commit into
Conversation
LangServe returns the runnable output directly under `output` (a string for LLM chains, a serialised message dict for chat models), not wrapped in a list. The generator indexed `output[0]`, so a string response was truncated to its first character and a chat-model dict response was silently dropped ([None]). Handle the output by type: string directly, dict via its content, list via its first element (backward compatible). Add tests for the string and dict shapes. Fixes NVIDIA#1915 Signed-off-by: WatchTree-19 <119982314+WatchTree-19@users.noreply.github.com>
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.
Description
LangChainServeLLMGenerator._call_modeldidMessage(response_data.get("output")[0]), assuming LangServe's/invokewraps the output in a list. LangServe returns the runnable's output directly underoutput:{"output": "the text", ...}->output[0]returns only"t"(first character){"output": {"content": "...", "type": "ai"}}->output[0]raisesKeyError, caught, so the response is silently dropped ([None])Only a
{"output": ["..."]}shape worked, which LangServe doesn't emit; the existing test used that fabricated shape so the bug went unnoticed.Now handles the output by type: a string directly, a dict via its
content, a list via its first element (backward compatible), guarding empty/None.Fixes #1915.
Type of change
Verification
Added
test_langchain_serve_string_outputandtest_langchain_serve_message_dict_output(real LangServe shapes); the existing list-shape test still passes.tests/generators/test_langchain_serve.pypasses (7). ruff clean on the changed lines (the two== True/Falsewarnings are pre-existing intest_validate_uri).