Skip to content

Commit a31f428

Browse files
authored
feat: adopt universal chain rework (#5)
1 parent a545828 commit a31f428

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

src/Resources/config/services.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
66

7-
use PhpLlm\LlmChain\Chat;
7+
use PhpLlm\LlmChain\Chain;
88
use PhpLlm\LlmChain\DocumentEmbedder;
99
use PhpLlm\LlmChain\OpenAI\Model\Embeddings;
1010
use PhpLlm\LlmChain\OpenAI\Model\Gpt;
@@ -15,7 +15,6 @@
1515
use PhpLlm\LlmChain\ToolBox\Registry;
1616
use PhpLlm\LlmChain\ToolBox\RegistryInterface;
1717
use PhpLlm\LlmChain\ToolBox\ToolAnalyzer;
18-
use PhpLlm\LlmChain\ToolChain;
1918
use PhpLlm\LlmChain\Store\Azure\SearchStore as AzureSearchStore;
2019
use PhpLlm\LlmChain\Store\ChromaDb\Store as ChromaDbStore;
2120
use PhpLlm\LlmChainBundle\DataCollector;
@@ -27,9 +26,9 @@
2726
->autowire()
2827
->autoconfigure()
2928

30-
// chains
31-
->set(Chat::class)
32-
->set(ToolChain::class)
29+
// high level feature
30+
->set(Chain::class)
31+
->set(DocumentEmbedder::class)
3332

3433
// runtimes
3534
->set(AzureRuntime::class)
@@ -73,9 +72,6 @@
7372
'$collectionName' => abstract_arg('Name of ChromaDB collection'),
7473
])
7574

76-
// embedder
77-
->set(DocumentEmbedder::class)
78-
7975
// tools
8076
->set(Registry::class)
8177
->args([

src/Resources/views/data_collector.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
{% for message in call.messages %}
7777
<li>
7878
<strong>{{ message.role.value|title }}:</strong>
79-
{{ message.hasFunctionCall ? dump(message.functionCall) : message.content }}
79+
{{ message.hasToolCalls ? dump(message.toolCalls) : message.content }}
8080
</li>
8181
{% endfor %}
8282
</ol>
@@ -114,7 +114,7 @@
114114
<tbody>
115115
<tr>
116116
<th>Arguments</th>
117-
<td>{{ call.arguments }}</td>
117+
<td>{{ dump(call.arguments) }}</td>
118118
</tr>
119119
<tr>
120120
<th>Response</th>

src/TraceableLanguageModel.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PhpLlm\LlmChain\LanguageModel;
88
use PhpLlm\LlmChain\Message\MessageBag;
9+
use PhpLlm\LlmChain\Response\Response;
910

1011
final class TraceableLanguageModel implements LanguageModel
1112
{
@@ -17,7 +18,7 @@ public function __construct(
1718
) {
1819
}
1920

20-
public function call(MessageBag $messages, array $options = []): array
21+
public function call(MessageBag $messages, array $options = []): Response
2122
{
2223
$response = $this->llm->call($messages, $options);
2324

@@ -30,6 +31,16 @@ public function call(MessageBag $messages, array $options = []): array
3031
return $response;
3132
}
3233

34+
public function hasToolSupport(): bool
35+
{
36+
return $this->llm->hasToolSupport();
37+
}
38+
39+
public function hasStructuredOutputSupport(): bool
40+
{
41+
return $this->llm->hasStructuredOutputSupport();
42+
}
43+
3344
public function getName(): string
3445
{
3546
return $this->name;

src/TraceableToolRegistry.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpLlm\LlmChainBundle;
66

7+
use PhpLlm\LlmChain\Response\ToolCall;
78
use PhpLlm\LlmChain\ToolBox\Registry;
89
use PhpLlm\LlmChain\ToolBox\RegistryInterface;
910

@@ -21,13 +22,13 @@ public function getMap(): array
2122
return $this->toolRegistry->getMap();
2223
}
2324

24-
public function execute(string $name, string $arguments): string
25+
public function execute(ToolCall $toolCall): string
2526
{
26-
$response = $this->toolRegistry->execute($name, $arguments);
27+
$response = $this->toolRegistry->execute($toolCall);
2728

2829
$this->calls[] = [
29-
'name' => $name,
30-
'arguments' => $arguments,
30+
'name' => $toolCall->name,
31+
'arguments' => $toolCall->arguments,
3132
'response' => $response,
3233
];
3334

0 commit comments

Comments
 (0)