Skip to content

Commit 52002b0

Browse files
committed
fix providers
1 parent b7baa02 commit 52002b0

File tree

8 files changed

+69
-12
lines changed

8 files changed

+69
-12
lines changed

src/Agent.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
namespace NeuronAI;
44

5+
use NeuronAI\Events\MessageSending;
6+
use NeuronAI\Events\MessageSent;
7+
use NeuronAI\Events\ToolCalled;
8+
use NeuronAI\Events\ToolCalling;
59
use NeuronAI\Exceptions\InvalidMessageInstance;
610
use NeuronAI\Exceptions\MissingCallbackParameter;
711
use NeuronAI\Exceptions\ToolCallableNotSet;
@@ -90,7 +94,12 @@ public function run(?Message $message = null): Message
9094
$this->resolveChatHistory()->addMessage($message);
9195
}
9296

93-
$this->notify('message:sending', $this->resolveChatHistory()->getLastMessage());
97+
$this->notify(
98+
'message:sending',
99+
new MessageSending(
100+
$this->resolveChatHistory()->getLastMessage()
101+
)
102+
);
94103

95104
$response = $this->provider()
96105
->systemPrompt($this->instructions())
@@ -99,17 +108,19 @@ public function run(?Message $message = null): Message
99108
$this->resolveChatHistory()->toArray()
100109
);
101110

102-
$this->notify('message:sent', [
103-
'response' => $response,
104-
'message' => $this->resolveChatHistory()->getLastMessage()
105-
]);
111+
$this->notify(
112+
'message:sent',
113+
new MessageSent(
114+
$this->resolveChatHistory()->getLastMessage(),
115+
$response
116+
)
117+
);
106118

107119
if ($response instanceof ToolCallMessage) {
108-
$this->notify('tool:calling', $response);
120+
$this->notify('tool:calling', new ToolCalling($response));
109121
$toolResult = $response->getTool()->execute($response->getInputs());
110-
$this->notify('tool:called', $toolResult);
122+
$this->notify('tool:called', new ToolCalled($response, $toolResult));
111123

112-
// Execute the tool and submit the response to the LLM again.
113124
$this->run(new UserMessage($toolResult));
114125
}
115126

src/Events/MessageSending.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace NeuronAI\Events;
4+
5+
use NeuronAI\Messages\AbstractMessage;
6+
7+
class MessageSending
8+
{
9+
public function __construct(public AbstractMessage $message) {}
10+
}

src/Events/MessageSent.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace NeuronAI\Events;
4+
5+
use NeuronAI\Messages\AbstractMessage;
6+
7+
class MessageSent
8+
{
9+
public function __construct(
10+
public AbstractMessage $message,
11+
public AbstractMessage $response
12+
) {}
13+
}

src/Events/ToolCalled.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace NeuronAI\Events;
4+
5+
use NeuronAI\Tools\ToolCallMessage;
6+
7+
class ToolCalled
8+
{
9+
public function __construct(
10+
public ToolCallMessage $toolCall,
11+
public mixed $result
12+
) {}
13+
}

src/Events/ToolCalling.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace NeuronAI\Events;
4+
5+
use NeuronAI\Tools\ToolCallMessage;
6+
7+
class ToolCalling
8+
{
9+
public function __construct(public ToolCallMessage $toolCall) {}
10+
}

src/Providers/Anthropic.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Anthropic implements AIProviderInterface
3535
*
3636
* @var array<Tool>
3737
*/
38-
protected array $tools;
38+
protected array $tools = [];
3939

4040
/**
4141
* AnthropicClaude constructor.
@@ -94,7 +94,7 @@ public function chat(array|string $prompt): Message
9494
}
9595

9696
// https://docs.anthropic.com/claude/reference/messages_post
97-
$result = $this->client->post('/messages', compact('json'))
97+
$result = $this->client->post('messages', compact('json'))
9898
->getBody()->getContents();
9999

100100
$result = \json_decode($result, true);

src/Providers/Mistral.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function chat(array|string $prompt): Message
5959
\array_unshift($prompt, new AssistantMessage($this->system));
6060
}
6161

62-
$result = $this->client->post('/chat/completions', [
62+
$result = $this->client->post('chat/completions', [
6363
RequestOptions::JSON => [
6464
'model' => $this->model,
6565
'messages' => $prompt,

src/Providers/OpenAI.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function chat(array|string $prompt): Message
5959
\array_unshift($prompt, new AssistantMessage($this->system));
6060
}
6161

62-
$result = $this->client->post('/chat/completions', [
62+
$result = $this->client->post('chat/completions', [
6363
RequestOptions::JSON => [
6464
'model' => $this->model,
6565
'messages' => $prompt,

0 commit comments

Comments
 (0)