-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle
int
, float
, array
, \Stringable
and \JsonSerializable
…
… return values from tools (#161)
- Loading branch information
1 parent
75e1263
commit 8365e13
Showing
7 changed files
with
197 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpLlm\LlmChain\Tests\Fixture\Tool; | ||
|
||
use PhpLlm\LlmChain\Chain\ToolBox\Attribute\AsTool; | ||
|
||
#[AsTool('tool_returning_array', 'A tool returning an array')] | ||
final class ToolReturningArray | ||
{ | ||
public function __invoke(): array | ||
{ | ||
return ['foo' => 'bar']; | ||
} | ||
} |
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\Tests\Fixture\Tool; | ||
|
||
use PhpLlm\LlmChain\Chain\ToolBox\Attribute\AsTool; | ||
|
||
#[AsTool('tool_returning_float', 'A tool returning a float')] | ||
final class ToolReturningFloat | ||
{ | ||
public function __invoke(): float | ||
{ | ||
return 42.42; | ||
} | ||
} |
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\Tests\Fixture\Tool; | ||
|
||
use PhpLlm\LlmChain\Chain\ToolBox\Attribute\AsTool; | ||
|
||
#[AsTool('tool_returning_integer', 'A tool returning an integer')] | ||
final class ToolReturningInteger | ||
{ | ||
public function __invoke(): int | ||
{ | ||
return 42; | ||
} | ||
} |
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\Tests\Fixture\Tool; | ||
|
||
use PhpLlm\LlmChain\Chain\ToolBox\Attribute\AsTool; | ||
|
||
#[AsTool('tool_returning_json_serializable', 'A tool returning an object which implements \JsonSerializable')] | ||
final class ToolReturningJsonSerializable | ||
{ | ||
public function __invoke(): \JsonSerializable | ||
{ | ||
return new class implements \JsonSerializable { | ||
public function jsonSerialize(): array | ||
{ | ||
return ['foo' => 'bar']; | ||
} | ||
}; | ||
} | ||
} |
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\Tests\Fixture\Tool; | ||
|
||
use PhpLlm\LlmChain\Chain\ToolBox\Attribute\AsTool; | ||
|
||
#[AsTool('tool_returning_stringable', 'A tool returning an object which implements \Stringable')] | ||
final class ToolReturningStringable | ||
{ | ||
public function __invoke(): \Stringable | ||
{ | ||
return new class implements \Stringable { | ||
public function __toString(): string | ||
{ | ||
return 'Hi!'; | ||
} | ||
}; | ||
} | ||
} |