-
Notifications
You must be signed in to change notification settings - Fork 22
feat: add ResponseContract handling [by Claude Code] #338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
3622f44
to
239ed8a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a unified ResponseContract
system to replace redundant per-platform response converters, streamlining response parsing and conversion across LLM platforms.
- Adds
ResponseContract
andResponseContractFactory
to centralize denormalization logic. - Updates OpenAI and Mistral factories to use
ResponseContract
instead of separate converters. - Provides extensive DTOs and denormalizers with full test coverage for parsing, streaming, and tool-call handling.
Reviewed Changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
src/Platform/ResponseContract.php | Core coordinator and factory for denormalizers |
src/Platform/ResponseContractFactory.php | Stateful adapter implementing ResponseConverterInterface |
src/Platform/Bridge/OpenAI/PlatformFactory.php | Switched to ResponseContract -based converter for OpenAI |
src/Platform/Bridge/Mistral/PlatformFactory.php | Switched to ResponseContract -based converter for Mistral |
tests/Platform/ResponseContractTest.php | Coverage for simple text, tool calls, and non-streaming responses |
tests/Platform/Bridge/** | New parser/stream tests for OpenAI and Mistral response formats |
Comments suppressed due to low confidence (1)
tests/Platform/ResponseContractTest.php:60
- Consider adding a dedicated test for multi-choice responses (i.e., when
choices
contains more than one element) to cover theChoiceResponse
path inTextResponseDenormalizer
.
public function testConvertResponseSimpleText(): void
src/Platform/ResponseContract.php
Outdated
public static function create(DenormalizerInterface ...$denormalizers): self | ||
{ | ||
return new self( | ||
new ResponseDenormalizer(...$denormalizers), | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static methods go directly after the constructor
public function supportsModel(Model $model): bool | ||
{ | ||
// Check if any denormalizer supports this model by testing denormalization | ||
$context = [self::CONTEXT_MODEL => $model]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this variable is not needed - just add the array directly to the supportsDenormalization
method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, a few things here:
- let's not duplicate DTOs like
ToolCall
andParsedToolCall
but use the same - meaning the already existingPhpLlm\LlmChain\Platform\Response\ToolCall
class - same for others. - Let's get rid off the
ResponseConverterInterface
now and the corresponding code in the bridge classes
239ed8a
to
af06a40
Compare
I guess my prompt in the beginning send Claude into introducing new DTOs and should have been more explicit about DTO usage, adding and running tests. |
35ec6ac
to
164dba4
Compare
164dba4
to
dbbc502
Compare
alrighty, fun but trash. |
Input: