diff --git a/.github/workflows/code-quality.yaml b/.github/workflows/code-quality.yaml index 67d661e85..9e7be91ec 100644 --- a/.github/workflows/code-quality.yaml +++ b/.github/workflows/code-quality.yaml @@ -65,3 +65,7 @@ jobs: source .github/workflows/.utils.sh echo "$PACKAGES" | xargs -n1 | parallel -j +3 "_run_task {} '(cd src/{} && $COMPOSER_UP && $PHPSTAN)'" + + - name: Run PHPStan on examples + run: | + cd examples/ && $COMPOSER_UP && $PHPSTAN diff --git a/examples/composer.json b/examples/composer.json index be2356139..59823e732 100644 --- a/examples/composer.json +++ b/examples/composer.json @@ -30,11 +30,19 @@ "symfony/process": "^6.4 || ^7.0", "symfony/var-dumper": "^6.4 || ^7.0" }, + "require-dev": { + "phpstan/phpstan": "^2.1" + }, "autoload": { "psr-4": { "Symfony\\AI\\Fixtures\\": "../fixtures/" } }, + "autoload-dev": { + "psr-4": { + "Symfony\\AI\\PHPStan\\": "../.phpstan/" + } + }, "config": { "allow-plugins": { "codewithkyrian/platform-package-installer": true, diff --git a/examples/document/splitting.php b/examples/document/splitting.php index c5c2d328a..8cea7e328 100644 --- a/examples/document/splitting.php +++ b/examples/document/splitting.php @@ -18,6 +18,6 @@ $splitter = new TextSplitTransformer(); $source = dirname(__DIR__, 2).'/fixtures/lorem.txt'; -$documents = iterator_to_array($splitter($loader($source))); +$documents = iterator_to_array($splitter->transform($loader->load($source))); dump($documents); diff --git a/examples/phpstan.dist.neon b/examples/phpstan.dist.neon new file mode 100644 index 000000000..d23b0dad1 --- /dev/null +++ b/examples/phpstan.dist.neon @@ -0,0 +1,9 @@ +includes: + - ../.phpstan/extension.neon + +parameters: + level: 6 + paths: + - ./ + excludePaths: + - vendor diff --git a/examples/rag/cache.php b/examples/rag/cache.php index eebdfe3bf..6b5270f82 100644 --- a/examples/rag/cache.php +++ b/examples/rag/cache.php @@ -34,6 +34,7 @@ $store = new CacheStore(new ArrayAdapter()); // create embeddings and documents +$documents = []; foreach (Movies::all() as $i => $movie) { $documents[] = new TextDocument( id: Uuid::v4(), diff --git a/examples/rag/chromadb.php b/examples/rag/chromadb.php index 676d464e0..9eed9fe23 100644 --- a/examples/rag/chromadb.php +++ b/examples/rag/chromadb.php @@ -34,7 +34,7 @@ $store = new Store( (new Codewithkyrian\ChromaDB\Factory()) ->withHost(env('CHROMADB_HOST')) - ->withPort(env('CHROMADB_PORT')) + ->withPort((int) env('CHROMADB_PORT')) ->connect(), 'movies', ); diff --git a/examples/rag/in-memory.php b/examples/rag/in-memory.php index 169620dd6..7f66cd325 100644 --- a/examples/rag/in-memory.php +++ b/examples/rag/in-memory.php @@ -33,6 +33,7 @@ $store = new InMemoryStore(); // create embeddings and documents +$documents = []; foreach (Movies::all() as $i => $movie) { $documents[] = new TextDocument( id: Uuid::v4(), diff --git a/examples/rag/mariadb-gemini.php b/examples/rag/mariadb-gemini.php index fa82ebe1b..ec64e6e51 100644 --- a/examples/rag/mariadb-gemini.php +++ b/examples/rag/mariadb-gemini.php @@ -40,6 +40,7 @@ ); // create embeddings and documents +$documents = []; foreach (Movies::all() as $i => $movie) { $documents[] = new TextDocument( id: Uuid::v4(), diff --git a/examples/rag/mariadb-openai.php b/examples/rag/mariadb-openai.php index e50870152..d1fbc541b 100644 --- a/examples/rag/mariadb-openai.php +++ b/examples/rag/mariadb-openai.php @@ -39,6 +39,7 @@ ); // create embeddings and documents +$documents = []; foreach (Movies::all() as $i => $movie) { $documents[] = new TextDocument( id: Uuid::v4(), diff --git a/examples/rag/mongodb.php b/examples/rag/mongodb.php index a3abca415..47c5b52c7 100644 --- a/examples/rag/mongodb.php +++ b/examples/rag/mongodb.php @@ -40,6 +40,7 @@ ); // create embeddings and documents +$documents = []; foreach (Movies::all() as $movie) { $documents[] = new TextDocument( id: Uuid::v4(), diff --git a/examples/rag/pinecone.php b/examples/rag/pinecone.php index 881a115be..b4d215309 100644 --- a/examples/rag/pinecone.php +++ b/examples/rag/pinecone.php @@ -34,6 +34,7 @@ $store = new Store(Pinecone::client(env('PINECONE_API_KEY'), env('PINECONE_HOST'))); // create embeddings and documents +$documents = []; foreach (Movies::all() as $movie) { $documents[] = new TextDocument( id: Uuid::v4(), diff --git a/examples/rag/qdrant.php b/examples/rag/qdrant.php index 5f5725f0e..9fa19d5b4 100644 --- a/examples/rag/qdrant.php +++ b/examples/rag/qdrant.php @@ -41,6 +41,7 @@ $store->setup(); // create embeddings and documents +$documents = []; foreach (Movies::all() as $movie) { $documents[] = new TextDocument( id: Uuid::v4(), diff --git a/examples/vertexai/bootstrap.php b/examples/vertexai/bootstrap.php index 081c7d719..daa3f8ae0 100644 --- a/examples/vertexai/bootstrap.php +++ b/examples/vertexai/bootstrap.php @@ -20,7 +20,7 @@ function adc_aware_http_client(): HttpClientInterface { $credentials = ApplicationDefaultCredentials::getCredentials(['https://www.googleapis.com/auth/cloud-platform']); $httpClient = HttpClient::create([ - 'auth_bearer' => $credentials?->fetchAuthToken()['access_token'] ?? null, + 'auth_bearer' => $credentials->fetchAuthToken()['access_token'] ?? null, ]); if ($httpClient instanceof LoggerAwareInterface) {