File tree Expand file tree Collapse file tree 5 files changed +14
-11
lines changed Expand file tree Collapse file tree 5 files changed +14
-11
lines changed Original file line number Diff line number Diff line change @@ -110,7 +110,9 @@ public function chat(Message|array $messages): Message
110
110
$ this ->notify ('tool-called ' , new ToolCalled ($ tool ));
111
111
}
112
112
113
- $ response = $ this ->chat ($ toolCallResult );
113
+ $ response = $ this ->chat ([
114
+ $ response , $ toolCallResult
115
+ ]);
114
116
}
115
117
116
118
$ this ->notify ('message-saving ' , new MessageSaving ($ response ));
Original file line number Diff line number Diff line change @@ -13,11 +13,11 @@ class Message implements \JsonSerializable
13
13
protected array $ meta = [];
14
14
15
15
public function __construct (
16
- protected ? string $ role = null ,
16
+ protected string $ role ,
17
17
protected array |string |int |float |null $ content = null
18
18
) {}
19
19
20
- public function getRole (): ? string
20
+ public function getRole (): string
21
21
{
22
22
return $ this ->role ;
23
23
}
Original file line number Diff line number Diff line change 2
2
3
3
namespace NeuronAI \Chat \Messages ;
4
4
5
- class ToolCallResultMessage extends Message
5
+ class ToolCallResultMessage extends UserMessage
6
6
{
7
7
public function __construct (protected array $ tools )
8
8
{
9
- parent ::__construct ();
9
+ parent ::__construct (null );
10
10
}
11
11
12
12
public function getTools (): array
Original file line number Diff line number Diff line change 4
4
5
5
use NeuronAI \Chat \Messages \Message ;
6
6
use NeuronAI \Chat \Messages \ToolCallMessage ;
7
+ use NeuronAI \Chat \Messages \ToolCallResultMessage ;
7
8
use NeuronAI \Tools \ToolInterface ;
8
9
9
10
class MessageMapper
@@ -23,10 +24,10 @@ public function __construct(protected array $messages) {}
23
24
public function map (): array
24
25
{
25
26
foreach ($ this ->messages as $ message ) {
26
- $ this ->mapping [] = $ message ->jsonSerialize ();
27
-
28
- if ($ message instanceof ToolCallMessage) {
27
+ if ($ message instanceof ToolCallResultMessage) {
29
28
$ this ->addToolsResult ($ message ->getTools ());
29
+ } else {
30
+ $ this ->mapping [] = $ message ->jsonSerialize ();
30
31
}
31
32
}
32
33
Original file line number Diff line number Diff line change @@ -23,10 +23,10 @@ public function __construct(protected array $messages) {}
23
23
public function map (): array
24
24
{
25
25
foreach ($ this ->messages as $ message ) {
26
- $ this ->mapping [] = $ message ->jsonSerialize ();
27
-
28
26
if ($ message instanceof ToolCallResultMessage) {
29
27
$ this ->addToolsResult ($ message ->getTools ());
28
+ } else {
29
+ $ this ->mapping [] = $ message ->jsonSerialize ();
30
30
}
31
31
}
32
32
@@ -37,7 +37,7 @@ public function addToolsResult(array $tools): void
37
37
{
38
38
foreach ($ tools as $ tool ) {
39
39
$ this ->mapping [] = [
40
- 'role ' => ' tool ' ,
40
+ 'role ' => Message:: ROLE_TOOL ,
41
41
'tool_call_id ' => $ tool ->getCallId (),
42
42
'content ' => $ tool ->getResult ()
43
43
];
You can’t perform that action at this time.
0 commit comments