@@ -50,42 +50,39 @@ public function convertMessage(UserMessage|SystemMessage|AssistantMessage $messa
50
50
ASSISTANT );
51
51
}
52
52
53
- if ($ message instanceof UserMessage) {
54
- $ count = count ($ message ->content );
55
-
56
- $ contentParts = [];
57
- if ($ count > 1 ) {
58
- foreach ($ message ->content as $ value ) {
59
- if ($ value instanceof Text) {
60
- $ contentParts [] = $ value ->text ;
61
- }
62
-
63
- if ($ value instanceof Image) {
64
- $ contentParts [] = $ value ->url ;
65
- }
66
- }
67
- } elseif (1 === $ count ) {
68
- $ value = $ message ->content [0 ];
53
+ // Handling of UserMessage
54
+ $ count = count ($ message ->content );
55
+
56
+ $ contentParts = [];
57
+ if ($ count > 1 ) {
58
+ foreach ($ message ->content as $ value ) {
69
59
if ($ value instanceof Text) {
70
60
$ contentParts [] = $ value ->text ;
71
61
}
72
62
73
63
if ($ value instanceof Image) {
74
64
$ contentParts [] = $ value ->url ;
75
65
}
76
- } else {
77
- throw new RuntimeException ('Unsupported message type. ' );
66
+ }
67
+ } elseif (1 === $ count ) {
68
+ $ value = $ message ->content [0 ];
69
+ if ($ value instanceof Text) {
70
+ $ contentParts [] = $ value ->text ;
78
71
}
79
72
80
- $ content = implode (PHP_EOL , $ contentParts );
73
+ if ($ value instanceof Image) {
74
+ $ contentParts [] = $ value ->url ;
75
+ }
76
+ } else {
77
+ throw new RuntimeException ('Unsupported message type. ' );
78
+ }
81
79
82
- return trim (<<<USER
83
- <|start_header_id|> {$ message ->getRole ()->value }<|end_header_id|>
80
+ $ content = implode (PHP_EOL , $ contentParts );
84
81
85
- {$ content }<|eot_id|>
86
- USER );
87
- }
82
+ return trim (<<<USER
83
+ <|start_header_id|> {$ message ->getRole ()->value }<|end_header_id|>
88
84
89
- throw new RuntimeException ('Unsupported message type. ' ); // @phpstan-ignore-line
85
+ {$ content }<|eot_id|>
86
+ USER );
90
87
}
91
88
}
0 commit comments