Skip to content

Commit 465a6c7

Browse files
author
sentiasa
committed
Merge branch 'main' into feat/anthropic-stream-0.51
2 parents 77dcd03 + 04a0aff commit 465a6c7

File tree

13 files changed

+60
-60
lines changed

13 files changed

+60
-60
lines changed

.github/workflows/formatting.yml

+1-11
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
pull_request:
99

1010
env:
11-
phpv: 8.3
11+
phpv: 8.2
1212

1313
jobs:
1414
formatting:
@@ -27,11 +27,6 @@ jobs:
2727
- name: Install composer dependencies
2828
uses: ramsey/composer-install@v3
2929

30-
- name: Install aspell
31-
run: |
32-
sudo apt-get update
33-
sudo apt-get install -y aspell
34-
3530
- name: Run Pint
3631
run: |
3732
vendor/bin/pint
@@ -41,8 +36,3 @@ jobs:
4136
run: |
4237
vendor/bin/rector
4338
git diff --exit-code
44-
45-
- name: Run Peck
46-
run: |
47-
vendor/bin/peck
48-
git diff --exit-code

.github/workflows/phpstan.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
pull_request:
99

1010
env:
11-
phpv: 8.3
11+
phpv: 8.2
1212

1313
jobs:
1414
phpstan:

.github/workflows/tests.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
fail-fast: true
1616
matrix:
1717
os: [ubuntu-latest]
18-
php: [8.3, 8.4]
18+
php: [8.2, 8.3, 8.4]
1919
laravel: [11.*, 12.*]
2020
stability: [prefer-lowest, prefer-stable]
2121
include:
@@ -53,4 +53,4 @@ jobs:
5353
run: composer show -D
5454

5555
- name: Execute tests
56-
run: vendor/bin/pest --ci
56+
run: vendor/bin/pest --parallel

bin/git-hooks/formatting

