Skip to content

Commit 4c2fa37

Browse files
committed
refactor: introduce model capabilities with generic base model instead of interfaces with supportsX methods
1 parent e6385cc commit 4c2fa37

File tree

93 files changed

+419
-654
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+419
-654
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ use PhpLlm\LlmChain\Model\Message\MessageBag;
9696

9797
// Platform & LLM instantiation
9898

99-
$chain = new Chain($platform, $llm);
99+
$chain = new Chain($platform, $model);
100100
$messages = new MessageBag(
101101
Message::forSystem('You are a helpful chatbot answering questions about LLM Chain.'),
102102
Message::ofUser('Hello, how are you?'),
@@ -156,7 +156,7 @@ $yourTool = new YourTool();
156156
$toolbox = Toolbox::create($yourTool);
157157
$toolProcessor = new ChainProcessor($toolbox);
158158

159-
$chain = new Chain($platform, $llm, inputProcessor: [$toolProcessor], outputProcessor: [$toolProcessor]);
159+
$chain = new Chain($platform, $model, inputProcessor: [$toolProcessor], outputProcessor: [$toolProcessor]);
160160
```
161161

162162
Custom tools can basically be any class, but must configure by the `#[AsTool]` attribute.
@@ -314,7 +314,7 @@ use PhpLlm\LlmChain\Chain\Toolbox\FaultTolerantToolbox;
314314
$toolbox = new FaultTolerantToolbox($innerToolbox);
315315
$toolProcessor = new ChainProcessor($toolbox);
316316

317-
$chain = new Chain($platform, $llm, inputProcessor: [$toolProcessor], outputProcessor: [$toolProcessor]);
317+
$chain = new Chain($platform, $model, inputProcessor: [$toolProcessor], outputProcessor: [$toolProcessor]);
318318
```
319319

320320
#### Tool Filtering
@@ -411,7 +411,7 @@ use PhpLlm\LlmChain\Chain\Toolbox\Toolbox;
411411
$similaritySearch = new SimilaritySearch($embeddings, $store);
412412
$toolbox = Toolbox::create($similaritySearch);
413413
$processor = new ChainProcessor($toolbox);
414-
$chain = new Chain($platform, $llm, [$processor], [$processor]);
414+
$chain = new Chain($platform, $model, [$processor], [$processor]);
415415

416416
$messages = new MessageBag(
417417
Message::forSystem(<<<PROMPT
@@ -450,6 +450,7 @@ LLM Chain supports that use-case by abstracting the hustle of defining and provi
450450
the response back to PHP objects.
451451
452452
To achieve this, a specific chain processor needs to be registered:
453+
453454
```php
454455
use PhpLlm\LlmChain\Chain;
455456
use PhpLlm\LlmChain\Model\Message\Message;
@@ -465,7 +466,7 @@ use Symfony\Component\Serializer\Serializer;
465466
466467
$serializer = new Serializer([new ObjectNormalizer()], [new JsonEncoder()]);
467468
$processor = new ChainProcessor(new ResponseFormatFactory(), $serializer);
468-
$chain = new Chain($platform, $llm, [$processor], [$processor]);
469+
$chain = new Chain($platform, $model, [$processor], [$processor]);
469470
470471
$messages = new MessageBag(
471472
Message::forSystem('You are a helpful math tutor. Guide the user through the solution step by step.'),
@@ -524,7 +525,7 @@ use PhpLlm\LlmChain\Message\MessageBag;
524525
525526
// Initialize Platform and LLM
526527
527-
$chain = new Chain($llm);
528+
$chain = new Chain($model);
528529
$messages = new MessageBag(
529530
Message::forSystem('You are a thoughtful philosopher.'),
530531
Message::ofUser('What is the purpose of an ant?'),
@@ -659,7 +660,7 @@ use PhpLlm\LlmChain\Chain;
659660
660661
// Initialize Platform, LLM and processors
661662
662-
$chain = new Chain($platform, $llm, $inputProcessors, $outputProcessors);
663+
$chain = new Chain($platform, $model, $inputProcessors, $outputProcessors);
663664
```
664665
665666
#### InputProcessor

examples/anthropic/chat.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
}
1717

1818
$platform = PlatformFactory::create($_ENV['ANTHROPIC_API_KEY']);
19-
$llm = new Claude(Claude::SONNET_37);
19+
$model = new Claude(Claude::SONNET_37);
2020

21-
$chain = new Chain($platform, $llm);
21+
$chain = new Chain($platform, $model);
2222
$messages = new MessageBag(
2323
Message::forSystem('You are a pirate and you write funny.'),
2424
Message::ofUser('What is the Symfony framework?'),

examples/anthropic/stream.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
}
1717

1818
$platform = PlatformFactory::create($_ENV['ANTHROPIC_API_KEY']);
19-
$llm = new Claude();
19+
$model = new Claude();
2020

21-
$chain = new Chain($platform, $llm);
21+
$chain = new Chain($platform, $model);
2222
$messages = new MessageBag(
2323
Message::forSystem('You are a thoughtful philosopher.'),
2424
Message::ofUser('What is the purpose of an ant?'),

examples/anthropic/toolcall.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
}
2121

2222
$platform = PlatformFactory::create($_ENV['ANTHROPIC_API_KEY']);
23-
$llm = new Claude();
23+
$model = new Claude();
2424

2525
$wikipedia = new Wikipedia(HttpClient::create());
2626
$toolbox = Toolbox::create($wikipedia);
2727
$processor = new ChainProcessor($toolbox);
28-
$chain = new Chain($platform, $llm, [$processor], [$processor]);
28+
$chain = new Chain($platform, $model, [$processor], [$processor]);
2929

3030
$messages = new MessageBag(Message::ofUser('Who is the current chancellor of Germany?'));
3131
$response = $chain->call($messages);

examples/azure/chat-gpt.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
$_ENV['AZURE_OPENAI_GPT_API_VERSION'],
2323
$_ENV['AZURE_OPENAI_KEY'],
2424
);
25-
$llm = new GPT(GPT::GPT_4O_MINI);
25+
$model = new GPT(GPT::GPT_4O_MINI);
2626

27-
$chain = new Chain($platform, $llm);
27+
$chain = new Chain($platform, $model);
2828
$messages = new MessageBag(
2929
Message::forSystem('You are a pirate and you write funny.'),
3030
Message::ofUser('What is the Symfony framework?'),

examples/azure/chat-llama.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
}
1717

1818
$platform = PlatformFactory::create($_ENV['AZURE_LLAMA_BASEURL'], $_ENV['AZURE_LLAMA_KEY']);
19-
$llm = new Llama(Llama::V3_3_70B_INSTRUCT);
19+
$model = new Llama(Llama::V3_3_70B_INSTRUCT);
2020

21-
$chain = new Chain($platform, $llm);
21+
$chain = new Chain($platform, $model);
2222
$messages = new MessageBag(Message::ofUser('I am going to Paris, what should I see?'));
2323
$response = $chain->call($messages, [
2424
'max_tokens' => 2048,

examples/bedrock/chat-claude.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
$platform = PlatformFactory::create(
2121
new BedrockRuntimeClient()
2222
);
23-
$llm = new Claude();
23+
$model = new Claude();
2424

25-
$chain = new Chain($platform, $llm);
25+
$chain = new Chain($platform, $model);
2626
$messages = new MessageBag(
2727
Message::forSystem('You are a pirate and you write funny.'),
2828
Message::ofUser('What is the Symfony framework?'),

examples/bedrock/chat-llama.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
$platform = PlatformFactory::create(
2121
new BedrockRuntimeClient()
2222
);
23-
$llm = new Llama('llama-3.2-3b-instruct');
23+
$model = new Llama('llama-3.2-3b-instruct');
2424

25-
$chain = new Chain($platform, $llm);
25+
$chain = new Chain($platform, $model);
2626
$messages = new MessageBag(
2727
Message::forSystem('You are a pirate and you write funny.'),
2828
Message::ofUser('What is the Symfony framework?'),

examples/bedrock/chat-nova.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
$platform = PlatformFactory::create(
2121
new BedrockRuntimeClient()
2222
);
23-
$llm = new Nova(Nova::PRO);
23+
$model = new Nova(Nova::PRO);
2424

25-
$chain = new Chain($platform, $llm);
25+
$chain = new Chain($platform, $model);
2626
$messages = new MessageBag(
2727
Message::forSystem('You are a pirate and you write funny.'),
2828
Message::ofUser('What is the Symfony framework?'),

examples/bedrock/image-claude-binary.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
$platform = PlatformFactory::create(
2222
new BedrockRuntimeClient()
2323
);
24-
$llm = new Claude();
24+
$model = new Claude();
2525

26-
$chain = new Chain($platform, $llm);
26+
$chain = new Chain($platform, $model);
2727
$messages = new MessageBag(
2828
Message::forSystem('You are an image analyzer bot that helps identify the content of images.'),
2929
Message::ofUser(

examples/bedrock/image-nova.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
$platform = PlatformFactory::create(
2222
new BedrockRuntimeClient()
2323
);
24-
$llm = new Nova(Nova::PRO);
24+
$model = new Nova(Nova::PRO);
2525

26-
$chain = new Chain($platform, $llm);
26+
$chain = new Chain($platform, $model);
2727
$messages = new MessageBag(
2828
Message::forSystem('You are an image analyzer bot that helps identify the content of images.'),
2929
Message::ofUser(

examples/bedrock/toolcall-claude.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
$platform = PlatformFactory::create(
2525
new BedrockRuntimeClient()
2626
);
27-
$llm = new Claude();
27+
$model = new Claude();
2828

2929
$wikipedia = new Wikipedia(HttpClient::create());
3030
$toolbox = Toolbox::create($wikipedia);
3131
$processor = new ChainProcessor($toolbox);
32-
$chain = new Chain($platform, $llm, [$processor], [$processor]);
32+
$chain = new Chain($platform, $model, [$processor], [$processor]);
3333

3434
$messages = new MessageBag(Message::ofUser('Who is the current chancellor of Germany?'));
3535
$response = $chain->call($messages);

examples/chat-system-prompt.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
}
1818

1919
$platform = PlatformFactory::create($_ENV['OPENAI_API_KEY']);
20-
$llm = new GPT(GPT::GPT_4O_MINI);
20+
$model = new GPT(GPT::GPT_4O_MINI);
2121

2222
$processor = new SystemPromptInputProcessor('You are Yoda and write like he speaks. But short.');
2323

24-
$chain = new Chain($platform, $llm, [$processor]);
24+
$chain = new Chain($platform, $model, [$processor]);
2525
$messages = new MessageBag(Message::ofUser('What is the meaning of life?'));
2626
$response = $chain->call($messages);
2727

examples/google/chat.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
}
1717

1818
$platform = PlatformFactory::create($_ENV['GOOGLE_API_KEY']);
19-
$llm = new Gemini(Gemini::GEMINI_2_FLASH);
19+
$model = new Gemini(Gemini::GEMINI_2_FLASH);
2020

21-
$chain = new Chain($platform, $llm);
21+
$chain = new Chain($platform, $model);
2222
$messages = new MessageBag(
2323
Message::forSystem('You are a pirate and you write funny.'),
2424
Message::ofUser('What is the Symfony framework?'),

examples/google/image-input.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
}
1818

1919
$platform = PlatformFactory::create($_ENV['GOOGLE_API_KEY']);
20-
$llm = new Gemini(Gemini::GEMINI_1_5_FLASH);
20+
$model = new Gemini(Gemini::GEMINI_1_5_FLASH);
2121

22-
$chain = new Chain($platform, $llm);
22+
$chain = new Chain($platform, $model);
2323
$messages = new MessageBag(
2424
Message::forSystem('You are an image analyzer bot that helps identify the content of images.'),
2525
Message::ofUser(

examples/google/stream.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
}
1717

1818
$platform = PlatformFactory::create($_ENV['GOOGLE_API_KEY']);
19-
$llm = new Gemini(Gemini::GEMINI_2_FLASH);
19+
$model = new Gemini(Gemini::GEMINI_2_FLASH);
2020

21-
$chain = new Chain($platform, $llm);
21+
$chain = new Chain($platform, $model);
2222
$messages = new MessageBag(
2323
Message::forSystem('You are a funny clown that entertains people.'),
2424
Message::ofUser('What is the purpose of an ant?'),

examples/huggingface/_model-listing.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
use PhpLlm\LlmChain\Bridge\HuggingFace\ApiClient;
4-
use PhpLlm\LlmChain\Bridge\HuggingFace\Model;
4+
use PhpLlm\LlmChain\Model\Model;
55
use Symfony\Component\Console\Command\Command;
66
use Symfony\Component\Console\Input\InputInterface;
77
use Symfony\Component\Console\Input\InputOption;

examples/huggingface/audio-classification.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
use PhpLlm\LlmChain\Bridge\HuggingFace\Model;
43
use PhpLlm\LlmChain\Bridge\HuggingFace\PlatformFactory;
54
use PhpLlm\LlmChain\Bridge\HuggingFace\Task;
65
use PhpLlm\LlmChain\Model\Message\Content\Audio;
6+
use PhpLlm\LlmChain\Model\Model;
77
use Symfony\Component\Dotenv\Dotenv;
88

99
require_once dirname(__DIR__, 2).'/vendor/autoload.php';

examples/huggingface/automatic-speech-recognition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
use PhpLlm\LlmChain\Bridge\HuggingFace\Model;
43
use PhpLlm\LlmChain\Bridge\HuggingFace\PlatformFactory;
54
use PhpLlm\LlmChain\Bridge\HuggingFace\Task;
65
use PhpLlm\LlmChain\Model\Message\Content\Audio;
6+
use PhpLlm\LlmChain\Model\Model;
77
use Symfony\Component\Dotenv\Dotenv;
88

99
require_once dirname(__DIR__, 2).'/vendor/autoload.php';

examples/huggingface/chat-completion.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

3-
use PhpLlm\LlmChain\Bridge\HuggingFace\Model;
43
use PhpLlm\LlmChain\Bridge\HuggingFace\PlatformFactory;
54
use PhpLlm\LlmChain\Bridge\HuggingFace\Task;
65
use PhpLlm\LlmChain\Model\Message\Message;
76
use PhpLlm\LlmChain\Model\Message\MessageBag;
7+
use PhpLlm\LlmChain\Model\Model;
88
use Symfony\Component\Dotenv\Dotenv;
99

1010
require_once dirname(__DIR__, 2).'/vendor/autoload.php';

examples/huggingface/feature-extraction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
use PhpLlm\LlmChain\Bridge\HuggingFace\Model;
43
use PhpLlm\LlmChain\Bridge\HuggingFace\PlatformFactory;
54
use PhpLlm\LlmChain\Bridge\HuggingFace\Task;
5+
use PhpLlm\LlmChain\Model\Model;
66
use PhpLlm\LlmChain\Model\Response\VectorResponse;
77
use Symfony\Component\Dotenv\Dotenv;
88

examples/huggingface/fill-mask.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
use PhpLlm\LlmChain\Bridge\HuggingFace\Model;
43
use PhpLlm\LlmChain\Bridge\HuggingFace\PlatformFactory;
54
use PhpLlm\LlmChain\Bridge\HuggingFace\Task;
5+
use PhpLlm\LlmChain\Model\Model;
66
use Symfony\Component\Dotenv\Dotenv;
77

88
require_once dirname(__DIR__, 2).'/vendor/autoload.php';

examples/huggingface/image-classification.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
use PhpLlm\LlmChain\Bridge\HuggingFace\Model;
43
use PhpLlm\LlmChain\Bridge\HuggingFace\PlatformFactory;
54
use PhpLlm\LlmChain\Bridge\HuggingFace\Task;
65
use PhpLlm\LlmChain\Model\Message\Content\Image;
6+
use PhpLlm\LlmChain\Model\Model;
77
use Symfony\Component\Dotenv\Dotenv;
88

99
require_once dirname(__DIR__, 2).'/vendor/autoload.php';

examples/huggingface/image-segmentation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
use PhpLlm\LlmChain\Bridge\HuggingFace\Model;
43
use PhpLlm\LlmChain\Bridge\HuggingFace\PlatformFactory;
54
use PhpLlm\LlmChain\Bridge\HuggingFace\Task;
65
use PhpLlm\LlmChain\Model\Message\Content\Image;
6+
use PhpLlm\LlmChain\Model\Model;
77
use Symfony\Component\Dotenv\Dotenv;
88

99
require_once dirname(__DIR__, 2).'/vendor/autoload.php';

examples/huggingface/image-to-text.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
use PhpLlm\LlmChain\Bridge\HuggingFace\Model;
43
use PhpLlm\LlmChain\Bridge\HuggingFace\PlatformFactory;
54
use PhpLlm\LlmChain\Bridge\HuggingFace\Task;
65
use PhpLlm\LlmChain\Model\Message\Content\Image;
6+
use PhpLlm\LlmChain\Model\Model;
77
use Symfony\Component\Dotenv\Dotenv;
88

99
require_once dirname(__DIR__, 2).'/vendor/autoload.php';

examples/huggingface/object-detection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
use PhpLlm\LlmChain\Bridge\HuggingFace\Model;
43
use PhpLlm\LlmChain\Bridge\HuggingFace\PlatformFactory;
54
use PhpLlm\LlmChain\Bridge\HuggingFace\Task;
65
use PhpLlm\LlmChain\Model\Message\Content\Image;
6+
use PhpLlm\LlmChain\Model\Model;
77
use Symfony\Component\Dotenv\Dotenv;
88

99
require_once dirname(__DIR__, 2).'/vendor/autoload.php';

examples/huggingface/question-answering.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
use PhpLlm\LlmChain\Bridge\HuggingFace\Model;
43
use PhpLlm\LlmChain\Bridge\HuggingFace\PlatformFactory;
54
use PhpLlm\LlmChain\Bridge\HuggingFace\Task;
5+
use PhpLlm\LlmChain\Model\Model;
66
use Symfony\Component\Dotenv\Dotenv;
77

88
require_once dirname(__DIR__, 2).'/vendor/autoload.php';

examples/huggingface/sentence-similarity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
use PhpLlm\LlmChain\Bridge\HuggingFace\Model;
43
use PhpLlm\LlmChain\Bridge\HuggingFace\PlatformFactory;
54
use PhpLlm\LlmChain\Bridge\HuggingFace\Task;
5+
use PhpLlm\LlmChain\Model\Model;
66
use Symfony\Component\Dotenv\Dotenv;
77

88
require_once dirname(__DIR__, 2).'/vendor/autoload.php';

examples/huggingface/summarization.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
use PhpLlm\LlmChain\Bridge\HuggingFace\Model;
43
use PhpLlm\LlmChain\Bridge\HuggingFace\PlatformFactory;
54
use PhpLlm\LlmChain\Bridge\HuggingFace\Task;
5+
use PhpLlm\LlmChain\Model\Model;
66
use Symfony\Component\Dotenv\Dotenv;
77

88
require_once dirname(__DIR__, 2).'/vendor/autoload.php';

0 commit comments

Comments
 (0)