Skip to content

Commit 3a813b7

Browse files
authored
feat: add chain wrapper tool (#266)
1 parent 6365947 commit 3a813b7

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/Chain/Toolbox/Tool/Chain.php

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpLlm\LlmChain\Chain\Toolbox\Tool;
6+
7+
use PhpLlm\LlmChain\ChainInterface;
8+
use PhpLlm\LlmChain\Model\Message\Message;
9+
use PhpLlm\LlmChain\Model\Message\MessageBag;
10+
use PhpLlm\LlmChain\Model\Response\TextResponse;
11+
12+
final readonly class Chain
13+
{
14+
public function __construct(
15+
private ChainInterface $chain,
16+
) {
17+
}
18+
19+
/**
20+
* @param string $message the message to pass to the chain
21+
*/
22+
public function __invoke(string $message): string
23+
{
24+
$response = $this->chain->call(new MessageBag(Message::ofUser($message)));
25+
26+
assert($response instanceof TextResponse);
27+
28+
return $response->getContent();
29+
}
30+
}

0 commit comments

Comments
 (0)