Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

Commit 987c3c0

Browse files
committed
fix: usage of Claude without system prompt
1 parent 375a11f commit 987c3c0

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

examples/toolbox-wikipedia.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

3-
use PhpLlm\LlmChain\Bridge\OpenAI\GPT;
4-
use PhpLlm\LlmChain\Bridge\OpenAI\PlatformFactory;
3+
use PhpLlm\LlmChain\Bridge\Anthropic\Claude;
4+
use PhpLlm\LlmChain\Bridge\Anthropic\PlatformFactory;
55
use PhpLlm\LlmChain\Chain;
66
use PhpLlm\LlmChain\Chain\Toolbox\ChainProcessor;
77
use PhpLlm\LlmChain\Chain\Toolbox\Tool\Wikipedia;
@@ -14,13 +14,13 @@
1414
require_once dirname(__DIR__).'/vendor/autoload.php';
1515
(new Dotenv())->loadEnv(dirname(__DIR__).'/.env');
1616

17-
if (empty($_ENV['OPENAI_API_KEY'])) {
18-
echo 'Please set the OPENAI_API_KEY environment variable.'.PHP_EOL;
17+
if (empty($_ENV['ANTHROPIC_API_KEY'])) {
18+
echo 'Please set the ANTHROPIC_API_KEY environment variable.'.PHP_EOL;
1919
exit(1);
2020
}
2121

22-
$platform = PlatformFactory::create($_ENV['OPENAI_API_KEY']);
23-
$llm = new GPT(GPT::GPT_4O_MINI);
22+
$platform = PlatformFactory::create($_ENV['ANTHROPIC_API_KEY']);
23+
$llm = new Claude();
2424

2525
$wikipedia = new Wikipedia(HttpClient::create());
2626
$toolbox = Toolbox::create($wikipedia);

src/Bridge/Anthropic/ModelHandler.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,10 @@ public function request(Model $model, object|array|string $input, array $options
6161
$options['tool_choice'] = ['type' => 'auto'];
6262
}
6363

64-
$system = $input->getSystemMessage();
65-
$body = array_merge($options, [
64+
$body = [
6665
'model' => $model->getVersion(),
67-
'system' => $system->content,
6866
'messages' => $input->withoutSystemMessage()->jsonSerialize(),
69-
]);
67+
];
7068

7169
$body['messages'] = array_map(static function (MessageInterface $message) {
7270
if ($message instanceof ToolCallMessage) {
@@ -98,12 +96,16 @@ public function request(Model $model, object|array|string $input, array $options
9896
return $message;
9997
}, $body['messages']);
10098

99+
if ($system = $input->getSystemMessage()) {
100+
$body['system'] = $system->content;
101+
}
102+
101103
return $this->httpClient->request('POST', 'https://api.anthropic.com/v1/messages', [
102104
'headers' => [
103105
'x-api-key' => $this->apiKey,
104106
'anthropic-version' => $this->version,
105107
],
106-
'json' => $body,
108+
'json' => array_merge($options, $body),
107109
]);
108110
}
109111

0 commit comments

Comments
 (0)