Skip to content

Commit b72ee37

Browse files
authored
refactor: simplify constructing ToolAnalyzer (#16)
1 parent 06f3b62 commit b72ee37

File tree

6 files changed

+6
-11
lines changed

6 files changed

+6
-11
lines changed

examples/toolbox-clock.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
77
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
88
use PhpLlm\LlmChain\OpenAI\Runtime\OpenAI;
9-
use PhpLlm\LlmChain\ToolBox\ParameterAnalyzer;
109
use PhpLlm\LlmChain\ToolBox\Tool\Clock;
1110
use PhpLlm\LlmChain\ToolBox\ToolAnalyzer;
1211
use PhpLlm\LlmChain\ToolBox\ToolBox;
@@ -19,7 +18,7 @@
1918
$llm = new Gpt($runtime, Version::GPT_4o_MINI);
2019

2120
$clock = new Clock(new SymfonyClock());
22-
$toolBox = new ToolBox(new ToolAnalyzer(new ParameterAnalyzer()), [$clock]);
21+
$toolBox = new ToolBox(new ToolAnalyzer(), [$clock]);
2322
$chain = new Chain($llm, $toolBox);
2423

2524
$messages = new MessageBag(Message::ofUser('What date and time is it?'));

examples/toolbox-serpapi.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
77
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
88
use PhpLlm\LlmChain\OpenAI\Runtime\OpenAI;
9-
use PhpLlm\LlmChain\ToolBox\ParameterAnalyzer;
109
use PhpLlm\LlmChain\ToolBox\Tool\SerpApi;
1110
use PhpLlm\LlmChain\ToolBox\ToolAnalyzer;
1211
use PhpLlm\LlmChain\ToolBox\ToolBox;
@@ -19,7 +18,7 @@
1918
$llm = new Gpt($runtime, Version::GPT_4o_MINI);
2019

2120
$serpApi = new SerpApi($httpClient, getenv('SERP_API_KEY'));
22-
$toolBox = new ToolBox(new ToolAnalyzer(new ParameterAnalyzer()), [$serpApi]);
21+
$toolBox = new ToolBox(new ToolAnalyzer(), [$serpApi]);
2322
$chain = new Chain($llm, $toolBox);
2423

2524
$messages = new MessageBag(Message::ofUser('Who is the current chancellor of Germany?'));

examples/toolbox-weather.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
77
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
88
use PhpLlm\LlmChain\OpenAI\Runtime\OpenAI;
9-
use PhpLlm\LlmChain\ToolBox\ParameterAnalyzer;
109
use PhpLlm\LlmChain\ToolBox\Tool\OpenMeteo;
1110
use PhpLlm\LlmChain\ToolBox\ToolAnalyzer;
1211
use PhpLlm\LlmChain\ToolBox\ToolBox;
@@ -19,7 +18,7 @@
1918
$llm = new Gpt($runtime, Version::GPT_4o_MINI);
2019

2120
$wikipedia = new OpenMeteo($httpClient);
22-
$toolBox = new ToolBox(new ToolAnalyzer(new ParameterAnalyzer()), [$wikipedia]);
21+
$toolBox = new ToolBox(new ToolAnalyzer(), [$wikipedia]);
2322
$chain = new Chain($llm, $toolBox);
2423

2524
$messages = new MessageBag(Message::ofUser('How is the weather currently in Berlin?'));

examples/toolbox-wikipedia.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
77
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
88
use PhpLlm\LlmChain\OpenAI\Runtime\OpenAI;
9-
use PhpLlm\LlmChain\ToolBox\ParameterAnalyzer;
109
use PhpLlm\LlmChain\ToolBox\Tool\Wikipedia;
1110
use PhpLlm\LlmChain\ToolBox\ToolAnalyzer;
1211
use PhpLlm\LlmChain\ToolBox\ToolBox;
@@ -19,7 +18,7 @@
1918
$llm = new Gpt($runtime, Version::GPT_4o_MINI);
2019

2120
$wikipedia = new Wikipedia($httpClient);
22-
$toolBox = new ToolBox(new ToolAnalyzer(new ParameterAnalyzer()), [$wikipedia]);
21+
$toolBox = new ToolBox(new ToolAnalyzer(), [$wikipedia]);
2322
$chain = new Chain($llm, $toolBox);
2423

2524
$messages = new MessageBag(Message::ofUser('Who is the current chancellor of Germany?'));

examples/toolbox-youtube.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
77
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version;
88
use PhpLlm\LlmChain\OpenAI\Runtime\OpenAI;
9-
use PhpLlm\LlmChain\ToolBox\ParameterAnalyzer;
109
use PhpLlm\LlmChain\ToolBox\Tool\YouTubeTranscriber;
1110
use PhpLlm\LlmChain\ToolBox\ToolAnalyzer;
1211
use PhpLlm\LlmChain\ToolBox\ToolBox;
@@ -19,7 +18,7 @@
1918
$llm = new Gpt($runtime, Version::GPT_4o_MINI);
2019

2120
$transcriber = new YouTubeTranscriber($httpClient);
22-
$toolBox = new ToolBox(new ToolAnalyzer(new ParameterAnalyzer()), [$transcriber]);
21+
$toolBox = new ToolBox(new ToolAnalyzer(), [$transcriber]);
2322
$chain = new Chain($llm, $toolBox);
2423

2524
$messages = new MessageBag(Message::ofUser('Please summarize this video for me: https://www.youtube.com/watch?v=6uXW-ulpj0s'));

src/ToolBox/ToolAnalyzer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
final class ToolAnalyzer
1010
{
1111
public function __construct(
12-
private readonly ParameterAnalyzer $parameterAnalyzer,
12+
private readonly ParameterAnalyzer $parameterAnalyzer = new ParameterAnalyzer(),
1313
) {
1414
}
1515

0 commit comments

Comments
 (0)