Skip to content

Use child model classes as factories instead #301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/src/Audio/Chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function say(string $base64audio): void
$path = tempnam(sys_get_temp_dir(), 'audio-').'.wav';
file_put_contents($path, base64_decode($base64audio));

$result = $this->platform->invoke(new Whisper(), Audio::fromFile($path));
$result = $this->platform->invoke(Whisper::create(), Audio::fromFile($path));

$this->submitMessage($result->asText());
}
Expand Down
2 changes: 1 addition & 1 deletion demo/src/Video/TwigComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function submit(#[LiveArg] string $instruction, #[LiveArg] string $image)
Message::ofUser($instruction, Image::fromDataUrl($image))
);

$result = $this->platform->invoke(new Gpt(Gpt::GPT_4O_MINI), $messageBag, [
$result = $this->platform->invoke(Gpt::create(Gpt::GPT_4O_MINI), $messageBag, [
'max_tokens' => 100,
]);

Expand Down
2 changes: 1 addition & 1 deletion examples/albert/chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

$platform = PlatformFactory::create(env('ALBERT_API_KEY'), env('ALBERT_API_URL'), http_client());

$model = new Gpt('gpt-4o');
$model = Gpt::create('gpt-4o');
$agent = new Agent($platform, $model, logger: logger());

$documentContext = <<<'CONTEXT'
Expand Down
2 changes: 1 addition & 1 deletion examples/anthropic/chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('ANTHROPIC_API_KEY'), httpClient: http_client());
$model = new Claude(Claude::SONNET_37);
$model = Claude::create(Claude::SONNET_37);

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Expand Down
2 changes: 1 addition & 1 deletion examples/anthropic/image-input-binary.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('ANTHROPIC_API_KEY'), httpClient: http_client());
$model = new Claude(Claude::SONNET_37);
$model = Claude::create(Claude::SONNET_37);

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Expand Down
2 changes: 1 addition & 1 deletion examples/anthropic/image-input-url.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('ANTHROPIC_API_KEY'), httpClient: http_client());
$model = new Claude(Claude::SONNET_37);
$model = Claude::create(Claude::SONNET_37);

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Expand Down
2 changes: 1 addition & 1 deletion examples/anthropic/pdf-input-binary.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('ANTHROPIC_API_KEY'), httpClient: http_client());
$model = new Claude(Claude::SONNET_37);
$model = Claude::create(Claude::SONNET_37);

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Expand Down
2 changes: 1 addition & 1 deletion examples/anthropic/pdf-input-url.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('ANTHROPIC_API_KEY'), httpClient: http_client());
$model = new Claude(Claude::SONNET_37);
$model = Claude::create(Claude::SONNET_37);

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Expand Down
2 changes: 1 addition & 1 deletion examples/anthropic/stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('ANTHROPIC_API_KEY'), httpClient: http_client());
$model = new Claude();
$model = Claude::create();

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Expand Down
2 changes: 1 addition & 1 deletion examples/anthropic/toolcall.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('ANTHROPIC_API_KEY'), httpClient: http_client());
$model = new Claude();
$model = Claude::create();

$wikipedia = new Wikipedia(http_client());
$toolbox = new Toolbox([$wikipedia], logger: logger());
Expand Down
2 changes: 1 addition & 1 deletion examples/azure/audio-transcript.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
env('AZURE_OPENAI_KEY'),
http_client(),
);
$model = new Whisper();
$model = Whisper::create();
$file = Audio::fromFile(dirname(__DIR__, 2).'/fixtures/audio.mp3');

