File tree Expand file tree Collapse file tree 4 files changed +35
-2
lines changed
Expand file tree Collapse file tree 4 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -83,4 +83,17 @@ Prism::text()
8383 ->withPrompt('Solve the equation 3x + 10 = 14.')
8484 ->withProviderTools([new ProviderTool(type: 'code_interpreter', options: ['container' => ['type' => 'auto']])])
8585 ->asText();
86- ```
86+ ```
87+
88+ ### Additional Message Attributes
89+
90+ Adding optional parameters to a ` UserMessage ` like the ` name ` field can be done through the ` additionalAttributes ` parameter.
91+
92+ ``` php
93+ Prism::text()
94+ ->using('openai', 'gpt-4.1')
95+ ->withMessages([
96+ new UserMessage('Who are you?', additionalAttributes: ['name' => 'TJ']),
97+ ])
98+ ->asText()
99+ ```
Original file line number Diff line number Diff line change @@ -87,6 +87,7 @@ protected function mapUserMessage(UserMessage $message): void
8787 ...self ::mapDocumentParts ($ message ->documents ()),
8888 ...self ::mapFileParts ($ message ->files ()),
8989 ],
90+ ...$ message ->additionalAttributes ,
9091 ];
9192 }
9293
Original file line number Diff line number Diff line change @@ -17,10 +17,12 @@ class UserMessage implements Message
1717
1818 /**
1919 * @param array<int, Text|Image|Document|OpenAIFile> $additionalContent
20+ * @param array<string, mixed> $additionalAttributes
2021 */
2122 public function __construct (
2223 public readonly string $ content ,
23- public array $ additionalContent = []
24+ public array $ additionalContent = [],
25+ public readonly array $ additionalAttributes = [],
2426 ) {
2527 $ this ->additionalContent [] = new Text ($ content );
2628 }
Original file line number Diff line number Diff line change 3131 ]]);
3232});
3333
34+ it ('maps user messages with additional attributes ' , function (): void {
35+ $ messageMap = new MessageMap (
36+ messages: [
37+ new UserMessage ('Who are you? ' , additionalAttributes: ['name ' => 'TJ ' ]),
38+ ],
39+ systemPrompts: []
40+ );
41+
42+ expect ($ messageMap ())->toBe ([[
43+ 'role ' => 'user ' ,
44+ 'content ' => [
45+ ['type ' => 'input_text ' , 'text ' => 'Who are you? ' ],
46+ ],
47+ 'name ' => 'TJ ' ,
48+ ]]);
49+ });
50+
3451it ('maps user messages with images from path ' , function (): void {
3552 $ messageMap = new MessageMap (
3653 messages: [
You can’t perform that action at this time.
0 commit comments