From a5c7bc039377151db17460c5273c3006510354d2 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Sat, 13 Sep 2025 10:16:47 +0200 Subject: [PATCH] [Platform] Remove default model names from constructor parameters --- demo/src/Blog/Command/QueryCommand.php | 2 +- examples/azure/audio-transcript.php | 2 +- examples/azure/embeddings.php | 2 +- examples/cerebras/chat.php | 2 +- examples/cerebras/stream.php | 2 +- examples/gemini/embeddings.php | 2 +- examples/memory/mariadb.php | 2 +- examples/mistral/embeddings.php | 2 +- examples/ollama/stream.php | 2 +- examples/ollama/structured-output-math.php | 2 +- examples/ollama/toolcall.php | 2 +- examples/openai/audio-transcript.php | 2 +- examples/openai/embeddings.php | 2 +- examples/openai/image-output-dall-e-2.php | 2 +- examples/rag/cache.php | 2 +- examples/rag/chromadb.php | 2 +- examples/rag/clickhouse.php | 2 +- examples/rag/cloudflare.php | 2 +- examples/rag/in-memory.php | 2 +- examples/rag/mariadb-gemini.php | 4 +-- examples/rag/mariadb-openai.php | 2 +- examples/rag/meilisearch.php | 2 +- examples/rag/milvus.php | 2 +- examples/rag/mongodb.php | 2 +- examples/rag/neo4j.php | 2 +- examples/rag/pinecone.php | 2 +- examples/rag/postgres.php | 2 +- examples/rag/qdrant.php | 2 +- examples/rag/surrealdb.php | 2 +- examples/rag/typesense.php | 2 +- examples/rag/weaviate.php | 2 +- examples/replicate/chat-llama.php | 2 +- examples/vertexai/embeddings.php | 2 +- examples/voyage/embeddings.php | 2 +- examples/voyage/multiple-embeddings.php | 2 +- src/platform/doc/index.rst | 2 +- src/platform/src/Bridge/Cerebras/Model.php | 2 +- src/platform/src/Bridge/Gemini/Embeddings.php | 2 +- src/platform/src/Bridge/Gemini/Gemini.php | 2 +- src/platform/src/Bridge/Meta/Llama.php | 2 +- src/platform/src/Bridge/Ollama/Ollama.php | 2 +- src/platform/src/Bridge/OpenAi/DallE.php | 2 +- src/platform/src/Bridge/OpenAi/Embeddings.php | 2 +- src/platform/src/Bridge/OpenAi/Whisper.php | 2 +- .../src/Bridge/VertexAi/Embeddings/Model.php | 2 +- .../src/Bridge/VertexAi/Gemini/Model.php | 2 +- src/platform/src/Bridge/Voyage/Voyage.php | 2 +- src/platform/src/Model.php | 9 ++++++ .../OpenAi/EmbeddingsModelClientTest.php | 4 +-- .../Azure/OpenAi/GptModelClientTest.php | 4 +-- .../Azure/OpenAi/WhisperModelClientTest.php | 8 ++--- .../AssistantMessageNormalizerTest.php | 2 +- .../Contract/MessageBagNormalizerTest.php | 2 +- .../ToolCallMessageNormalizerTest.php | 2 +- .../Gemini/Contract/ToolNormalizerTest.php | 2 +- .../Contract/UserMessageNormalizerTest.php | 2 +- .../AssistantMessageNormalizerTest.php | 2 +- .../tests/Bridge/Ollama/OllamaClientTest.php | 6 ++-- .../Ollama/OllamaResultConverterTest.php | 2 +- .../Contract/DocumentNormalizerTest.php | 2 +- .../Bridge/OpenAi/DallE/ModelClientTest.php | 6 ++-- .../tests/Bridge/OpenAi/DallETest.php | 2 +- .../OpenAi/Embeddings/ModelClientTest.php | 8 ++--- .../tests/Bridge/OpenAi/EmbeddingsTest.php | 2 +- .../Bridge/OpenAi/Gpt/ModelClientTest.php | 8 ++--- src/platform/tests/Bridge/OpenAi/GptTest.php | 2 +- .../Bridge/OpenAi/Whisper/ModelClientTest.php | 12 +++---- .../tests/Bridge/OpenAi/WhisperTest.php | 2 +- .../AssistantMessageNormalizerTest.php | 2 +- .../Contract/MessageBagNormalizerTest.php | 2 +- .../ToolCallMessageNormalizerTest.php | 2 +- .../VertexAi/Contract/ToolNormalizerTest.php | 2 +- .../Contract/UserMessageNormalizerTest.php | 2 +- .../Message/MessageBagNormalizerTest.php | 4 +-- src/platform/tests/ContractTest.php | 16 +++++----- src/store/tests/Document/VectorizerTest.php | 32 +++++++++---------- src/store/tests/IndexerTest.php | 10 +++--- 77 files changed, 133 insertions(+), 124 deletions(-) diff --git a/demo/src/Blog/Command/QueryCommand.php b/demo/src/Blog/Command/QueryCommand.php index 3128c7238..82c2ad67d 100644 --- a/demo/src/Blog/Command/QueryCommand.php +++ b/demo/src/Blog/Command/QueryCommand.php @@ -44,7 +44,7 @@ public function __invoke(SymfonyStyle $io): int $io->comment(\sprintf('Converting "%s" to vector & searching in Chroma DB ...', $search)); $io->comment('Results are limited to 4 most similar documents.'); - $platformResponse = $this->platform->invoke(new Embeddings(), $search); + $platformResponse = $this->platform->invoke(new Embeddings(Embeddings::TEXT_3_SMALL), $search); $queryResponse = $collection->query( queryEmbeddings: [$platformResponse->asVectors()[0]->getData()], nResults: 4, diff --git a/examples/azure/audio-transcript.php b/examples/azure/audio-transcript.php index e4ffea49e..9d8f2b5d3 100644 --- a/examples/azure/audio-transcript.php +++ b/examples/azure/audio-transcript.php @@ -22,7 +22,7 @@ env('AZURE_OPENAI_KEY'), http_client(), ); -$model = new Whisper(); +$model = new Whisper(Whisper::WHISPER_1); $file = Audio::fromFile(dirname(__DIR__, 2).'/fixtures/audio.mp3'); $result = $platform->invoke($model, $file); diff --git a/examples/azure/embeddings.php b/examples/azure/embeddings.php index 17ee838c9..3f4195d63 100644 --- a/examples/azure/embeddings.php +++ b/examples/azure/embeddings.php @@ -21,7 +21,7 @@ env('AZURE_OPENAI_KEY'), http_client(), ); -$embeddings = new Embeddings(); +$embeddings = new Embeddings(Embeddings::TEXT_3_SMALL); $result = $platform->invoke($embeddings, <<invoke(new Model(), $messages); +$result = $platform->invoke(new Model(Model::LLAMA3_1_8B), $messages); echo $result->getResult()->getContent().\PHP_EOL; diff --git a/examples/cerebras/stream.php b/examples/cerebras/stream.php index ba815188f..b1f254fd9 100644 --- a/examples/cerebras/stream.php +++ b/examples/cerebras/stream.php @@ -23,7 +23,7 @@ Message::ofUser('What are the top three destinations in France?'), ); -$result = $platform->invoke(new Model(), $messages, [ +$result = $platform->invoke(new Model(Model::LLAMA3_1_8B), $messages, [ 'stream' => true, ]); diff --git a/examples/gemini/embeddings.php b/examples/gemini/embeddings.php index d9928ffd7..f5295efaf 100644 --- a/examples/gemini/embeddings.php +++ b/examples/gemini/embeddings.php @@ -15,7 +15,7 @@ require_once dirname(__DIR__).'/bootstrap.php'; $platform = PlatformFactory::create(env('GEMINI_API_KEY'), http_client()); -$embeddings = new Embeddings(); +$embeddings = new Embeddings(Embeddings::GEMINI_EMBEDDING_EXP_03_07); $result = $platform->invoke($embeddings, <<index($documents); diff --git a/examples/mistral/embeddings.php b/examples/mistral/embeddings.php index 037cb1eaa..54b061e9e 100644 --- a/examples/mistral/embeddings.php +++ b/examples/mistral/embeddings.php @@ -15,7 +15,7 @@ require_once dirname(__DIR__).'/bootstrap.php'; $platform = PlatformFactory::create(env('MISTRAL_API_KEY'), http_client()); -$model = new Embeddings(); +$model = new Embeddings(Embeddings::MISTRAL_EMBED); $result = $platform->invoke($model, <<invoke($model, $file); diff --git a/examples/openai/embeddings.php b/examples/openai/embeddings.php index 71f423909..6180f3504 100644 --- a/examples/openai/embeddings.php +++ b/examples/openai/embeddings.php @@ -15,7 +15,7 @@ require_once dirname(__DIR__).'/bootstrap.php'; $platform = PlatformFactory::create(env('OPENAI_API_KEY'), http_client()); -$embeddings = new Embeddings(); +$embeddings = new Embeddings(Embeddings::TEXT_3_SMALL); $result = $platform->invoke($embeddings, <<invoke( - model: new DallE(), // Utilize Dall-E 2 version in default + model: new DallE(DallE::DALL_E_2), input: 'A cartoon-style elephant with a long trunk and large ears.', options: [ 'response_format' => 'url', // Generate response as URL diff --git a/examples/rag/cache.php b/examples/rag/cache.php index 6b5270f82..7dff96b4f 100644 --- a/examples/rag/cache.php +++ b/examples/rag/cache.php @@ -45,7 +45,7 @@ // create embeddings for documents $platform = PlatformFactory::create(env('OPENAI_API_KEY'), http_client()); -$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(), logger()); +$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(Embeddings::TEXT_3_SMALL), logger()); $indexer = new Indexer(new InMemoryLoader($documents), $vectorizer, $store, logger: logger()); $indexer->index($documents); diff --git a/examples/rag/chromadb.php b/examples/rag/chromadb.php index 9eed9fe23..0bbec99c6 100644 --- a/examples/rag/chromadb.php +++ b/examples/rag/chromadb.php @@ -51,7 +51,7 @@ // create embeddings for documents $platform = PlatformFactory::create(env('OPENAI_API_KEY'), http_client()); -$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(), logger()); +$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(Embeddings::TEXT_3_SMALL), logger()); $indexer = new Indexer(new InMemoryLoader($documents), $vectorizer, $store, logger: logger()); $indexer->index($documents); diff --git a/examples/rag/clickhouse.php b/examples/rag/clickhouse.php index f6556c10c..490228824 100644 --- a/examples/rag/clickhouse.php +++ b/examples/rag/clickhouse.php @@ -52,7 +52,7 @@ // create embeddings for documents $platform = PlatformFactory::create(env('OPENAI_API_KEY'), http_client()); -$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(), logger()); +$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(Embeddings::TEXT_3_SMALL), logger()); $indexer = new Indexer(new InMemoryLoader($documents), $vectorizer, $store, logger: logger()); $indexer->index($documents); diff --git a/examples/rag/cloudflare.php b/examples/rag/cloudflare.php index 4516058e6..4c8730870 100644 --- a/examples/rag/cloudflare.php +++ b/examples/rag/cloudflare.php @@ -52,7 +52,7 @@ // create embeddings for documents (keep in mind that upserting vectors is asynchronous) $platform = PlatformFactory::create(env('OPENAI_API_KEY'), http_client()); -$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(), logger()); +$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(Embeddings::TEXT_3_SMALL), logger()); $indexer = new Indexer(new InMemoryLoader($documents), $vectorizer, $store, logger: logger()); $indexer->index($documents); diff --git a/examples/rag/in-memory.php b/examples/rag/in-memory.php index 7f66cd325..0f6dd14ca 100644 --- a/examples/rag/in-memory.php +++ b/examples/rag/in-memory.php @@ -44,7 +44,7 @@ // create embeddings for documents $platform = PlatformFactory::create(env('OPENAI_API_KEY'), http_client()); -$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(), logger()); +$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(Embeddings::TEXT_3_SMALL), logger()); $indexer = new Indexer(new InMemoryLoader($documents), $vectorizer, $store, logger: logger()); $indexer->index($documents); diff --git a/examples/rag/mariadb-gemini.php b/examples/rag/mariadb-gemini.php index ec64e6e51..0ae739faa 100644 --- a/examples/rag/mariadb-gemini.php +++ b/examples/rag/mariadb-gemini.php @@ -54,8 +54,8 @@ // create embeddings for documents $platform = PlatformFactory::create(env('GEMINI_API_KEY'), http_client()); -$embeddings = new Embeddings(options: ['dimensions' => 768, 'task_type' => TaskType::SemanticSimilarity]); -$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(), logger()); +$embeddings = new Embeddings(Embeddings::GEMINI_EMBEDDING_EXP_03_07, ['dimensions' => 768, 'task_type' => TaskType::SemanticSimilarity]); +$vectorizer = new Vectorizer($platform, $embeddings, logger()); $indexer = new Indexer(new InMemoryLoader($documents), $vectorizer, $store, logger: logger()); $indexer->index($documents); diff --git a/examples/rag/mariadb-openai.php b/examples/rag/mariadb-openai.php index d1fbc541b..a582ae213 100644 --- a/examples/rag/mariadb-openai.php +++ b/examples/rag/mariadb-openai.php @@ -53,7 +53,7 @@ // create embeddings for documents $platform = PlatformFactory::create(env('OPENAI_API_KEY'), http_client()); -$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(), logger()); +$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(Embeddings::TEXT_3_SMALL), logger()); $indexer = new Indexer(new InMemoryLoader($documents), $vectorizer, $store, logger: logger()); $indexer->index($documents); diff --git a/examples/rag/meilisearch.php b/examples/rag/meilisearch.php index b4bd8d7ca..534278c2c 100644 --- a/examples/rag/meilisearch.php +++ b/examples/rag/meilisearch.php @@ -52,7 +52,7 @@ // create embeddings for documents $platform = PlatformFactory::create(env('OPENAI_API_KEY'), http_client()); -$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(), logger()); +$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(Embeddings::TEXT_3_SMALL), logger()); $indexer = new Indexer(new InMemoryLoader($documents), $vectorizer, $store, logger: logger()); $indexer->index($documents); diff --git a/examples/rag/milvus.php b/examples/rag/milvus.php index f9f849fa5..d669caa69 100644 --- a/examples/rag/milvus.php +++ b/examples/rag/milvus.php @@ -53,7 +53,7 @@ // create embeddings for documents $platform = PlatformFactory::create(env('OPENAI_API_KEY'), http_client()); -$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(), logger()); +$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(Embeddings::TEXT_3_SMALL), logger()); $indexer = new Indexer(new InMemoryLoader($documents), $vectorizer, $store, logger: logger()); $indexer->index($documents); diff --git a/examples/rag/mongodb.php b/examples/rag/mongodb.php index 47c5b52c7..050d5a2e1 100644 --- a/examples/rag/mongodb.php +++ b/examples/rag/mongodb.php @@ -51,7 +51,7 @@ // create embeddings for documents $platform = PlatformFactory::create(env('OPENAI_API_KEY')); -$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(), logger()); +$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(Embeddings::TEXT_3_SMALL), logger()); $indexer = new Indexer(new InMemoryLoader($documents), $vectorizer, $store, logger: logger()); $indexer->index($documents); diff --git a/examples/rag/neo4j.php b/examples/rag/neo4j.php index 9010fff62..f4e1a38a8 100644 --- a/examples/rag/neo4j.php +++ b/examples/rag/neo4j.php @@ -55,7 +55,7 @@ // create embeddings for documents $platform = PlatformFactory::create($_SERVER['OPENAI_API_KEY']); -$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(), logger()); +$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(Embeddings::TEXT_3_SMALL), logger()); $indexer = new Indexer(new InMemoryLoader($documents), $vectorizer, $store, logger: logger()); $indexer->index($documents); diff --git a/examples/rag/pinecone.php b/examples/rag/pinecone.php index b4d215309..ee34c05e4 100644 --- a/examples/rag/pinecone.php +++ b/examples/rag/pinecone.php @@ -45,7 +45,7 @@ // create embeddings for documents $platform = PlatformFactory::create(env('OPENAI_API_KEY'), http_client()); -$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(), logger()); +$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(Embeddings::TEXT_3_SMALL), logger()); $indexer = new Indexer(new InMemoryLoader($documents), $vectorizer, $store, logger: logger()); $indexer->index($documents); diff --git a/examples/rag/postgres.php b/examples/rag/postgres.php index 06ac859b2..8fb3ed433 100644 --- a/examples/rag/postgres.php +++ b/examples/rag/postgres.php @@ -52,7 +52,7 @@ // create embeddings for documents $platform = PlatformFactory::create(env('OPENAI_API_KEY'), http_client()); -$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(), logger()); +$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(Embeddings::TEXT_3_SMALL), logger()); $indexer = new Indexer(new InMemoryLoader($documents), $vectorizer, $store, logger: logger()); $indexer->index($documents); diff --git a/examples/rag/qdrant.php b/examples/rag/qdrant.php index 9fa19d5b4..079caf48b 100644 --- a/examples/rag/qdrant.php +++ b/examples/rag/qdrant.php @@ -52,7 +52,7 @@ // create embeddings for documents $platform = PlatformFactory::create(env('OPENAI_API_KEY'), http_client()); -$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(), logger()); +$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(Embeddings::TEXT_3_SMALL), logger()); $indexer = new Indexer(new InMemoryLoader($documents), $vectorizer, $store, logger: logger()); $indexer->index($documents); diff --git a/examples/rag/surrealdb.php b/examples/rag/surrealdb.php index 8f10780ad..ae858ca46 100644 --- a/examples/rag/surrealdb.php +++ b/examples/rag/surrealdb.php @@ -55,7 +55,7 @@ // create embeddings for documents $platform = PlatformFactory::create($_SERVER['OPENAI_API_KEY']); -$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(), logger()); +$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(Embeddings::TEXT_3_SMALL), logger()); $indexer = new Indexer(new InMemoryLoader($documents), $vectorizer, $store, logger: logger()); $indexer->index($documents); diff --git a/examples/rag/typesense.php b/examples/rag/typesense.php index 85b8b4985..232949652 100644 --- a/examples/rag/typesense.php +++ b/examples/rag/typesense.php @@ -52,7 +52,7 @@ // create embeddings for documents $platform = PlatformFactory::create(env('OPENAI_API_KEY'), http_client()); -$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(), logger()); +$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(Embeddings::TEXT_3_SMALL), logger()); $indexer = new Indexer(new InMemoryLoader($documents), $vectorizer, $store, logger: logger()); $indexer->index($documents); diff --git a/examples/rag/weaviate.php b/examples/rag/weaviate.php index d1c017bc4..531871fd2 100644 --- a/examples/rag/weaviate.php +++ b/examples/rag/weaviate.php @@ -52,7 +52,7 @@ // create embeddings for documents $platform = PlatformFactory::create(env('OPENAI_API_KEY'), http_client()); -$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(), logger()); +$vectorizer = new Vectorizer($platform, $embeddings = new Embeddings(Embeddings::TEXT_3_SMALL), logger()); $indexer = new Indexer(new InMemoryLoader($documents), $vectorizer, $store, logger: logger()); $indexer->index($documents); diff --git a/examples/replicate/chat-llama.php b/examples/replicate/chat-llama.php index 1bc1aaec9..c9d6adfa7 100644 --- a/examples/replicate/chat-llama.php +++ b/examples/replicate/chat-llama.php @@ -17,7 +17,7 @@ require_once dirname(__DIR__).'/bootstrap.php'; $platform = PlatformFactory::create(env('REPLICATE_API_KEY'), http_client()); -$model = new Llama(); +$model = new Llama(Llama::V3_1_405B_INSTRUCT); $messages = new MessageBag( Message::forSystem('You are a helpful assistant.'), diff --git a/examples/vertexai/embeddings.php b/examples/vertexai/embeddings.php index e0b1c6dd7..53ffc73eb 100644 --- a/examples/vertexai/embeddings.php +++ b/examples/vertexai/embeddings.php @@ -15,7 +15,7 @@ require_once __DIR__.'/bootstrap.php'; $platform = PlatformFactory::create(env('GOOGLE_CLOUD_LOCATION'), env('GOOGLE_CLOUD_PROJECT'), adc_aware_http_client()); -$embeddings = new Model(); +$embeddings = new Model(Model::GEMINI_EMBEDDING_001); $result = $platform->invoke($embeddings, <<invoke($embeddings, << $options The default options for the model usage */ - public function __construct(string $name = self::GEMINI_2_PRO, array $options = []) + public function __construct(string $name, array $options = []) { $capabilities = [ Capability::INPUT_MESSAGES, diff --git a/src/platform/src/Bridge/Meta/Llama.php b/src/platform/src/Bridge/Meta/Llama.php index d6d50e9e0..2b5485c62 100644 --- a/src/platform/src/Bridge/Meta/Llama.php +++ b/src/platform/src/Bridge/Meta/Llama.php @@ -38,7 +38,7 @@ class Llama extends Model /** * @param array $options */ - public function __construct(string $name = self::V3_1_405B_INSTRUCT, array $options = []) + public function __construct(string $name, array $options = []) { $capabilities = [ Capability::INPUT_MESSAGES, diff --git a/src/platform/src/Bridge/Ollama/Ollama.php b/src/platform/src/Bridge/Ollama/Ollama.php index c31eef3de..5c8f3bfef 100644 --- a/src/platform/src/Bridge/Ollama/Ollama.php +++ b/src/platform/src/Bridge/Ollama/Ollama.php @@ -64,7 +64,7 @@ class Ollama extends Model /** * @param array $options */ - public function __construct(string $name = self::LLAMA_3_2, array $options = []) + public function __construct(string $name, array $options = []) { $capabilities = []; diff --git a/src/platform/src/Bridge/OpenAi/DallE.php b/src/platform/src/Bridge/OpenAi/DallE.php index 40b071cf4..e0cb89b21 100644 --- a/src/platform/src/Bridge/OpenAi/DallE.php +++ b/src/platform/src/Bridge/OpenAi/DallE.php @@ -23,7 +23,7 @@ class DallE extends Model public const DALL_E_3 = 'dall-e-3'; /** @param array $options The default options for the model usage */ - public function __construct(string $name = self::DALL_E_2, array $options = []) + public function __construct(string $name, array $options = []) { $capabilities = [ Capability::INPUT_TEXT, diff --git a/src/platform/src/Bridge/OpenAi/Embeddings.php b/src/platform/src/Bridge/OpenAi/Embeddings.php index 80472e8e2..633b447dd 100644 --- a/src/platform/src/Bridge/OpenAi/Embeddings.php +++ b/src/platform/src/Bridge/OpenAi/Embeddings.php @@ -25,7 +25,7 @@ class Embeddings extends Model /** * @param array $options */ - public function __construct(string $name = self::TEXT_3_SMALL, array $options = []) + public function __construct(string $name, array $options = []) { parent::__construct($name, [], $options); } diff --git a/src/platform/src/Bridge/OpenAi/Whisper.php b/src/platform/src/Bridge/OpenAi/Whisper.php index 24e8ffe10..882d543b1 100644 --- a/src/platform/src/Bridge/OpenAi/Whisper.php +++ b/src/platform/src/Bridge/OpenAi/Whisper.php @@ -24,7 +24,7 @@ class Whisper extends Model /** * @param array $options */ - public function __construct(string $name = self::WHISPER_1, array $options = []) + public function __construct(string $name, array $options = []) { $capabilities = [ Capability::INPUT_AUDIO, diff --git a/src/platform/src/Bridge/VertexAi/Embeddings/Model.php b/src/platform/src/Bridge/VertexAi/Embeddings/Model.php index 99afe8bad..1bab2d68d 100644 --- a/src/platform/src/Bridge/VertexAi/Embeddings/Model.php +++ b/src/platform/src/Bridge/VertexAi/Embeddings/Model.php @@ -29,7 +29,7 @@ final class Model extends BaseModel /** * @see https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/text-embeddings-api for various options */ - public function __construct(string $name = self::GEMINI_EMBEDDING_001, array $options = []) + public function __construct(string $name, array $options = []) { parent::__construct($name, [Capability::INPUT_TEXT, Capability::INPUT_MULTIPLE], $options); } diff --git a/src/platform/src/Bridge/VertexAi/Gemini/Model.php b/src/platform/src/Bridge/VertexAi/Gemini/Model.php index cd49f7ebd..8b83a0622 100644 --- a/src/platform/src/Bridge/VertexAi/Gemini/Model.php +++ b/src/platform/src/Bridge/VertexAi/Gemini/Model.php @@ -30,7 +30,7 @@ final class Model extends BaseModel * * @see https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference for more details */ - public function __construct(string $name = self::GEMINI_2_5_PRO, array $options = []) + public function __construct(string $name, array $options = []) { $capabilities = [ Capability::INPUT_MESSAGES, diff --git a/src/platform/src/Bridge/Voyage/Voyage.php b/src/platform/src/Bridge/Voyage/Voyage.php index 0784b2332..1d991139b 100644 --- a/src/platform/src/Bridge/Voyage/Voyage.php +++ b/src/platform/src/Bridge/Voyage/Voyage.php @@ -36,7 +36,7 @@ class Voyage extends Model /** * @param array{dimensions?: int, input_type?: self::INPUT_TYPE_*, truncation?: bool} $options */ - public function __construct(string $name = self::V3, array $options = []) + public function __construct(string $name, array $options = []) { parent::__construct($name, [Capability::INPUT_MULTIPLE], $options); } diff --git a/src/platform/src/Model.php b/src/platform/src/Model.php index 6594b972b..393b1528e 100644 --- a/src/platform/src/Model.php +++ b/src/platform/src/Model.php @@ -11,12 +11,15 @@ namespace Symfony\AI\Platform; +use Symfony\AI\Platform\Exception\InvalidArgumentException; + /** * @author Christopher Hertel */ class Model { /** + * @param non-empty-string $name * @param Capability[] $capabilities * @param array $options */ @@ -25,8 +28,14 @@ public function __construct( private readonly array $capabilities = [], private readonly array $options = [], ) { + if ('' === trim($name)) { + throw new InvalidArgumentException('Model name cannot be empty.'); + } } + /** + * @return non-empty-string + */ public function getName(): string { return $this->name; diff --git a/src/platform/tests/Bridge/Azure/OpenAi/EmbeddingsModelClientTest.php b/src/platform/tests/Bridge/Azure/OpenAi/EmbeddingsModelClientTest.php index f3cbc4f4c..6e0f5b711 100644 --- a/src/platform/tests/Bridge/Azure/OpenAi/EmbeddingsModelClientTest.php +++ b/src/platform/tests/Bridge/Azure/OpenAi/EmbeddingsModelClientTest.php @@ -77,7 +77,7 @@ public function testItIsSupportingTheCorrectModel() { $client = new EmbeddingsModelClient(new MockHttpClient(), 'test.azure.com', 'deployment', '2023-12-01', 'api-key'); - $this->assertTrue($client->supports(new Embeddings())); + $this->assertTrue($client->supports(new Embeddings(Embeddings::TEXT_3_SMALL))); } public function testItIsExecutingTheCorrectRequest() @@ -93,6 +93,6 @@ public function testItIsExecutingTheCorrectRequest() $httpClient = new MockHttpClient([$resultCallback]); $client = new EmbeddingsModelClient($httpClient, 'test.azure.com', 'embeddings-deployment', '2023-12-01', 'test-api-key'); - $client->request(new Embeddings(), 'Hello, world!'); + $client->request(new Embeddings(Embeddings::TEXT_3_SMALL), 'Hello, world!'); } } diff --git a/src/platform/tests/Bridge/Azure/OpenAi/GptModelClientTest.php b/src/platform/tests/Bridge/Azure/OpenAi/GptModelClientTest.php index a51abffd8..9297cf85b 100644 --- a/src/platform/tests/Bridge/Azure/OpenAi/GptModelClientTest.php +++ b/src/platform/tests/Bridge/Azure/OpenAi/GptModelClientTest.php @@ -77,7 +77,7 @@ public function testItIsSupportingTheCorrectModel() { $client = new GptModelClient(new MockHttpClient(), 'test.azure.com', 'deployment', '2023-12-01', 'api-key'); - $this->assertTrue($client->supports(new Gpt())); + $this->assertTrue($client->supports(new Gpt(Gpt::GPT_4O))); } public function testItIsExecutingTheCorrectRequest() @@ -93,6 +93,6 @@ public function testItIsExecutingTheCorrectRequest() $httpClient = new MockHttpClient([$resultCallback]); $client = new GptModelClient($httpClient, 'test.azure.com', 'gpt-deployment', '2023-12-01', 'test-api-key'); - $client->request(new Gpt(), ['messages' => [['role' => 'user', 'content' => 'Hello']]]); + $client->request(new Gpt(Gpt::GPT_4O), ['messages' => [['role' => 'user', 'content' => 'Hello']]]); } } diff --git a/src/platform/tests/Bridge/Azure/OpenAi/WhisperModelClientTest.php b/src/platform/tests/Bridge/Azure/OpenAi/WhisperModelClientTest.php index 28bea6340..d216d48fc 100644 --- a/src/platform/tests/Bridge/Azure/OpenAi/WhisperModelClientTest.php +++ b/src/platform/tests/Bridge/Azure/OpenAi/WhisperModelClientTest.php @@ -78,7 +78,7 @@ public function testItSupportsWhisperModel() '2023-12-01-preview', 'test-key' ); - $model = new Whisper(); + $model = new Whisper(Whisper::WHISPER_1); $this->assertTrue($client->supports($model)); } @@ -95,7 +95,7 @@ function ($method, $url): MockResponse { ]); $client = new WhisperModelClient($httpClient, 'test.azure.com', 'whspr', '2023-12', 'test-key'); - $client->request(new Whisper(), ['file' => 'audio-data']); + $client->request(new Whisper(Whisper::WHISPER_1), ['file' => 'audio-data']); $this->assertSame(1, $httpClient->getRequestsCount()); } @@ -112,7 +112,7 @@ function ($method, $url): MockResponse { ]); $client = new WhisperModelClient($httpClient, 'test.azure.com', 'whspr', '2023-12', 'test-key'); - $client->request(new Whisper(), ['file' => 'audio-data'], ['task' => Task::TRANSCRIPTION]); + $client->request(new Whisper(Whisper::WHISPER_1), ['file' => 'audio-data'], ['task' => Task::TRANSCRIPTION]); $this->assertSame(1, $httpClient->getRequestsCount()); } @@ -129,7 +129,7 @@ function ($method, $url): MockResponse { ]); $client = new WhisperModelClient($httpClient, 'test.azure.com', 'whspr', '2023-12', 'test-key'); - $client->request(new Whisper(), ['file' => 'audio-data'], ['task' => Task::TRANSLATION]); + $client->request(new Whisper(Whisper::WHISPER_1), ['file' => 'audio-data'], ['task' => Task::TRANSLATION]); $this->assertSame(1, $httpClient->getRequestsCount()); } diff --git a/src/platform/tests/Bridge/Gemini/Contract/AssistantMessageNormalizerTest.php b/src/platform/tests/Bridge/Gemini/Contract/AssistantMessageNormalizerTest.php index 6a4940339..f47a3a618 100644 --- a/src/platform/tests/Bridge/Gemini/Contract/AssistantMessageNormalizerTest.php +++ b/src/platform/tests/Bridge/Gemini/Contract/AssistantMessageNormalizerTest.php @@ -36,7 +36,7 @@ public function testSupportsNormalization() $normalizer = new AssistantMessageNormalizer(); $this->assertTrue($normalizer->supportsNormalization(new AssistantMessage('Hello'), context: [ - Contract::CONTEXT_MODEL => new Gemini(), + Contract::CONTEXT_MODEL => new Gemini(Gemini::GEMINI_2_PRO), ])); $this->assertFalse($normalizer->supportsNormalization('not an assistant message')); } diff --git a/src/platform/tests/Bridge/Gemini/Contract/MessageBagNormalizerTest.php b/src/platform/tests/Bridge/Gemini/Contract/MessageBagNormalizerTest.php index 761e8e7a8..40633db85 100644 --- a/src/platform/tests/Bridge/Gemini/Contract/MessageBagNormalizerTest.php +++ b/src/platform/tests/Bridge/Gemini/Contract/MessageBagNormalizerTest.php @@ -45,7 +45,7 @@ public function testSupportsNormalization() $normalizer = new MessageBagNormalizer(); $this->assertTrue($normalizer->supportsNormalization(new MessageBag(), context: [ - Contract::CONTEXT_MODEL => new Gemini(), + Contract::CONTEXT_MODEL => new Gemini(Gemini::GEMINI_2_PRO), ])); $this->assertFalse($normalizer->supportsNormalization('not a message bag')); } diff --git a/src/platform/tests/Bridge/Gemini/Contract/ToolCallMessageNormalizerTest.php b/src/platform/tests/Bridge/Gemini/Contract/ToolCallMessageNormalizerTest.php index 0395da8df..31c896178 100644 --- a/src/platform/tests/Bridge/Gemini/Contract/ToolCallMessageNormalizerTest.php +++ b/src/platform/tests/Bridge/Gemini/Contract/ToolCallMessageNormalizerTest.php @@ -36,7 +36,7 @@ public function testSupportsNormalization() $normalizer = new ToolCallMessageNormalizer(); $this->assertTrue($normalizer->supportsNormalization(new ToolCallMessage(new ToolCall('', '', []), ''), context: [ - Contract::CONTEXT_MODEL => new Gemini(), + Contract::CONTEXT_MODEL => new Gemini(Gemini::GEMINI_2_PRO), ])); $this->assertFalse($normalizer->supportsNormalization('not a tool call')); } diff --git a/src/platform/tests/Bridge/Gemini/Contract/ToolNormalizerTest.php b/src/platform/tests/Bridge/Gemini/Contract/ToolNormalizerTest.php index 7cf2b0eff..3a84ceeeb 100644 --- a/src/platform/tests/Bridge/Gemini/Contract/ToolNormalizerTest.php +++ b/src/platform/tests/Bridge/Gemini/Contract/ToolNormalizerTest.php @@ -37,7 +37,7 @@ public function testSupportsNormalization() $normalizer = new ToolNormalizer(); $this->assertTrue($normalizer->supportsNormalization(new Tool(new ExecutionReference(ToolNoParams::class), 'test', 'test'), context: [ - Contract::CONTEXT_MODEL => new Gemini(), + Contract::CONTEXT_MODEL => new Gemini(Gemini::GEMINI_2_PRO), ])); $this->assertFalse($normalizer->supportsNormalization('not a tool')); } diff --git a/src/platform/tests/Bridge/Gemini/Contract/UserMessageNormalizerTest.php b/src/platform/tests/Bridge/Gemini/Contract/UserMessageNormalizerTest.php index 5ccf9970d..184fdcc9e 100644 --- a/src/platform/tests/Bridge/Gemini/Contract/UserMessageNormalizerTest.php +++ b/src/platform/tests/Bridge/Gemini/Contract/UserMessageNormalizerTest.php @@ -42,7 +42,7 @@ public function testSupportsNormalization() $normalizer = new UserMessageNormalizer(); $this->assertTrue($normalizer->supportsNormalization(new UserMessage(new Text('Hello')), context: [ - Contract::CONTEXT_MODEL => new Gemini(), + Contract::CONTEXT_MODEL => new Gemini(Gemini::GEMINI_2_PRO), ])); $this->assertFalse($normalizer->supportsNormalization('not a user message')); } diff --git a/src/platform/tests/Bridge/Ollama/Contract/AssistantMessageNormalizerTest.php b/src/platform/tests/Bridge/Ollama/Contract/AssistantMessageNormalizerTest.php index 465b117c0..70c45b511 100644 --- a/src/platform/tests/Bridge/Ollama/Contract/AssistantMessageNormalizerTest.php +++ b/src/platform/tests/Bridge/Ollama/Contract/AssistantMessageNormalizerTest.php @@ -42,7 +42,7 @@ protected function setUp(): void public function testSupportsNormalization() { $this->assertTrue($this->normalizer->supportsNormalization(new AssistantMessage('Hello'), context: [ - Contract::CONTEXT_MODEL => new Ollama(), + Contract::CONTEXT_MODEL => new Ollama(Ollama::LLAMA_3_2), ])); $this->assertFalse($this->normalizer->supportsNormalization(new AssistantMessage('Hello'), context: [ Contract::CONTEXT_MODEL => new Model('any-model'), diff --git a/src/platform/tests/Bridge/Ollama/OllamaClientTest.php b/src/platform/tests/Bridge/Ollama/OllamaClientTest.php index e786bfa33..02d457f76 100644 --- a/src/platform/tests/Bridge/Ollama/OllamaClientTest.php +++ b/src/platform/tests/Bridge/Ollama/OllamaClientTest.php @@ -32,7 +32,7 @@ public function testSupportsModel() { $client = new OllamaClient(new MockHttpClient(), 'http://localhost:1234'); - $this->assertTrue($client->supports(new Ollama())); + $this->assertTrue($client->supports(new Ollama(Ollama::LLAMA_3_2))); $this->assertFalse($client->supports(new Model('any-model'))); } @@ -53,7 +53,7 @@ public function testOutputStructureIsSupported() ], 'http://127.0.0.1:1234'); $client = new OllamaClient($httpClient, 'http://127.0.0.1:1234'); - $response = $client->request(new Ollama(), [ + $response = $client->request(new Ollama(Ollama::LLAMA_3_2), [ 'messages' => [ [ 'role' => 'user', @@ -110,7 +110,7 @@ public function testStreamingIsSupported() ], 'http://127.0.0.1:1234'); $platform = PlatformFactory::create('http://127.0.0.1:1234', $httpClient); - $response = $platform->invoke(new Ollama(), [ + $response = $platform->invoke(new Ollama(Ollama::LLAMA_3_2), [ 'messages' => [ [ 'role' => 'user', diff --git a/src/platform/tests/Bridge/Ollama/OllamaResultConverterTest.php b/src/platform/tests/Bridge/Ollama/OllamaResultConverterTest.php index 791206200..93840f6fa 100644 --- a/src/platform/tests/Bridge/Ollama/OllamaResultConverterTest.php +++ b/src/platform/tests/Bridge/Ollama/OllamaResultConverterTest.php @@ -42,7 +42,7 @@ public function testSupportsLlamaModel() { $converter = new OllamaResultConverter(); - $this->assertTrue($converter->supports(new Ollama())); + $this->assertTrue($converter->supports(new Ollama(Ollama::LLAMA_3_2))); $this->assertFalse($converter->supports(new Model('any-model'))); } diff --git a/src/platform/tests/Bridge/OpenAi/Contract/DocumentNormalizerTest.php b/src/platform/tests/Bridge/OpenAi/Contract/DocumentNormalizerTest.php index 4c9317b0f..6118a37a0 100644 --- a/src/platform/tests/Bridge/OpenAi/Contract/DocumentNormalizerTest.php +++ b/src/platform/tests/Bridge/OpenAi/Contract/DocumentNormalizerTest.php @@ -31,7 +31,7 @@ public function testSupportsNormalization() $normalizer = new DocumentNormalizer(); $this->assertTrue($normalizer->supportsNormalization(new Document('some content', 'application/pdf'), context: [ - Contract::CONTEXT_MODEL => new Gpt(), + Contract::CONTEXT_MODEL => new Gpt(Gpt::GPT_4O), ])); $this->assertFalse($normalizer->supportsNormalization('not a document')); } diff --git a/src/platform/tests/Bridge/OpenAi/DallE/ModelClientTest.php b/src/platform/tests/Bridge/OpenAi/DallE/ModelClientTest.php index c75ca7bfd..febe09b52 100644 --- a/src/platform/tests/Bridge/OpenAi/DallE/ModelClientTest.php +++ b/src/platform/tests/Bridge/OpenAi/DallE/ModelClientTest.php @@ -61,7 +61,7 @@ public function testItIsSupportingTheCorrectModel() { $modelClient = new ModelClient(new MockHttpClient(), 'sk-api-key'); - $this->assertTrue($modelClient->supports(new DallE())); + $this->assertTrue($modelClient->supports(new DallE(DallE::DALL_E_2))); } public function testItIsExecutingTheCorrectRequest() @@ -76,7 +76,7 @@ public function testItIsExecutingTheCorrectRequest() }; $httpClient = new MockHttpClient([$resultCallback]); $modelClient = new ModelClient($httpClient, 'sk-api-key'); - $modelClient->request(new DallE(), 'foo', ['n' => 1, 'response_format' => 'url']); + $modelClient->request(new DallE(DallE::DALL_E_2), 'foo', ['n' => 1, 'response_format' => 'url']); } #[TestWith(['EU', 'https://eu.api.openai.com/v1/images/generations'])] @@ -93,6 +93,6 @@ public function testItUsesCorrectBaseUrl(?string $region, string $expectedUrl) }; $httpClient = new MockHttpClient([$resultCallback]); $modelClient = new ModelClient($httpClient, 'sk-api-key', $region); - $modelClient->request(new DallE(), 'foo', ['n' => 1, 'response_format' => 'url']); + $modelClient->request(new DallE(DallE::DALL_E_2), 'foo', ['n' => 1, 'response_format' => 'url']); } } diff --git a/src/platform/tests/Bridge/OpenAi/DallETest.php b/src/platform/tests/Bridge/OpenAi/DallETest.php index 7448f0c4a..9e55d89c6 100644 --- a/src/platform/tests/Bridge/OpenAi/DallETest.php +++ b/src/platform/tests/Bridge/OpenAi/DallETest.php @@ -22,7 +22,7 @@ final class DallETest extends TestCase { public function testItCreatesDallEWithDefaultSettings() { - $dallE = new DallE(); + $dallE = new DallE(DallE::DALL_E_2); $this->assertSame(DallE::DALL_E_2, $dallE->getName()); $this->assertSame([], $dallE->getOptions()); diff --git a/src/platform/tests/Bridge/OpenAi/Embeddings/ModelClientTest.php b/src/platform/tests/Bridge/OpenAi/Embeddings/ModelClientTest.php index b502df891..8d05d8c75 100644 --- a/src/platform/tests/Bridge/OpenAi/Embeddings/ModelClientTest.php +++ b/src/platform/tests/Bridge/OpenAi/Embeddings/ModelClientTest.php @@ -64,7 +64,7 @@ public function testItIsSupportingTheCorrectModel() { $modelClient = new ModelClient(new MockHttpClient(), 'sk-api-key'); - $this->assertTrue($modelClient->supports(new Embeddings())); + $this->assertTrue($modelClient->supports(new Embeddings(Embeddings::TEXT_3_SMALL))); } public function testItIsExecutingTheCorrectRequest() @@ -79,7 +79,7 @@ public function testItIsExecutingTheCorrectRequest() }; $httpClient = new MockHttpClient([$resultCallback]); $modelClient = new ModelClient($httpClient, 'sk-api-key'); - $modelClient->request(new Embeddings(), 'test text', []); + $modelClient->request(new Embeddings(Embeddings::TEXT_3_SMALL), 'test text', []); } public function testItIsExecutingTheCorrectRequestWithCustomOptions() @@ -109,7 +109,7 @@ public function testItIsExecutingTheCorrectRequestWithArrayInput() }; $httpClient = new MockHttpClient([$resultCallback]); $modelClient = new ModelClient($httpClient, 'sk-api-key'); - $modelClient->request(new Embeddings(), ['text1', 'text2', 'text3'], []); + $modelClient->request(new Embeddings(Embeddings::TEXT_3_SMALL), ['text1', 'text2', 'text3'], []); } #[TestWith(['EU', 'https://eu.api.openai.com/v1/embeddings'])] @@ -126,6 +126,6 @@ public function testItUsesCorrectBaseUrl(?string $region, string $expectedUrl) }; $httpClient = new MockHttpClient([$resultCallback]); $modelClient = new ModelClient($httpClient, 'sk-api-key', $region); - $modelClient->request(new Embeddings(), 'test input', []); + $modelClient->request(new Embeddings(Embeddings::TEXT_3_SMALL), 'test input', []); } } diff --git a/src/platform/tests/Bridge/OpenAi/EmbeddingsTest.php b/src/platform/tests/Bridge/OpenAi/EmbeddingsTest.php index 9bc6e5a02..72f0e1735 100644 --- a/src/platform/tests/Bridge/OpenAi/EmbeddingsTest.php +++ b/src/platform/tests/Bridge/OpenAi/EmbeddingsTest.php @@ -25,7 +25,7 @@ final class EmbeddingsTest extends TestCase { public function testItCreatesEmbeddingsWithDefaultSettings() { - $embeddings = new Embeddings(); + $embeddings = new Embeddings(Embeddings::TEXT_3_SMALL); $this->assertSame(Embeddings::TEXT_3_SMALL, $embeddings->getName()); $this->assertSame([], $embeddings->getOptions()); diff --git a/src/platform/tests/Bridge/OpenAi/Gpt/ModelClientTest.php b/src/platform/tests/Bridge/OpenAi/Gpt/ModelClientTest.php index 99bde7aa9..2549e6058 100644 --- a/src/platform/tests/Bridge/OpenAi/Gpt/ModelClientTest.php +++ b/src/platform/tests/Bridge/OpenAi/Gpt/ModelClientTest.php @@ -81,7 +81,7 @@ public function testItIsSupportingTheCorrectModel() { $modelClient = new ModelClient(new MockHttpClient(), 'sk-api-key'); - $this->assertTrue($modelClient->supports(new Gpt())); + $this->assertTrue($modelClient->supports(new Gpt(Gpt::GPT_4O))); } public function testItIsExecutingTheCorrectRequest() @@ -96,7 +96,7 @@ public function testItIsExecutingTheCorrectRequest() }; $httpClient = new MockHttpClient([$resultCallback]); $modelClient = new ModelClient($httpClient, 'sk-api-key'); - $modelClient->request(new Gpt(), ['model' => 'gpt-4o', 'messages' => [['role' => 'user', 'content' => 'test message']]], ['temperature' => 1]); + $modelClient->request(new Gpt(Gpt::GPT_4O), ['model' => 'gpt-4o', 'messages' => [['role' => 'user', 'content' => 'test message']]], ['temperature' => 1]); } public function testItIsExecutingTheCorrectRequestWithArrayPayload() @@ -111,7 +111,7 @@ public function testItIsExecutingTheCorrectRequestWithArrayPayload() }; $httpClient = new MockHttpClient([$resultCallback]); $modelClient = new ModelClient($httpClient, 'sk-api-key'); - $modelClient->request(new Gpt(), ['model' => 'gpt-4o', 'messages' => [['role' => 'user', 'content' => 'Hello']]], ['temperature' => 0.7]); + $modelClient->request(new Gpt(Gpt::GPT_4O), ['model' => 'gpt-4o', 'messages' => [['role' => 'user', 'content' => 'Hello']]], ['temperature' => 0.7]); } #[TestWith(['EU', 'https://eu.api.openai.com/v1/chat/completions'])] @@ -128,6 +128,6 @@ public function testItUsesCorrectBaseUrl(?string $region, string $expectedUrl) }; $httpClient = new MockHttpClient([$resultCallback]); $modelClient = new ModelClient($httpClient, 'sk-api-key', $region); - $modelClient->request(new Gpt(), ['messages' => []], []); + $modelClient->request(new Gpt(Gpt::GPT_4O), ['messages' => []], []); } } diff --git a/src/platform/tests/Bridge/OpenAi/GptTest.php b/src/platform/tests/Bridge/OpenAi/GptTest.php index d78261639..eaa2c029c 100644 --- a/src/platform/tests/Bridge/OpenAi/GptTest.php +++ b/src/platform/tests/Bridge/OpenAi/GptTest.php @@ -25,7 +25,7 @@ final class GptTest extends TestCase { public function testItCreatesGptWithDefaultSettings() { - $gpt = new Gpt(); + $gpt = new Gpt(Gpt::GPT_4O); $this->assertSame(Gpt::GPT_4O, $gpt->getName()); $this->assertSame([], $gpt->getOptions()); diff --git a/src/platform/tests/Bridge/OpenAi/Whisper/ModelClientTest.php b/src/platform/tests/Bridge/OpenAi/Whisper/ModelClientTest.php index 0f641c5db..0925f89f6 100644 --- a/src/platform/tests/Bridge/OpenAi/Whisper/ModelClientTest.php +++ b/src/platform/tests/Bridge/OpenAi/Whisper/ModelClientTest.php @@ -58,7 +58,7 @@ public function testItAcceptsValidApiKey() public function testItSupportsWhisperModel() { $client = new ModelClient(new MockHttpClient(), 'sk-test-key'); - $this->assertTrue($client->supports(new Whisper())); + $this->assertTrue($client->supports(new Whisper(Whisper::WHISPER_1))); } public function testItUsesTranscriptionEndpointByDefault() @@ -73,7 +73,7 @@ function ($method, $url): MockResponse { ]); $client = new ModelClient($httpClient, 'sk-test-key'); - $client->request(new Whisper(), ['file' => 'audio-data']); + $client->request(new Whisper(Whisper::WHISPER_1), ['file' => 'audio-data']); $this->assertSame(1, $httpClient->getRequestsCount()); } @@ -90,7 +90,7 @@ function ($method, $url): MockResponse { ]); $client = new ModelClient($httpClient, 'sk-test-key'); - $client->request(new Whisper(), ['file' => 'audio-data'], ['task' => Task::TRANSCRIPTION]); + $client->request(new Whisper(Whisper::WHISPER_1), ['file' => 'audio-data'], ['task' => Task::TRANSCRIPTION]); $this->assertSame(1, $httpClient->getRequestsCount()); } @@ -107,7 +107,7 @@ function ($method, $url): MockResponse { ]); $client = new ModelClient($httpClient, 'sk-test-key'); - $client->request(new Whisper(), ['file' => 'audio-data'], ['task' => Task::TRANSLATION]); + $client->request(new Whisper(Whisper::WHISPER_1), ['file' => 'audio-data'], ['task' => Task::TRANSLATION]); $this->assertSame(1, $httpClient->getRequestsCount()); } @@ -127,7 +127,7 @@ function ($method, $url) use ($expectedUrl): MockResponse { ]); $client = new ModelClient($httpClient, 'sk-test-key', $region); - $client->request(new Whisper(), ['file' => 'audio-data']); + $client->request(new Whisper(Whisper::WHISPER_1), ['file' => 'audio-data']); $this->assertSame(1, $httpClient->getRequestsCount()); } @@ -147,7 +147,7 @@ function ($method, $url) use ($expectedUrl): MockResponse { ]); $client = new ModelClient($httpClient, 'sk-test-key', $region); - $client->request(new Whisper(), ['file' => 'audio-data'], ['task' => Task::TRANSLATION]); + $client->request(new Whisper(Whisper::WHISPER_1), ['file' => 'audio-data'], ['task' => Task::TRANSLATION]); $this->assertSame(1, $httpClient->getRequestsCount()); } diff --git a/src/platform/tests/Bridge/OpenAi/WhisperTest.php b/src/platform/tests/Bridge/OpenAi/WhisperTest.php index 428efe057..60ce1fd44 100644 --- a/src/platform/tests/Bridge/OpenAi/WhisperTest.php +++ b/src/platform/tests/Bridge/OpenAi/WhisperTest.php @@ -25,7 +25,7 @@ final class WhisperTest extends TestCase { public function testItCreatesWhisperWithDefaultSettings() { - $whisper = new Whisper(); + $whisper = new Whisper(Whisper::WHISPER_1); $this->assertSame(Whisper::WHISPER_1, $whisper->getName()); $this->assertSame([], $whisper->getOptions()); diff --git a/src/platform/tests/Bridge/VertexAi/Contract/AssistantMessageNormalizerTest.php b/src/platform/tests/Bridge/VertexAi/Contract/AssistantMessageNormalizerTest.php index aba754d0e..4b59bc538 100644 --- a/src/platform/tests/Bridge/VertexAi/Contract/AssistantMessageNormalizerTest.php +++ b/src/platform/tests/Bridge/VertexAi/Contract/AssistantMessageNormalizerTest.php @@ -36,7 +36,7 @@ public function testSupportsNormalization() $normalizer = new AssistantMessageNormalizer(); $this->assertTrue($normalizer->supportsNormalization(new AssistantMessage('Hello'), context: [ - Contract::CONTEXT_MODEL => new Model(), + Contract::CONTEXT_MODEL => new Model(Model::GEMINI_2_5_PRO), ])); $this->assertFalse($normalizer->supportsNormalization('not an assistant message')); } diff --git a/src/platform/tests/Bridge/VertexAi/Contract/MessageBagNormalizerTest.php b/src/platform/tests/Bridge/VertexAi/Contract/MessageBagNormalizerTest.php index 608ef99f8..d51473c65 100644 --- a/src/platform/tests/Bridge/VertexAi/Contract/MessageBagNormalizerTest.php +++ b/src/platform/tests/Bridge/VertexAi/Contract/MessageBagNormalizerTest.php @@ -45,7 +45,7 @@ public function testSupportsNormalization() $normalizer = new MessageBagNormalizer(); $this->assertTrue($normalizer->supportsNormalization(new MessageBag(), context: [ - Contract::CONTEXT_MODEL => new Model(), + Contract::CONTEXT_MODEL => new Model(Model::GEMINI_2_5_PRO), ])); $this->assertFalse($normalizer->supportsNormalization('not a message bag')); } diff --git a/src/platform/tests/Bridge/VertexAi/Contract/ToolCallMessageNormalizerTest.php b/src/platform/tests/Bridge/VertexAi/Contract/ToolCallMessageNormalizerTest.php index 0900f05d0..9d27f1216 100644 --- a/src/platform/tests/Bridge/VertexAi/Contract/ToolCallMessageNormalizerTest.php +++ b/src/platform/tests/Bridge/VertexAi/Contract/ToolCallMessageNormalizerTest.php @@ -36,7 +36,7 @@ public function testSupportsNormalization() $normalizer = new ToolCallMessageNormalizer(); $this->assertTrue($normalizer->supportsNormalization(new ToolCallMessage(new ToolCall('', '', []), ''), context: [ - Contract::CONTEXT_MODEL => new Model(), + Contract::CONTEXT_MODEL => new Model(Model::GEMINI_2_5_PRO), ])); $this->assertFalse($normalizer->supportsNormalization('not a tool call')); } diff --git a/src/platform/tests/Bridge/VertexAi/Contract/ToolNormalizerTest.php b/src/platform/tests/Bridge/VertexAi/Contract/ToolNormalizerTest.php index 96c2be25b..d4b824e33 100644 --- a/src/platform/tests/Bridge/VertexAi/Contract/ToolNormalizerTest.php +++ b/src/platform/tests/Bridge/VertexAi/Contract/ToolNormalizerTest.php @@ -37,7 +37,7 @@ public function testSupportsNormalization() $normalizer = new ToolNormalizer(); $this->assertTrue($normalizer->supportsNormalization(new Tool(new ExecutionReference(ToolNoParams::class), 'test', 'test'), context: [ - Contract::CONTEXT_MODEL => new Model(), + Contract::CONTEXT_MODEL => new Model(Model::GEMINI_2_5_PRO), ])); $this->assertFalse($normalizer->supportsNormalization('not a tool')); } diff --git a/src/platform/tests/Bridge/VertexAi/Contract/UserMessageNormalizerTest.php b/src/platform/tests/Bridge/VertexAi/Contract/UserMessageNormalizerTest.php index a640c3590..378fd75a3 100644 --- a/src/platform/tests/Bridge/VertexAi/Contract/UserMessageNormalizerTest.php +++ b/src/platform/tests/Bridge/VertexAi/Contract/UserMessageNormalizerTest.php @@ -42,7 +42,7 @@ public function testSupportsNormalization() $normalizer = new UserMessageNormalizer(); $this->assertTrue($normalizer->supportsNormalization(new UserMessage(new Text('Hello')), context: [ - Contract::CONTEXT_MODEL => new Model(), + Contract::CONTEXT_MODEL => new Model(Model::GEMINI_2_5_PRO), ])); $this->assertFalse($normalizer->supportsNormalization('not a user message')); } diff --git a/src/platform/tests/Contract/Normalizer/Message/MessageBagNormalizerTest.php b/src/platform/tests/Contract/Normalizer/Message/MessageBagNormalizerTest.php index e5a295959..7dd2cabd7 100644 --- a/src/platform/tests/Contract/Normalizer/Message/MessageBagNormalizerTest.php +++ b/src/platform/tests/Contract/Normalizer/Message/MessageBagNormalizerTest.php @@ -95,7 +95,7 @@ public function testNormalizeWithModel() $innerNormalizer = $this->createMock(NormalizerInterface::class); $innerNormalizer->expects($this->once()) ->method('normalize') - ->with($messages, null, [Contract::CONTEXT_MODEL => new Gpt()]) + ->with($messages, null, [Contract::CONTEXT_MODEL => new Gpt(Gpt::GPT_4O)]) ->willReturn([ ['role' => 'system', 'content' => 'You are a helpful assistant'], ['role' => 'user', 'content' => 'Hello'], @@ -112,7 +112,7 @@ public function testNormalizeWithModel() ]; $this->assertSame($expected, $this->normalizer->normalize($messageBag, context: [ - Contract::CONTEXT_MODEL => new Gpt(), + Contract::CONTEXT_MODEL => new Gpt(Gpt::GPT_4O), ])); } } diff --git a/src/platform/tests/ContractTest.php b/src/platform/tests/ContractTest.php index 111ee40c3..2b717ec82 100644 --- a/src/platform/tests/ContractTest.php +++ b/src/platform/tests/ContractTest.php @@ -83,7 +83,7 @@ public function testCreateRequestPayload(Model $model, array|string|object $inpu public static function providePayloadTestCases(): iterable { yield 'MessageBag with Gpt' => [ - 'model' => new Gpt(), + 'model' => new Gpt(Gpt::GPT_4O), 'input' => new MessageBag( Message::forSystem('System message'), Message::ofUser('User message'), @@ -101,7 +101,7 @@ public static function providePayloadTestCases(): iterable $audio = Audio::fromFile(\dirname(__DIR__, 3).'/fixtures/audio.mp3'); yield 'Audio within MessageBag with Gpt' => [ - 'model' => new Gpt(), + 'model' => new Gpt(Gpt::GPT_4O), 'input' => new MessageBag(Message::ofUser('What is this recording about?', $audio)), 'expected' => [ 'messages' => [ @@ -125,7 +125,7 @@ public static function providePayloadTestCases(): iterable $image = Image::fromFile(\dirname(__DIR__, 3).'/fixtures/image.jpg'); yield 'Image within MessageBag with Gpt' => [ - 'model' => new Gpt(), + 'model' => new Gpt(Gpt::GPT_4O), 'input' => new MessageBag( Message::forSystem('You are an image analyzer bot that helps identify the content of images.'), Message::ofUser('Describe the image as a comedian would do it.', $image), @@ -149,7 +149,7 @@ public static function providePayloadTestCases(): iterable ]; yield 'ImageUrl within MessageBag with Gpt' => [ - 'model' => new Gpt(), + 'model' => new Gpt(Gpt::GPT_4O), 'input' => new MessageBag( Message::forSystem('You are an image analyzer bot that helps identify the content of images.'), Message::ofUser('Describe the image as a comedian would do it.', new ImageUrl('https://example.com/image.jpg')), @@ -173,13 +173,13 @@ public static function providePayloadTestCases(): iterable ]; yield 'Text Input with Embeddings' => [ - 'model' => new Embeddings(), + 'model' => new Embeddings(Embeddings::TEXT_3_SMALL), 'input' => 'This is a test input.', 'expected' => 'This is a test input.', ]; yield 'Longer Conversation with Gpt' => [ - 'model' => new Gpt(), + 'model' => new Gpt(Gpt::GPT_4O), 'input' => new MessageBag( Message::forSystem('My amazing system prompt.'), Message::ofAssistant('It is time to sleep.'), @@ -223,7 +223,7 @@ public function jsonSerialize(): array }; yield 'MessageBag with custom message from Gpt' => [ - 'model' => new Gpt(), + 'model' => new Gpt(Gpt::GPT_4O), 'input' => new MessageBag($customSerializableMessage), 'expected' => [ 'messages' => [ @@ -240,7 +240,7 @@ public function testExtendedContractHandlesWhisper() $audio = Audio::fromFile(\dirname(__DIR__, 3).'/fixtures/audio.mp3'); - $actual = $contract->createRequestPayload(new Whisper(), $audio); + $actual = $contract->createRequestPayload(new Whisper(Whisper::WHISPER_1), $audio); $this->assertArrayHasKey('model', $actual); $this->assertSame('whisper-1', $actual['model']); diff --git a/src/store/tests/Document/VectorizerTest.php b/src/store/tests/Document/VectorizerTest.php index d8eeb3a12..f253a14ec 100644 --- a/src/store/tests/Document/VectorizerTest.php +++ b/src/store/tests/Document/VectorizerTest.php @@ -65,7 +65,7 @@ public function testVectorizeDocumentsWithBatchSupport() $platform = PlatformTestHandler::createPlatform(new VectorResult(...$vectors)); - $model = new Embeddings(); + $model = new Embeddings(Embeddings::TEXT_3_SMALL); $vectorizer = new Vectorizer($platform, $model); $vectorDocuments = $vectorizer->vectorizeTextDocuments($documents); @@ -86,7 +86,7 @@ public function testVectorizeDocumentsWithSingleDocument() $vector = new Vector([0.1, 0.2, 0.3]); $platform = PlatformTestHandler::createPlatform(new VectorResult($vector)); - $model = new Embeddings(); + $model = new Embeddings(Embeddings::TEXT_3_SMALL); $vectorizer = new Vectorizer($platform, $model); $vectorDocuments = $vectorizer->vectorizeTextDocuments([$document]); @@ -101,7 +101,7 @@ public function testVectorizeDocumentsWithSingleDocument() public function testVectorizeEmptyDocumentsArray() { $platform = PlatformTestHandler::createPlatform(new VectorResult()); - $model = new Embeddings(); + $model = new Embeddings(Embeddings::TEXT_3_SMALL); $vectorizer = new Vectorizer($platform, $model); $vectorDocuments = $vectorizer->vectorizeTextDocuments([]); @@ -125,7 +125,7 @@ public function testVectorizeDocumentsPreservesMetadata() ]; $platform = PlatformTestHandler::createPlatform(new VectorResult(...$vectors)); - $model = new Embeddings(); + $model = new Embeddings(Embeddings::TEXT_3_SMALL); $vectorizer = new Vectorizer($platform, $model); $vectorDocuments = $vectorizer->vectorizeTextDocuments($documents); @@ -156,7 +156,7 @@ public function testVectorizeDocumentsPreservesDocumentIds() ]; $platform = PlatformTestHandler::createPlatform(new VectorResult(...$vectors)); - $model = new Embeddings(); + $model = new Embeddings(Embeddings::TEXT_3_SMALL); $vectorizer = new Vectorizer($platform, $model); $vectorDocuments = $vectorizer->vectorizeTextDocuments($documents); @@ -185,7 +185,7 @@ public function testVectorizeVariousDocumentCounts(int $count) $platform = PlatformTestHandler::createPlatform( $count > 0 ? new VectorResult(...$vectors) : new VectorResult() ); - $model = new Embeddings(); + $model = new Embeddings(Embeddings::TEXT_3_SMALL); $vectorizer = new Vectorizer($platform, $model); $vectorDocuments = $vectorizer->vectorizeTextDocuments($documents); @@ -224,7 +224,7 @@ public function testVectorizeDocumentsWithLargeVectors() $vector = new Vector($dimensions); $platform = PlatformTestHandler::createPlatform(new VectorResult($vector)); - $model = new Embeddings(); + $model = new Embeddings(Embeddings::TEXT_3_SMALL); $vectorizer = new Vectorizer($platform, $model); $vectorDocuments = $vectorizer->vectorizeTextDocuments([$document]); @@ -248,7 +248,7 @@ public function testVectorizeDocumentsWithSpecialCharacters() ]; $platform = PlatformTestHandler::createPlatform(new VectorResult(...$vectors)); - $model = new Embeddings(); + $model = new Embeddings(Embeddings::TEXT_3_SMALL); $vectorizer = new Vectorizer($platform, $model); $vectorDocuments = $vectorizer->vectorizeTextDocuments($documents); @@ -327,7 +327,7 @@ public function testVectorizeString() $vector = new Vector([0.1, 0.2, 0.3]); $platform = PlatformTestHandler::createPlatform(new VectorResult($vector)); - $model = new Embeddings(); + $model = new Embeddings(Embeddings::TEXT_3_SMALL); $vectorizer = new Vectorizer($platform, $model); $result = $vectorizer->vectorize($text); @@ -342,7 +342,7 @@ public function testVectorizeStringWithSpecialCharacters() $vector = new Vector([0.5, 0.6, 0.7]); $platform = PlatformTestHandler::createPlatform(new VectorResult($vector)); - $model = new Embeddings(); + $model = new Embeddings(Embeddings::TEXT_3_SMALL); $vectorizer = new Vectorizer($platform, $model); $result = $vectorizer->vectorize($text); @@ -357,7 +357,7 @@ public function testVectorizeEmptyString() $vector = new Vector([0.0, 0.0, 0.0]); $platform = PlatformTestHandler::createPlatform(new VectorResult($vector)); - $model = new Embeddings(); + $model = new Embeddings(Embeddings::TEXT_3_SMALL); $vectorizer = new Vectorizer($platform, $model); $result = $vectorizer->vectorize($text); @@ -371,7 +371,7 @@ public function testVectorizeStringThrowsExceptionWhenNoVectorReturned() $text = 'Test string'; $platform = PlatformTestHandler::createPlatform(new VectorResult()); - $model = new Embeddings(); + $model = new Embeddings(Embeddings::TEXT_3_SMALL); $vectorizer = new Vectorizer($platform, $model); @@ -400,7 +400,7 @@ public function testVectorizeTextDocumentsPassesOptionsToInvoke() ) ->willReturn(new ResultPromise(fn () => new VectorResult($vector), $this->createMock(RawResultInterface::class))); - $model = new Embeddings(); + $model = new Embeddings(Embeddings::TEXT_3_SMALL); $vectorizer = new Vectorizer($platform, $model); $result = $vectorizer->vectorizeTextDocuments($documents, $options); @@ -427,7 +427,7 @@ public function testVectorizeTextDocumentsWithEmptyOptions() ) ->willReturn(new ResultPromise(fn () => new VectorResult($vector), $this->createMock(RawResultInterface::class))); - $model = new Embeddings(); + $model = new Embeddings(Embeddings::TEXT_3_SMALL); $vectorizer = new Vectorizer($platform, $model); $result = $vectorizer->vectorizeTextDocuments($documents); @@ -452,7 +452,7 @@ public function testVectorizeStringPassesOptionsToInvoke() ) ->willReturn(new ResultPromise(fn () => new VectorResult($vector), $this->createMock(RawResultInterface::class))); - $model = new Embeddings(); + $model = new Embeddings(Embeddings::TEXT_3_SMALL); $vectorizer = new Vectorizer($platform, $model); $result = $vectorizer->vectorize($text, $options); @@ -475,7 +475,7 @@ public function testVectorizeStringWithEmptyOptions() ) ->willReturn(new ResultPromise(fn () => new VectorResult($vector), $this->createMock(RawResultInterface::class))); - $model = new Embeddings(); + $model = new Embeddings(Embeddings::TEXT_3_SMALL); $vectorizer = new Vectorizer($platform, $model); $result = $vectorizer->vectorize($text); diff --git a/src/store/tests/IndexerTest.php b/src/store/tests/IndexerTest.php index 893f4ca9f..ea8e75516 100644 --- a/src/store/tests/IndexerTest.php +++ b/src/store/tests/IndexerTest.php @@ -51,7 +51,7 @@ public function testIndexSingleDocument() $document = new TextDocument($id = Uuid::v4(), 'Test content'); $vector = new Vector([0.1, 0.2, 0.3]); $loader = new InMemoryLoader([$document]); - $vectorizer = new Vectorizer(PlatformTestHandler::createPlatform(new VectorResult($vector)), new Embeddings()); + $vectorizer = new Vectorizer(PlatformTestHandler::createPlatform(new VectorResult($vector)), new Embeddings(Embeddings::TEXT_3_SMALL)); $indexer = new Indexer($loader, $vectorizer, $store = new TestStore()); $indexer->index(); @@ -65,7 +65,7 @@ public function testIndexSingleDocument() public function testIndexEmptyDocumentList() { $loader = new InMemoryLoader([]); - $vectorizer = new Vectorizer(PlatformTestHandler::createPlatform(), new Embeddings()); + $vectorizer = new Vectorizer(PlatformTestHandler::createPlatform(), new Embeddings(Embeddings::TEXT_3_SMALL)); $indexer = new Indexer($loader, $vectorizer, $store = new TestStore()); $indexer->index(); @@ -79,7 +79,7 @@ public function testIndexDocumentWithMetadata() $document = new TextDocument($id = Uuid::v4(), 'Test content', $metadata); $vector = new Vector([0.1, 0.2, 0.3]); $loader = new InMemoryLoader([$document]); - $vectorizer = new Vectorizer(PlatformTestHandler::createPlatform(new VectorResult($vector)), new Embeddings()); + $vectorizer = new Vectorizer(PlatformTestHandler::createPlatform(new VectorResult($vector)), new Embeddings(Embeddings::TEXT_3_SMALL)); $indexer = new Indexer($loader, $vectorizer, $store = new TestStore()); $indexer->index(); @@ -99,7 +99,7 @@ public function testWithSource() // InMemoryLoader doesn't use source parameter, so we'll test withSource method's immutability $loader = new InMemoryLoader([$document1]); - $vectorizer = new Vectorizer(PlatformTestHandler::createPlatform(new VectorResult($vector)), new Embeddings()); + $vectorizer = new Vectorizer(PlatformTestHandler::createPlatform(new VectorResult($vector)), new Embeddings(Embeddings::TEXT_3_SMALL)); // Create indexer with initial source $indexer = new Indexer($loader, $vectorizer, $store = new TestStore(), 'source1'); @@ -128,7 +128,7 @@ public function testWithSourceArray() // InMemoryLoader returns all documents regardless of source $loader = new InMemoryLoader([$document1, $document2]); - $vectorizer = new Vectorizer(PlatformTestHandler::createPlatform(new VectorResult($vector)), new Embeddings()); + $vectorizer = new Vectorizer(PlatformTestHandler::createPlatform(new VectorResult($vector)), new Embeddings(Embeddings::TEXT_3_SMALL)); // Create indexer with single source $indexer = new Indexer($loader, $vectorizer, $store1 = new TestStore(), 'source1');