-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4adb1a2
commit fc8db39
Showing
16 changed files
with
169 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpLlm\LlmChain\Chain\ToolBox\Event; | ||
|
||
use PhpLlm\LlmChain\Chain\ToolBox\ToolCallResult; | ||
use PhpLlm\LlmChain\Model\Response\ResponseInterface; | ||
|
||
final class ToolCallsExecuted | ||
{ | ||
/** | ||
* @var ToolCallResult[] | ||
*/ | ||
public readonly array $toolCallResults; | ||
public ResponseInterface $response; | ||
|
||
public function __construct(ToolCallResult ...$toolCallResults) | ||
{ | ||
$this->toolCallResults = $toolCallResults; | ||
} | ||
|
||
public function hasResponse(): bool | ||
{ | ||
return isset($this->response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpLlm\LlmChain\Chain\ToolBox; | ||
|
||
use PhpLlm\LlmChain\Model\Response\ToolCall; | ||
|
||
final readonly class ToolCallResult | ||
{ | ||
public function __construct( | ||
public ToolCall $toolCall, | ||
public mixed $result, | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpLlm\LlmChain\Chain\ToolBox; | ||
|
||
final readonly class ToolResultConverter | ||
{ | ||
public function convert(mixed $result): string | ||
{ | ||
if ($result instanceof \JsonSerializable || is_array($result)) { | ||
return json_encode($result, flags: JSON_THROW_ON_ERROR); | ||
} | ||
|
||
if (is_integer($result) || is_float($result) || $result instanceof \Stringable) { | ||
return (string) $result; | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpLlm\LlmChain\Tests\Chain\ToolBox; | ||
|
||
use PhpLlm\LlmChain\Chain\ToolBox\ToolResultConverter; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[CoversClass(ToolResultConverter::class)] | ||
final class ToolResultConverterTest extends TestCase | ||
{ | ||
#[Test] | ||
#[DataProvider('provideResults')] | ||
public function testConvert(mixed $result, string $expected): void | ||
{ | ||
$converter = new ToolResultConverter(); | ||
|
||
self::assertSame($expected, $converter->convert($result)); | ||
} | ||
|
||
public static function provideResults(): \Generator | ||
{ | ||
yield 'integer' => [42, '42']; | ||
|
||
yield 'float' => [42.42, '42.42']; | ||
|
||
yield 'array' => [['key' => 'value'], '{"key":"value"}']; | ||
|
||
yield 'string' => ['plain string', 'plain string']; | ||
|
||
yield 'stringable' => [ | ||
new class implements \Stringable { | ||
public function __toString(): string | ||
{ | ||
return 'stringable'; | ||
} | ||
}, | ||
'stringable', | ||
]; | ||
|
||
yield 'json_serializable' => [ | ||
new class implements \JsonSerializable { | ||
public function jsonSerialize(): array | ||
{ | ||
return ['key' => 'value']; | ||
} | ||
}, | ||
'{"key":"value"}', | ||
]; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.