$result = $platform->invoke($model, $file);
Expand Down
2 changes: 1 addition & 1 deletion examples/azure/chat-gpt.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
env('AZURE_OPENAI_KEY'),
http_client(),
);
$model = new Gpt(Gpt::GPT_4O_MINI);
$model = Gpt::create(Gpt::GPT_4O_MINI);

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Expand Down
2 changes: 1 addition & 1 deletion examples/azure/chat-llama.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('AZURE_LLAMA_BASEURL'), env('AZURE_LLAMA_KEY'), http_client());
$model = new Llama(Llama::V3_3_70B_INSTRUCT);
$model = Llama::create(Llama::V3_3_70B_INSTRUCT);

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(Message::ofUser('I am going to Paris, what should I see?'));
Expand Down
2 changes: 1 addition & 1 deletion examples/azure/embeddings.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
env('AZURE_OPENAI_KEY'),
http_client(),
);
$embeddings = new Embeddings();
$embeddings = Embeddings::create();

$result = $platform->invoke($embeddings, <<<TEXT
Once upon a time, there was a country called Japan. It was a beautiful country with a lot of mountains and rivers.
Expand Down
2 changes: 1 addition & 1 deletion examples/bedrock/chat-claude.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}

$platform = PlatformFactory::create();
$model = new Claude('claude-3-7-sonnet-20250219');
$model = Claude::create('claude-3-7-sonnet-20250219');

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Expand Down
2 changes: 1 addition & 1 deletion examples/bedrock/chat-llama.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}

$platform = PlatformFactory::create();
$model = new Llama(Llama::V3_2_3B_INSTRUCT);
$model = Llama::create(Llama::V3_2_3B_INSTRUCT);

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Expand Down
2 changes: 1 addition & 1 deletion examples/bedrock/chat-nova.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}

$platform = PlatformFactory::create();
$model = new Nova(Nova::PRO);
$model = Nova::create(Nova::PRO);

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Expand Down
2 changes: 1 addition & 1 deletion examples/bedrock/image-claude-binary.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}

$platform = PlatformFactory::create();
$model = new Claude('claude-3-7-sonnet-20250219');
$model = Claude::create('claude-3-7-sonnet-20250219');

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Expand Down
2 changes: 1 addition & 1 deletion examples/bedrock/image-nova.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}

$platform = PlatformFactory::create();
$model = new Nova(Nova::PRO);
$model = Nova::create(Nova::PRO);

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Expand Down
2 changes: 1 addition & 1 deletion examples/bedrock/toolcall-claude.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
}

$platform = PlatformFactory::create();
$model = new Claude('claude-3-7-sonnet-20250219');
$model = Claude::create('claude-3-7-sonnet-20250219');

$wikipedia = new Wikipedia(http_client());
$toolbox = new Toolbox([$wikipedia]);
Expand Down
2 changes: 1 addition & 1 deletion examples/bedrock/toolcall-nova.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
}

$platform = PlatformFactory::create();
$model = new Nova();
$model = Nova::create();

$wikipedia = new Wikipedia(http_client());
$toolbox = new Toolbox([$wikipedia]);
Expand Down
2 changes: 1 addition & 1 deletion examples/document/vectorizing.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('OPENAI_API_KEY'), http_client());
$embeddings = new Embeddings(Embeddings::TEXT_3_LARGE);
$embeddings = Embeddings::create(Embeddings::TEXT_3_LARGE);

$textDocuments = [
new TextDocument(Uuid::v4(), 'Hello World'),
Expand Down
2 changes: 1 addition & 1 deletion examples/gemini/audio-input.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('GEMINI_API_KEY'), http_client());
$model = new Gemini(Gemini::GEMINI_1_5_FLASH);
$model = Gemini::create(Gemini::GEMINI_1_5_FLASH);

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Expand Down
2 changes: 1 addition & 1 deletion examples/gemini/chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('GEMINI_API_KEY'), http_client());
$model = new Gemini(Gemini::GEMINI_2_FLASH);
$model = Gemini::create(Gemini::GEMINI_2_FLASH);

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Expand Down
2 changes: 1 addition & 1 deletion examples/gemini/embeddings.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('GEMINI_API_KEY'), http_client());
$embeddings = new Embeddings();
$embeddings = Embeddings::create();

