Skip to content

Commit cd5a16b

Browse files
committed
Deepseek privider
1 parent 72dae4d commit cd5a16b

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

src/Agent.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ public function chat(Message|array $messages): Message
110110
$this->notify('tool-called', new ToolCalled($tool));
111111
}
112112

113-
$response = $this->chat($toolCallResult);
113+
$response = $this->chat([
114+
$response, $toolCallResult
115+
]);
114116
}
115117

116118
$this->notify('message-saving', new MessageSaving($response));

src/Chat/Messages/Message.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ class Message implements \JsonSerializable
1313
protected array $meta = [];
1414

1515
public function __construct(
16-
protected ?string $role = null,
16+
protected string $role,
1717
protected array|string|int|float|null $content = null
1818
) {}
1919

20-
public function getRole(): ?string
20+
public function getRole(): string
2121
{
2222
return $this->role;
2323
}

src/Chat/Messages/ToolCallResultMessage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace NeuronAI\Chat\Messages;
44

5-
class ToolCallResultMessage extends Message
5+
class ToolCallResultMessage extends UserMessage
66
{
77
public function __construct(protected array $tools)
88
{
9-
parent::__construct();
9+
parent::__construct(null);
1010
}
1111

1212
public function getTools(): array

src/Providers/Anthropic/MessageMapper.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use NeuronAI\Chat\Messages\Message;
66
use NeuronAI\Chat\Messages\ToolCallMessage;
7+
use NeuronAI\Chat\Messages\ToolCallResultMessage;
78
use NeuronAI\Tools\ToolInterface;
89

910
class MessageMapper
@@ -23,10 +24,10 @@ public function __construct(protected array $messages) {}
2324
public function map(): array
2425
{
2526
foreach ($this->messages as $message) {
26-
$this->mapping[] = $message->jsonSerialize();
27-
28-
if ($message instanceof ToolCallMessage) {
27+
if ($message instanceof ToolCallResultMessage) {
2928
$this->addToolsResult($message->getTools());
29+
} else {
30+
$this->mapping[] = $message->jsonSerialize();
3031
}
3132
}
3233

src/Providers/OpenAI/MessageMapper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public function __construct(protected array $messages) {}
2323
public function map(): array
2424
{
2525
foreach ($this->messages as $message) {
26-
$this->mapping[] = $message->jsonSerialize();
27-
2826
if ($message instanceof ToolCallResultMessage) {
2927
$this->addToolsResult($message->getTools());
28+
} else {
29+
$this->mapping[] = $message->jsonSerialize();
3030
}
3131
}
3232

@@ -37,7 +37,7 @@ public function addToolsResult(array $tools): void
3737
{
3838
foreach ($tools as $tool) {
3939
$this->mapping[] = [
40-
'role' => 'tool',
40+
'role' => Message::ROLE_TOOL,
4141
'tool_call_id' => $tool->getCallId(),
4242
'content' => $tool->getResult()
4343
];

0 commit comments

Comments
 (0)