Skip to content

Commit 9430b51

Browse files
committed
refactor: introduce model capabilities with generic base model instead of interfaces with supportsX methods
1 parent be5d914 commit 9430b51

File tree

85 files changed

+378
-586
lines changed

Some content is hidden

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

85 files changed

+378
-586
lines changed

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/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';

examples/huggingface/table-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/text-classification.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/text-generation.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/text-to-image.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\BinaryResponse;
77
use Symfony\Component\Dotenv\Dotenv;
88

examples/huggingface/token-classification.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/translation.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/zero-shot-classification.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/ollama/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['OLLAMA_HOST_URL']);
19-
$llm = new Llama('llama3.2');
19+
$model = new Llama('llama3.2');
2020

21-
$chain = new Chain($platform, $llm);
21+
$chain = new Chain($platform, $model);
2222
$messages = new MessageBag(
2323
Message::forSystem('You are a helpful assistant.'),
2424
Message::ofUser('Tina has one brother and one sister. How many sisters do Tina\'s siblings have?'),

examples/openai/audio-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['OPENAI_API_KEY']);
20-
$llm = new GPT(GPT::GPT_4O_AUDIO);
20+
$model = new GPT(GPT::GPT_4O_AUDIO);
2121

22-
$chain = new Chain($platform, $llm);
22+
$chain = new Chain($platform, $model);
2323
$messages = new MessageBag(
2424
Message::ofUser(
2525
'What is this recording about?',

examples/openai/chat-o1.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
}
2222

2323
$platform = PlatformFactory::create($_ENV['OPENAI_API_KEY']);
24-
$llm = new GPT(GPT::O1_PREVIEW);
24+
$model = new GPT(GPT::O1_PREVIEW);
2525

2626
$prompt = <<<PROMPT
2727
I want to build a Symfony app in PHP 8.2 that takes user questions and looks them
@@ -32,6 +32,6 @@
3232
at the beginning and end, not throughout the code.
3333
PROMPT;
3434

35-
$response = (new Chain($platform, $llm))->call(new MessageBag(Message::ofUser($prompt)));
35+
$response = (new Chain($platform, $model))->call(new MessageBag(Message::ofUser($prompt)));
3636

3737
echo $response->getContent().PHP_EOL;

examples/openai/chat.php

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

1818
$platform = PlatformFactory::create($_ENV['OPENAI_API_KEY']);
19-
$llm = new GPT(GPT::GPT_4O_MINI, [
19+
$model = new GPT(GPT::GPT_4O_MINI, [
2020
'temperature' => 0.5, // default options for the model
2121
]);
2222

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

examples/openai/image-input-binary.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['OPENAI_API_KEY']);
20-
$llm = new GPT(GPT::GPT_4O_MINI);
20+
$model = new GPT(GPT::GPT_4O_MINI);
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/openai/image-input-url.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['OPENAI_API_KEY']);
20-
$llm = new GPT(GPT::GPT_4O_MINI);
20+
$model = new GPT(GPT::GPT_4O_MINI);
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(

0 commit comments

Comments
 (0)