$result = $platform->invoke($embeddings, <<<TEXT
Once upon a time, there was a country called Japan. It was a beautiful country with a lot of mountains and rivers.
Expand Down
2 changes: 1 addition & 1 deletion examples/gemini/image-input.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('GEMINI_API_KEY'), http_client());
$model = new Gemini(Gemini::GEMINI_1_5_FLASH);
$model = Gemini::create(Gemini::GEMINI_1_5_FLASH);

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Expand Down
2 changes: 1 addition & 1 deletion examples/gemini/pdf-input-binary.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('GEMINI_API_KEY'), http_client());
$model = new Gemini(Gemini::GEMINI_1_5_FLASH);
$model = Gemini::create(Gemini::GEMINI_1_5_FLASH);

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Expand Down
2 changes: 1 addition & 1 deletion examples/gemini/server-tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
$platform = PlatformFactory::create(env('GEMINI_API_KEY'), http_client());

// Available server-side tools as of 2025-06-28: url_context, google_search, code_execution
$llm = new Gemini('gemini-2.5-pro-preview-03-25', ['server_tools' => ['url_context' => true], 'temperature' => 1.0]);
$llm = Gemini::create('gemini-2.5-pro-preview-03-25', options: ['server_tools' => ['url_context' => true], 'temperature' => 1.0]);

$toolbox = new Toolbox([new Clock()], logger: logger());
$processor = new AgentProcessor($toolbox);
Expand Down
2 changes: 1 addition & 1 deletion examples/gemini/stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('GEMINI_API_KEY'), http_client());
$model = new Gemini(Gemini::GEMINI_2_FLASH);
$model = Gemini::create(Gemini::GEMINI_2_FLASH);

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Expand Down
2 changes: 1 addition & 1 deletion examples/gemini/structured-output-clock.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('GEMINI_API_KEY'), http_client());
$model = new Gemini(Gemini::GEMINI_1_5_FLASH);
$model = Gemini::create(Gemini::GEMINI_1_5_FLASH);

$clock = new Clock(new SymfonyClock());
$toolbox = new Toolbox([$clock]);
Expand Down
2 changes: 1 addition & 1 deletion examples/gemini/structured-output-math.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('GEMINI_API_KEY'), http_client());
$model = new Gemini(Gemini::GEMINI_1_5_FLASH);
$model = Gemini::create(Gemini::GEMINI_1_5_FLASH);

$processor = new AgentProcessor();
$agent = new Agent($platform, $model, [$processor], [$processor], logger());
Expand Down
2 changes: 1 addition & 1 deletion examples/gemini/toolcall.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('GEMINI_API_KEY'), http_client());
$llm = new Gemini(Gemini::GEMINI_2_FLASH);
$llm = Gemini::create(Gemini::GEMINI_2_FLASH);

$toolbox = new Toolbox([new Clock()], logger: logger());
$processor = new AgentProcessor($toolbox);
Expand Down
2 changes: 1 addition & 1 deletion examples/lmstudio/chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('LMSTUDIO_HOST_URL'), http_client());
$model = new Completions('gemma-3-4b-it-qat');
$model = Completions::create('gemma-3-4b-it-qat');

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(
Expand Down
2 changes: 1 addition & 1 deletion examples/lmstudio/image-input-binary.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('LMSTUDIO_HOST_URL'), http_client());
$model = new Completions(
$model = Completions::create(
name: 'gemma-3-4b-it-qat',
capabilities: [...Completions::DEFAULT_CAPABILITIES, Capability::INPUT_IMAGE]
);
Expand Down
4 changes: 2 additions & 2 deletions examples/memory/mariadb.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@

// create embeddings for documents as preparation of the chain memory
$platform = PlatformFactory::create(env('OPENAI_API_KEY'), http_client());
$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings());
$vectorizer = new Vectorizer($platform, $embeddings = Embeddings::create());
$indexer = new Indexer($vectorizer, $store, logger());
$indexer->index($documents);

