diff --git a/src/Providers/Ollama/Handlers/Embeddings.php b/src/Providers/Ollama/Handlers/Embeddings.php index 475cfadee..95e2a85c0 100644 --- a/src/Providers/Ollama/Handlers/Embeddings.php +++ b/src/Providers/Ollama/Handlers/Embeddings.php @@ -43,6 +43,8 @@ public function handle(Request $request): EmbeddingsResponse protected function sendRequest(Request $request): Response { + $options = Arr::except($request->providerOptions(), ['dimensions', 'keep_alive']); + /** @var Response $response */ $response = $this->client->post( 'api/embed', @@ -51,7 +53,7 @@ protected function sendRequest(Request $request): Response 'input' => $request->inputs(), 'dimensions' => $request->providerOptions('dimensions'), 'keep_alive' => $request->providerOptions('keep_alive'), - 'options' => $request->providerOptions() ?: null, + 'options' => $options ?: null, ]) ); diff --git a/src/Text/Response.php b/src/Text/Response.php index 30ce7fff9..c49cbbc46 100644 --- a/src/Text/Response.php +++ b/src/Text/Response.php @@ -57,7 +57,7 @@ public function toArray(): array 'tool_results' => array_map(fn (ToolResult $toolResult): array => $toolResult->toArray(), $this->toolResults), 'usage' => $this->usage->toArray(), 'meta' => $this->meta->toArray(), - 'messages' => $this->messages->map(fn (Message $message): array => $this->messageToArray($message))->toArray(), + 'messages' => $this->messages->map($this->messageToArray(...))->toArray(), 'additional_content' => $this->additionalContent, 'raw' => $this->raw, ]; diff --git a/tests/Embeddings/ImageEmbeddingsTest.php b/tests/Embeddings/ImageEmbeddingsTest.php index a0146513e..62e1e5159 100644 --- a/tests/Embeddings/ImageEmbeddingsTest.php +++ b/tests/Embeddings/ImageEmbeddingsTest.php @@ -7,7 +7,6 @@ use Prism\Prism\Embeddings\Content; use Prism\Prism\Embeddings\PendingRequest; use Prism\Prism\Embeddings\Request; -use Prism\Prism\Embeddings\Response; use Prism\Prism\Exceptions\PrismException; use Prism\Prism\ValueObjects\Media\Image; @@ -103,7 +102,7 @@ it('throws exception when no embeddings content is provided', function (): void { $pendingRequest = new PendingRequest; - expect(fn (): Response => $pendingRequest->asEmbeddings()) + expect($pendingRequest->asEmbeddings(...)) ->toThrow(PrismException::class, 'Embeddings input is required (text, images, audio, video, documents, or content parts)'); }); diff --git a/tests/Embeddings/MultimodalEmbeddingsTest.php b/tests/Embeddings/MultimodalEmbeddingsTest.php index 6c945235e..06733d24b 100644 --- a/tests/Embeddings/MultimodalEmbeddingsTest.php +++ b/tests/Embeddings/MultimodalEmbeddingsTest.php @@ -7,7 +7,6 @@ use Prism\Prism\Embeddings\Content; use Prism\Prism\Embeddings\PendingRequest; use Prism\Prism\Embeddings\Request; -use Prism\Prism\Embeddings\Response; use Prism\Prism\Exceptions\PrismException; use Prism\Prism\ValueObjects\Media\Audio; use Prism\Prism\ValueObjects\Media\Document; @@ -70,6 +69,6 @@ it('throws exception when no embeddings content is provided', function (): void { $pendingRequest = new PendingRequest; - expect(fn (): Response => $pendingRequest->asEmbeddings()) + expect($pendingRequest->asEmbeddings(...)) ->toThrow(PrismException::class, 'Embeddings input is required (text, images, audio, video, documents, or content parts)'); }); diff --git a/tests/Providers/Ollama/EmbeddingsTest.php b/tests/Providers/Ollama/EmbeddingsTest.php index 3f572ed91..f739c2dd6 100644 --- a/tests/Providers/Ollama/EmbeddingsTest.php +++ b/tests/Providers/Ollama/EmbeddingsTest.php @@ -83,6 +83,13 @@ ->fromInput('The food was delicious and the waiter...') ->asEmbeddings(); + Http::assertSent(function (Request $request): true { + expect($request->data()['dimensions'])->toBe(256); + expect($request->data())->not->toHaveKeys(['options']); + + return true; + }); + $embeddings = json_decode( file_get_contents('tests/Fixtures/ollama/embeddings-with-dimensions-1.json'), true