Skip to content

Commit

Permalink
feat: introduce RegistryInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
chr-hertel committed Sep 21, 2024
1 parent 242e6a8 commit bde2e69
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
16 changes: 2 additions & 14 deletions src/ToolBox/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,9 @@
use Psr\Log\LoggerInterface;

/**
* @phpstan-import-type ParameterDefinition from ParameterAnalyzer
*
* @phpstan-type ToolDefinition = array{
* type: 'function',
* function: array{
* name: string,
* description: string,
* parameters?: ParameterDefinition
* }
* }
* @phpstan-import-type ToolDefinition from RegistryInterface
*/
final class Registry
final class Registry implements RegistryInterface
{
/**
* @var list<object>
Expand All @@ -41,9 +32,6 @@ public function __construct(
$this->tools = $tools instanceof \Traversable ? iterator_to_array($tools) : $tools;
}

/**
* @return list<ToolDefinition>
*/
public function getMap(): array
{
if (isset($this->map)) {
Expand Down
27 changes: 27 additions & 0 deletions src/ToolBox/RegistryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace PhpLlm\LlmChain\ToolBox;

/**
* @phpstan-import-type ParameterDefinition from ParameterAnalyzer
*
* @phpstan-type ToolDefinition = array{
* type: 'function',
* function: array{
* name: string,
* description: string,
* parameters?: ParameterDefinition
* }
* }
*/
interface RegistryInterface
{
/**
* @return list<ToolDefinition>
*/
public function getMap(): array;

public function execute(string $name, string $arguments): string;
}
4 changes: 2 additions & 2 deletions src/ToolChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

use PhpLlm\LlmChain\Message\Message;
use PhpLlm\LlmChain\Message\MessageBag;
use PhpLlm\LlmChain\ToolBox\Registry;
use PhpLlm\LlmChain\ToolBox\RegistryInterface;

final class ToolChain
{
public function __construct(
private LanguageModel $llm,
private Registry $toolRegistry,
private RegistryInterface $toolRegistry,
) {
}

Expand Down

0 comments on commit bde2e69

Please sign in to comment.