// Execute a chat call that is utilizing the memory
$embeddingsMemory = new EmbeddingProvider($platform, $embeddings, $store);
$memoryProcessor = new MemoryInputProcessor($embeddingsMemory);

$agent = new Agent($platform, new Gpt(Gpt::GPT_4O_MINI), [$memoryProcessor], logger: logger());
$agent = new Agent($platform, Gpt::create(Gpt::GPT_4O_MINI), [$memoryProcessor], logger: logger());
$messages = new MessageBag(Message::ofUser('Have we discussed about my friend John in the past? If yes, what did we talk about?'));
$result = $agent->call($messages);

Expand Down
2 changes: 1 addition & 1 deletion examples/memory/static.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create($_ENV['OPENAI_API_KEY'], http_client());
$model = new Gpt(Gpt::GPT_4O_MINI);
$model = Gpt::create(Gpt::GPT_4O_MINI);

$systemPromptProcessor = new SystemPromptInputProcessor('You are a professional trainer with short, personalized advice and a motivating claim.');

Expand Down
2 changes: 1 addition & 1 deletion examples/misc/chat-system-prompt.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('OPENAI_API_KEY'), http_client());
$model = new Gpt(Gpt::GPT_4O_MINI);
$model = Gpt::create(Gpt::GPT_4O_MINI);

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

Expand Down
2 changes: 1 addition & 1 deletion examples/misc/parallel-chat-gpt.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('OPENAI_API_KEY'), http_client());
$model = new Gpt(Gpt::GPT_4O_MINI, [
$model = Gpt::create(Gpt::GPT_4O_MINI, [
'temperature' => 0.5, // default options for the model
]);

Expand Down
6 changes: 3 additions & 3 deletions examples/misc/parallel-embeddings.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('OPENAI_API_KEY'), http_client());
$ada = new Embeddings(Embeddings::TEXT_ADA_002);
$small = new Embeddings(Embeddings::TEXT_3_SMALL);
$large = new Embeddings(Embeddings::TEXT_3_LARGE);
$ada = Embeddings::create(Embeddings::TEXT_ADA_002);
$small = Embeddings::create(Embeddings::TEXT_3_SMALL);
$large = Embeddings::create(Embeddings::TEXT_3_LARGE);

echo 'Initiating parallel embeddings calls to platform ...'.\PHP_EOL;
$results = [];
Expand Down
2 changes: 1 addition & 1 deletion examples/misc/persistent-chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('OPENAI_API_KEY'), http_client());
$llm = new Gpt(Gpt::GPT_4O_MINI);
$llm = Gpt::create(Gpt::GPT_4O_MINI);

$agent = new Agent($platform, $llm, logger: logger());
$chat = new Chat($agent, new InMemoryStore());
Expand Down
2 changes: 1 addition & 1 deletion examples/mistral/chat-multiple.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('MISTRAL_API_KEY'), http_client());
$agent = new Agent($platform, new Mistral(), logger: logger());
$agent = new Agent($platform, Mistral::create(), logger: logger());

$messages = new MessageBag(
Message::forSystem('Just give short answers.'),
Expand Down
2 changes: 1 addition & 1 deletion examples/mistral/chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('MISTRAL_API_KEY'), http_client());
$model = new Mistral();
$model = Mistral::create();
$agent = new Agent($platform, $model, logger: logger());

$messages = new MessageBag(Message::ofUser('What is the best French cheese?'));
Expand Down
2 changes: 1 addition & 1 deletion examples/mistral/embeddings.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
require_once dirname(__DIR__).'/bootstrap.php';

$platform = PlatformFactory::create(env('MISTRAL_API_KEY'), http_client());
$model = new Embeddings();
$model = Embeddings::create();

$result = $platform->invoke($model, <<<TEXT
In the middle of the 20th century, food scientists began to understand the importance of vitamins and minerals in
Expand Down
Loading
Loading