This repository was archived by the owner on Jul 16, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 1717use PhpLlm \LlmChain \Platform \Contract \Normalizer \ToolNormalizer ;
1818use PhpLlm \LlmChain \Platform \Tool \Tool ;
1919use Symfony \Component \Serializer \Normalizer \AbstractObjectNormalizer ;
20+ use Symfony \Component \Serializer \Normalizer \JsonSerializableNormalizer ;
2021use Symfony \Component \Serializer \Normalizer \NormalizerInterface ;
2122use Symfony \Component \Serializer \Serializer ;
2223
@@ -53,6 +54,9 @@ public static function create(NormalizerInterface ...$normalizer): self
5354 // Response
5455 $ normalizer [] = new ToolCallNormalizer ();
5556
57+ // Generally allow JsoNSerializable objects in the contract, as extension point
58+ $ normalizer [] = new JsonSerializableNormalizer ();
59+
5660 return new self (
5761 new Serializer ($ normalizer ),
5862 );
Original file line number Diff line number Diff line change 2424use PhpLlm \LlmChain \Platform \Message \Content \ImageUrl ;
2525use PhpLlm \LlmChain \Platform \Message \Message ;
2626use PhpLlm \LlmChain \Platform \Message \MessageBag ;
27+ use PhpLlm \LlmChain \Platform \Message \MessageInterface ;
28+ use PhpLlm \LlmChain \Platform \Message \Role ;
2729use PhpLlm \LlmChain \Platform \Message \SystemMessage ;
2830use PhpLlm \LlmChain \Platform \Message \UserMessage ;
2931use PhpLlm \LlmChain \Platform \Model ;
3335use PHPUnit \Framework \Attributes \Test ;
3436use PHPUnit \Framework \Attributes \UsesClass ;
3537use PHPUnit \Framework \TestCase ;
38+ use Symfony \Component \Uid \Uuid ;
3639
3740#[Large]
3841#[CoversClass(Contract::class)]
@@ -191,6 +194,37 @@ public static function providePayloadTestCases(): iterable
191194 'model ' => 'gpt-4o ' ,
192195 ],
193196 ];
197+
198+ $ customSerializableMessage = new class implements MessageInterface, \JsonSerializable {
199+ public function getRole (): Role
200+ {
201+ return Role::User;
202+ }
203+
204+ public function getId (): Uuid
205+ {
206+ return Uuid::v7 ();
207+ }
208+
209+ public function jsonSerialize (): array
210+ {
211+ return [
212+ 'role ' => 'user ' ,
213+ 'content ' => 'This is a custom serializable message. ' ,
214+ ];
215+ }
216+ };
217+
218+ yield 'MessageBag with custom message from GPT ' => [
219+ 'model ' => new GPT (),
220+ 'input ' => new MessageBag ($ customSerializableMessage ),
221+ 'expected ' => [
222+ 'messages ' => [
223+ ['role ' => 'user ' , 'content ' => 'This is a custom serializable message. ' ],
224+ ],
225+ 'model ' => 'gpt-4o ' ,
226+ ],
227+ ];
194228 }
195229
196230 #[Test]
You can’t perform that action at this time.
0 commit comments