refactor(adapter): simplify base adapter flow - #64
Draft
isaacbmiller wants to merge 1 commit into
Draft
Conversation
isaacbmiller
force-pushed
the
reviewable/adapter-simplify-02-base-flow
branch
from
May 27, 2026 05:28
c6f76a0 to
c45be69
Compare
isaacbmiller
force-pushed
the
reviewable/adapter-simplify-01-type-bridges
branch
from
May 27, 2026 05:28
1d4c395 to
188e60a
Compare
isaacbmiller
force-pushed
the
reviewable/adapter-simplify-02-base-flow
branch
from
May 27, 2026 05:44
c45be69 to
d479da7
Compare
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
This is PR 2 of 2 in the adapter simplification stack. It sits on top of #63.
This PR simplifies
dspy/adapters/base.pynow that PR 1 gives native response types a normalizedLMOutputparse hook. The adapter still builds anLMRequestinternally, but it does not changedspy.LM,BaseLM, or the provider/client boundary.Key changes:
BaseLMboundary by converting the internalLMRequestback to legacy OpenAI-shaped kwargs inside the adapter edge.LMResponse/LMOutputvalues directly instead of converting back through legacy postprocess dictionaries.ToolCallsoutput filling, native response types,logprobs, and empty-output handling.Type.format()content blocks.Why This Belongs After #63
The base adapter can only parse
LMResponsedirectly once custom/native response fields know how to read normalized output parts. #63 adds that output hook and the small history/type bridge; this PR then uses it to remove the bulk of the internal legacy parsing path.Review Notes
This deliberately avoids the LM/client files. The adapter builds
LMRequestbecause that is the internal shape we want to move toward, but the call into currentBaseLMremains:LMRequestfrom adapter-rendered messages.to_openai_chat_request(...)at the adapter edge.lm(messages=..., **kwargs)/lm.acall(...).LMResponsefor adapter parsing.That leaves the future deletion path clear: when
BaseLMaccepts/returns normalized request/response objects, remove the adapter-local_legacy_call_kwargs(...)and legacy-output normalization call.Validation
uv run --frozen ruff check dspy/adapters/base.py dspy/adapters/types/base_type.py dspy/adapters/types/citation.py dspy/adapters/types/reasoning.py dspy/core/types.pyuv run --frozen pytest --deno -q tests/core/test_types.py tests/streaming/test_streaming.py::test_streaming_allows_custom_streamable_type tests/adapters tests/signatures/test_adapter_file.py279 passed, 14 warningsuv run --frozen pytest --deno -q tests1046 passed, 233 skipped, 2 xfailed, 50 warnings