-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ main() {
1313
_header "Running rector..."
1414
vendor/bin/rector process --no-diffs
1515

16-
_header "Running Peck..."
17-
vendor/bin/peck
18-
1916
files_after_format=$(git diff --name-only --diff-filter=d)
2017

2118
# Find files fixed by pint by comparing file lists before and after pint run

composer.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
],
1717
"require": {
18-
"php": "^8.3",
18+
"php": "^8.2",
1919
"laravel/framework": "^11.0|^12.0"
2020
},
2121
"config": {
@@ -39,7 +39,6 @@
3939
"mockery/mockery": "^1.6",
4040
"symplify/rule-doc-generator-contracts": "^11.2",
4141
"phpstan/phpdoc-parser": "^1.24",
42-
"peckphp/peck": "^0.1.1",
4342
"spatie/laravel-ray": "^1.39"
4443
},
4544
"autoload-dev": {

docs/core-concepts/testing.md

+33-2
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,37 @@ it('can generate structured response', function () {
281281
});
282282
```
283283

284+
## Testing Embeddings
285+
286+
```
287+
use Prism\Prism\Prism;
288+
use Prism\Prism\Enums\Provider;
289+
use Prism\Prism\ValueObjects\Embedding;
290+
use Prism\Prism\ValueObjects\EmbeddingsUsage;
291+
use Prism\Prism\Embeddings\Response as EmbeddingsResponse;
292+
293+
it('can generate embeddings', function () {
294+
$fakeResponse = new EmbeddingsResponse(
295+
embeddings: [new Embedding(array_fill(0, 1536, 0.1))],
296+
usage: new EmbeddingsUsage(
297+
tokens: 10,
298+
)
299+
);
300+
301+
Prism::fake([$fakeResponse]);
302+
303+
$response = Prism::embeddings()
304+
->using(Provider::OpenAI, 'text-embedding-3-small')
305+
->fromInput('Test content for embedding generation.')
306+
->generate();
307+
308+
expect($response->embeddings)->toHaveCount(1)
309+
->and($response->embeddings[0]->embedding)
310+
->toBeArray()
311+
->toHaveCount(1536);
312+
});
313+
```
314+
284315
## Assertions
285316

286317
PrismFake provides several helpful assertion methods:
@@ -294,8 +325,8 @@ $fake->assertCallCount(2);
294325

295326
// Assert detailed request properties
296327
$fake->assertRequest(function ($requests) {
297-
expect($requests[0]->provider)->toBe('anthropic');
298-
expect($requests[0]->model)->toBe('claude-3-sonnet');
328+
expect($requests[0]->provider())->toBe('anthropic');
329+
expect($requests[0]->model())->toBe('claude-3-sonnet');
299330
});
300331

301332
// Assert provider configuration

docs/getting-started/installation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Getting started with Prism is a breeze.
66

77
Before we dive in, make sure your project meets these requirements:
88

9-
- PHP 8.3 or higher
9+
- PHP 8.2 or higher
1010
- Laravel 11.0 or higher
1111

1212
## Step 1: Composer Installation

docs/providers/voyageai.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Prism::embeddings()
2828
->using(Provider::VoyageAI, 'voyage-3-lite')
2929
->fromInput('The food was delicious and the waiter...')
3030
->withProviderMeta(Provider::VoyageAI, ['inputType' => 'query'])
31-
->generate();
31+
->asEmbeddings();
3232
```
3333

3434
For document retrieval:
@@ -41,7 +41,7 @@ Prism::embeddings()
4141
->using(Provider::VoyageAI, 'voyage-3-lite')
4242
->fromInput('The food was delicious and the waiter...')
4343
->withProviderMeta(Provider::VoyageAI, ['inputType' => 'document'])
44-
->generate();
44+
->asEmbeddings();
4545
```
4646

4747
### Truncation
@@ -58,7 +58,5 @@ Prism::embeddings()
5858
->using(Provider::VoyageAI, 'voyage-3-lite')
5959
->fromInput('The food was delicious and the waiter...')
6060
->withProviderMeta(Provider::VoyageAI, ['truncation' => false])
61-
->generate();
61+
->asEmbeddings();
6262
```
63-
64-
### Truncation

peck.json

-21
This file was deleted.

rector.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
ReorderMethodsRector::class,
2020
])
2121
->withSets([
22-
LevelSetList::UP_TO_PHP_83,
22+
LevelSetList::UP_TO_PHP_82,
2323
SetList::CODE_QUALITY,
2424
SetList::DEAD_CODE,
2525
SetList::EARLY_RETURN,

src/Providers/Mistral/Concerns/ValidatesResponse.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ protected function validateResponse(Response $response): void
2424
$data = $response->json();
2525

2626
if (! $data || data_get($data, 'object') === 'error') {
27+
$message = data_get($data, 'message', 'unknown');
28+
2729
throw PrismException::providerResponseError(vsprintf(
2830
'Mistral Error: [%s] %s',
2931
[
3032
data_get($data, 'type', 'unknown'),
31-
data_get($data, 'message', 'unknown'),
33+
is_array($message) ? json_encode($message) : $message,
3234
]
3335
));
3436
}

src/Providers/Mistral/Handlers/Text.php

+13-9
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,19 @@ protected function addStep(array $data, Request $request, ClientResponse $client
132132
protected function sendRequest(Request $request): ClientResponse
133133
{
134134
try {
135-
return $this->client->post('chat/completions', [
136-
'model' => $request->model(),
137-
'messages' => (new MessageMap($request->messages(), $request->systemPrompts()))(),
138-
'tools' => ToolMap::map($request->tools()),
139-
'temperature' => $request->temperature(),
140-
'max_tokens' => $request->maxTokens(),
141-
'top_p' => $request->topP(),
142-
'tool_choice' => ToolChoiceMap::map($request->toolChoice()),
143-
]);
135+
return $this->client->post(
136+
'chat/completions',
137+
array_merge([
138+
'model' => $request->model(),
139+
'messages' => (new MessageMap($request->messages(), $request->systemPrompts()))(),
140+
'max_tokens' => $request->maxTokens(),
141+
], array_filter([
142+
'temperature' => $request->temperature(),
143+
'top_p' => $request->topP(),
144+
'tools' => ToolMap::map($request->tools()),
145+
'tool_choice' => ToolChoiceMap::map($request->toolChoice()),
146+
]))
147+
);
144148
} catch (Throwable $e) {
145149
throw PrismException::providerRequestError($request->model(), $e);
146150
}

src/Providers/OpenAI/Handlers/Text.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function handle(Request $request): Response
5050
$data = $response->json();
5151

5252
$responseMessage = new AssistantMessage(
53-
data_get($data, 'message.content') ?? '',
53+
data_get($data, 'choices.0.message.content') ?? '',
5454
ToolCallMap::map(data_get($data, 'choices.0.message.tool_calls', [])),
5555
);
5656

0 commit comments

Comments
 (0)