Skip to content

Commit f9be079

Browse files
committed
minor #414 [Examples] Add and use print_vectors() function (OskarStark)
This PR was squashed before being merged into the main branch. Discussion ---------- [Examples] Add and use `print_vectors()` function | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Docs? | no | Issues | -- | License | MIT Commits ------- 5339140 [Examples] Add and use `print_vectors()` function
2 parents 3fc2ab1 + 5339140 commit f9be079

File tree

9 files changed

+17
-8
lines changed

9 files changed

+17
-8
lines changed

examples/azure/embeddings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@
2929
country was very peaceful and prosperous. The people lived happily ever after.
3030
TEXT);
3131

32-
echo 'Dimensions: '.$result->asVectors()[0]->getDimensions().\PHP_EOL;
32+
print_vectors($result);

examples/bootstrap.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Psr\Log\LoggerInterface;
1414
use Symfony\AI\Platform\Metadata\Metadata;
1515
use Symfony\AI\Platform\Metadata\TokenUsage;
16+
use Symfony\AI\Platform\Result\ResultPromise;
1617
use Symfony\Component\Console\Logger\ConsoleLogger;
1718
use Symfony\Component\Console\Output\ConsoleOutput;
1819
use Symfony\Component\Dotenv\Dotenv;
@@ -71,3 +72,11 @@ function print_token_usage(Metadata $metadata): void
7172
echo 'Remaining tokens: '.$tokenUsage->remainingTokens.\PHP_EOL;
7273
echo 'Utilized tokens: '.$tokenUsage->totalTokens.\PHP_EOL;
7374
}
75+
76+
function print_vectors(ResultPromise $result): void
77+
{
78+
assert([] !== $result->asVectors());
79+
assert(array_key_exists(0, $result->asVectors()));
80+
81+
echo 'Dimensions: '.$result->asVectors()[0]->getDimensions().\PHP_EOL;
82+
}

examples/gemini/embeddings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323
country was very peaceful and prosperous. The people lived happily ever after.
2424
TEXT);
2525

26-
echo 'Dimensions: '.$result->asVectors()[0]->getDimensions().\PHP_EOL;
26+
print_vectors($result);

examples/huggingface/feature-extraction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
'task' => Task::FEATURE_EXTRACTION,
2323
]);
2424

25-
echo 'Dimensions: '.$result->asVectors()[0]->getDimensions().\PHP_EOL;
25+
print_vectors($result);

examples/misc/parallel-embeddings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@
2828

2929
echo 'Waiting for the responses ...'.\PHP_EOL;
3030
foreach ($results as $result) {
31-
echo 'Dimensions: '.$result->asVectors()[0]->getDimensions().\PHP_EOL;
31+
print_vectors($result);
3232
}

examples/mistral/embeddings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
salt. The goal was to prevent deficiencies and promote better health in the population.
2525
TEXT);
2626

27-
echo 'Dimensions: '.$result->asVectors()[0]->getDimensions().\PHP_EOL;
27+
print_vectors($result);

examples/openai/embeddings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323
country was very peaceful and prosperous. The people lived happily ever after.
2424
TEXT);
2525

26-
echo 'Dimensions: '.$result->asVectors()[0]->getDimensions().\PHP_EOL;
26+
print_vectors($result);

examples/vertexai/embeddings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323
country was very peaceful and prosperous. The people lived happily ever after.
2424
TEXT);
2525

26-
echo 'Dimensions: '.$result->asVectors()[0]->getDimensions().\PHP_EOL;
26+
print_vectors($result);

examples/voyage/embeddings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323
country was very peaceful and prosperous. The people lived happily ever after.
2424
TEXT);
2525

26-
echo 'Dimensions: '.$result->asVectors()[0]->getDimensions().\PHP_EOL;
26+
print_vectors($result);

0 commit comments

Comments
 (0)