-
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.
refactor: toolbox error handling (#185)
- Loading branch information
1 parent
0930e73
commit eb8e36a
Showing
7 changed files
with
120 additions
and
29 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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpLlm\LlmChain\Exception; | ||
|
||
use PhpLlm\LlmChain\Model\Response\ToolCall; | ||
|
||
final class ToolBoxException extends RuntimeException | ||
{ | ||
public ?ToolCall $toolCall; | ||
|
||
public static function notFoundForToolCall(ToolCall $toolCall): self | ||
{ | ||
$exception = new self(sprintf('Tool not found for call: %s.', $toolCall->name)); | ||
$exception->toolCall = $toolCall; | ||
|
||
return $exception; | ||
} | ||
|
||
public static function invalidMethod(string $toolClass, string $methodName): self | ||
{ | ||
return new self(sprintf('Method "%s" not found in tool "%s".', $methodName, $toolClass)); | ||
} | ||
|
||
public static function executionFailed(ToolCall $toolCall, \Throwable $previous): self | ||
{ | ||
$exception = new self(sprintf('Execution of tool "%s" failed with error: %s', $toolCall->name, $previous->getMessage()), previous: $previous); | ||
$exception->toolCall = $toolCall; | ||
|
||
return $exception; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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_exception', description: 'This tool is broken', method: 'bar')] | ||
final class ToolException | ||
{ | ||
public function bar(): string | ||
{ | ||
throw new \Exception('Tool error.'); | ||
} | ||
} |
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_misconfigured', description: 'This tool is misconfigured, see method', method: 'foo')] | ||
final class ToolMisconfigured | ||
{ | ||
public function bar(): string | ||
{ | ||
return 'Wrong Config Attribute'; | ||
} | ||
} |