Skip to content
Merged
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
1 change: 1 addition & 0 deletions src/Providers/VoyageAI/Embeddings.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ protected function sendRequest(): void
'model' => $this->request->model(),
'input' => $this->request->inputs(),
'input_type' => $providerOptions['inputType'] ?? null,
'output_dimension' => $providerOptions['outputDimension'] ?? null,
'truncation' => $providerOptions['truncation'] ?? null,
]));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"object":"list","data":[{"object":"embedding","embedding":[0.1,0.2,0.3,0.4],"index":0}],"model":"voyage-3-lite","usage":{"total_tokens":8}}
35 changes: 35 additions & 0 deletions tests/Providers/VoyageAI/EmbeddingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,41 @@
expect($response->usage->tokens)->toBe(7);
});

it('returns embeddings with outputDimension set', function (): void {
FixtureResponse::fakeResponseSequence('*', 'voyageai/embeddings-with-output-dimension');

$response = Prism::embeddings()
->using(Provider::VoyageAI, 'voyage-3-lite')
->fromInput('The food was delicious and the waiter...')
->withProviderOptions(['outputDimension' => 4])
->asEmbeddings();

expect($response->embeddings)->toBeArray();
expect($response->embeddings[0]->embedding)->toHaveCount(4);
expect($response->usage->tokens)->toBe(8);

Http::assertSent(function ($request): bool {
$body = json_decode((string) $request->body(), true);

return $body['output_dimension'] === 4;
});
});

it('does not include output_dimension when not set', function (): void {
FixtureResponse::fakeResponseSequence('*', 'voyageai/embeddings-from-input');

Prism::embeddings()
->using(Provider::VoyageAI, 'voyage-3-lite')
->fromInput('The food was delicious and the waiter...')
->asEmbeddings();

Http::assertSent(function ($request): bool {
$body = json_decode((string) $request->body(), true);

return ! array_key_exists('output_dimension', $body);
});
});

it('throws a PrismRateLimitedException for a 429 response code', function (): void {
Http::fake([
'*' => Http::response(
Expand Down