|
4 | 4 |
|
5 | 5 | namespace Tests\Schemas\Cohere; |
6 | 6 |
|
| 7 | +use Illuminate\Support\Facades\Http; |
7 | 8 | use Prism\Prism\Prism; |
8 | 9 | use Prism\Prism\ValueObjects\Embedding; |
9 | 10 | use Tests\Fixtures\FixtureResponse; |
|
63 | 64 | expect($response->embeddings[1]->embedding)->toEqual($embeddings[1]->embedding); |
64 | 65 | expect($response->usage->tokens)->toBe(1); |
65 | 66 | }); |
| 67 | + |
| 68 | +it('can set request params', function (): void { |
| 69 | + FixtureResponse::fakeResponseSequence('invoke', 'cohere/generate-embeddings-from-input', [ |
| 70 | + 'X-Amzn-Bedrock-Input-Token-Count' => 4, |
| 71 | + ]); |
| 72 | + |
| 73 | + $response = Prism::embeddings() |
| 74 | + ->using('bedrock', 'cohere.embed-english-v3') |
| 75 | + ->withProviderOptions([ |
| 76 | + 'input_type' => 'search_query', |
| 77 | + 'truncate' => 'RIGHT', |
| 78 | + 'embedding_types' => ['sparse', 'dense'], |
| 79 | + 'output_dimension' => 1536, |
| 80 | + 'some_other_option' => 'should be filtered out', |
| 81 | + ]) |
| 82 | + ->fromInput('Hello, world!') |
| 83 | + ->asEmbeddings(); |
| 84 | + |
| 85 | + $embeddings = json_decode(file_get_contents('tests/Fixtures/cohere/generate-embeddings-from-input-1.json'), true); |
| 86 | + $embeddings = array_map(fn (array $item): Embedding => Embedding::fromArray($item), data_get($embeddings, 'embeddings')); |
| 87 | + |
| 88 | + Http::assertSent(function ($request): bool { |
| 89 | + $body = $request->data(); |
| 90 | + |
| 91 | + return $body['input_type'] === 'search_query' |
| 92 | + && $body['truncate'] === 'RIGHT' |
| 93 | + && $body['embedding_types'] === ['sparse', 'dense'] |
| 94 | + && $body['output_dimension'] === 1536 |
| 95 | + && ! array_key_exists('some_other_option', $body); |
| 96 | + }); |
| 97 | + |
| 98 | + expect($response->embeddings)->toBeArray(); |
| 99 | + expect($response->embeddings[0]->embedding)->toEqual($embeddings[0]->embedding); |
| 100 | + expect($response->usage->tokens)->toBe(4); |
| 101 | +}); |
0 commit comments