Skip to content

Commit ef311ee

Browse files
authored
chore: update Prism (#11)
1 parent 07bf312 commit ef311ee

File tree

15 files changed

+40
-50
lines changed

15 files changed

+40
-50
lines changed

.github/workflows/formatting.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Prism Bedrock resolves the most appropriate API schema from the model string. If
137137

138138
Therefore if you use a model that is not supported by AWS Bedrock Converse, and does not have a specific Prism Bedrock implementation, your request will fail.
139139

140-
If you wish to force Prism Bedrock to use Converse instead of a vendor specific interface, you can do so with `withProviderMeta()`:
140+
If you wish to force Prism Bedrock to use Converse instead of a vendor specific interface, you can do so with `withProviderOptions()`:
141141

142142
```php
143143
use Prism\Prism\Prism;
@@ -146,7 +146,7 @@ use Prism\Bedrock\Enums\BedrockSchema;
146146

147147
$response = Prism::text()
148148
->using(Bedrock::KEY, 'anthropic.claude-3-sonnet-20240229-v1:0')
149-
->withProviderMeta(Bedrock::KEY, ['apiSchema' => BedrockSchema::Converse])
149+
->withProviderOptions(['apiSchema' => BedrockSchema::Converse])
150150
->withPrompt('Explain quantum computing in simple terms')
151151
->asText();
152152

@@ -164,8 +164,8 @@ use Prism\Prism\ValueObjects\Messages\UserMessage;
164164
$response = Prism::text()
165165
->using(Bedrock::KEY, 'anthropic.claude-3-sonnet-20240229-v1:0')
166166
->withMessages([
167-
(new UserMessage('Message with cache breakpoint'))->withProviderMeta('bedrock', ['cacheType' => 'ephemeral']),
168-
(new UserMessage('Message with another cache breakpoint'))->withProviderMeta('bedrock', ['cacheType' => 'ephemeral']),
167+
(new UserMessage('Message with cache breakpoint'))->withProviderOptions(['cacheType' => 'ephemeral']),
168+
(new UserMessage('Message with another cache breakpoint'))->withProviderOptions(['cacheType' => 'ephemeral']),
169169
new UserMessage('Compare the last two messages.')
170170
])
171171
->asText();

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"php": "^8.3",
2323
"laravel/framework": "^11.0|^12.0",
2424
"aws/aws-sdk-php": "^3.339",
25-
"prism-php/prism": ">=0.61.0"
25+
"prism-php/prism": ">=0.63.0"
2626
},
2727
"config": {
2828
"allow-plugins": {

src/Bedrock.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function stream(TextRequest $request): Generator
105105

106106
public function schema(PrismRequest $request): BedrockSchema
107107
{
108-
$override = $request->providerMeta('bedrock');
108+
$override = $request->providerOptions();
109109

110110
$override = data_get($override, 'apiSchema', null);
111111

@@ -127,7 +127,7 @@ protected function client(TextRequest|StructuredRequest|EmbeddingRequest $reques
127127

128128
$enableCaching = $request instanceof EmbeddingRequest
129129
? false
130-
: $request->providerMeta('bedrock', 'enableCaching') ?? false;
130+
: $request->providerOptions('enableCaching') ?? false;
131131

132132
return Http::acceptJson()
133133
->withHeader('explicitPromptCaching', $enableCaching ? 'enabled' : 'disabled')

src/Schemas/Anthropic/Maps/MessageMap.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Exception;
99
use InvalidArgumentException;
1010
use Prism\Prism\Contracts\Message;
11-
use Prism\Prism\Enums\Provider;
1211
use Prism\Prism\Exceptions\PrismException;
1312
use Prism\Prism\ValueObjects\Messages\AssistantMessage;
1413
use Prism\Prism\ValueObjects\Messages\Support\Image;
@@ -66,9 +65,9 @@ protected static function mapMessage(Message $message): array
6665
*/
6766
protected static function mapSystemMessage(SystemMessage $systemMessage): array
6867
{
69-
$providerMeta = array_merge($systemMessage->providerMeta('bedrock'), $systemMessage->providerMeta(Provider::Anthropic));
68+
$providerOptions = $systemMessage->providerOptions();
7069

71-
$cacheType = data_get($providerMeta, 'cacheType', null);
70+
$cacheType = data_get($providerOptions, 'cacheType', null);
7271

7372
return array_filter([
7473
'type' => 'text',
@@ -97,9 +96,9 @@ protected static function mapToolResultMessage(ToolResultMessage $message): arra
9796
*/
9897
protected static function mapUserMessage(UserMessage $message): array
9998
{
100-
$providerMeta = array_merge($message->providerMeta('bedrock'), $message->providerMeta(Provider::Anthropic));
99+
$providerOptions = $message->providerOptions();
101100

102-
$cacheType = data_get($providerMeta, 'cacheType', null);
101+
$cacheType = data_get($providerOptions, 'cacheType', null);
103102
$cache_control = $cacheType ? ['type' => $cacheType instanceof BackedEnum ? $cacheType->value : $cacheType] : null;
104103

105104
if ($message->documents() !== []) {
@@ -124,9 +123,9 @@ protected static function mapUserMessage(UserMessage $message): array
124123
*/
125124
protected static function mapAssistantMessage(AssistantMessage $message): array
126125
{
127-
$providerMeta = array_merge($message->providerMeta('bedrock'), $message->providerMeta(Provider::Anthropic));
126+
$providerOptions = $message->providerOptions();
128127

129-
$cacheType = data_get($providerMeta, 'cacheType', null);
128+
$cacheType = data_get($providerOptions, 'cacheType', null);
130129

131130
$content = [];
132131

src/Schemas/Anthropic/Maps/ToolMap.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Prism\Bedrock\Schemas\Anthropic\Maps;
66

7-
use Prism\Prism\Enums\Provider;
87
use Prism\Prism\Tool as PrismTool;
98
use UnitEnum;
109

@@ -17,7 +16,7 @@ class ToolMap
1716
public static function map(array $tools): array
1817
{
1918
return array_map(function (PrismTool $tool): array {
20-
$cacheType = data_get($tool->providerMeta(Provider::Anthropic), 'cacheType', null);
19+
$cacheType = data_get($tool->providerOptions(), 'cacheType', null);
2120

2221
return array_filter([
2322
'name' => $tool->name(),

src/Schemas/Cohere/CohereEmbeddingsHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public static function buildPayload(Request $request): array
3939
{
4040
return array_filter([
4141
'texts' => $request->inputs(),
42-
'input_type' => 'search_document', // TODO: Need to PR providerMeta onto embeddings request to allow override.
43-
'truncate' => null, // TODO: Need to PR providerMeta onto embeddings request to allow override. Default for now.
44-
'embedding_types' => null, // TODO: Need to PR providerMeta onto embeddings request to allow override. Default for now.
42+
'input_type' => 'search_document', // TODO: Need to PR providerOptions onto embeddings request to allow override.
43+
'truncate' => null, // TODO: Need to PR providerOptions onto embeddings request to allow override. Default for now.
44+
'embedding_types' => null, // TODO: Need to PR providerOptions onto embeddings request to allow override. Default for now.
4545
]);
4646
}
4747

src/Schemas/Converse/Maps/MessageMap.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static function mapSystemMessages(array $systemPrompts): array
4747
foreach ($systemPrompts as $prompt) {
4848
$output[] = self::mapSystemMessage($prompt);
4949

50-
$cacheType = data_get($prompt->providerMeta('bedrock'), 'cacheType', null);
50+
$cacheType = data_get($prompt->providerOptions(), 'cacheType', null);
5151

5252
if ($cacheType) {
5353
$output[] = ['cachePoint' => ['type' => $cacheType]];
@@ -105,7 +105,7 @@ protected static function mapToolResultMessage(ToolResultMessage $message): arra
105105
*/
106106
protected static function mapUserMessage(UserMessage $message): array
107107
{
108-
$cacheType = data_get($message->providerMeta('bedrock'), 'cacheType', null);
108+
$cacheType = data_get($message->providerOptions(), 'cacheType', null);
109109

110110
return [
111111
'role' => 'user',
@@ -123,7 +123,7 @@ protected static function mapUserMessage(UserMessage $message): array
123123
*/
124124
protected static function mapAssistantMessage(AssistantMessage $message): array
125125
{
126-
$cacheType = data_get($message->providerMeta('bedrock'), 'cacheType', null);
126+
$cacheType = data_get($message->providerOptions(), 'cacheType', null);
127127

128128
return [
129129
'role' => 'assistant',

tests/BedrockServiceProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
Prism::embeddings()
2020
->using('bedrock', 'test-model')
21-
->withProviderMeta('bedrock', ['apiSchema' => BedrockSchema::Anthropic])
21+
->withProviderOptions(['apiSchema' => BedrockSchema::Anthropic])
2222
->fromInput('Hello world')
2323
->asEmbeddings();
2424
})->throws(PrismException::class, 'Prism Bedrock does not support embeddings for the anthropic apiSchema.');

tests/Schemas/Anthropic/AnthropicTextHandlerTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Illuminate\Http\Client\Request;
66
use Illuminate\Support\Facades\Http;
7-
use Prism\Prism\Enums\Provider;
87
use Prism\Prism\Facades\Tool;
98
use Prism\Prism\Prism;
109
use Prism\Prism\ValueObjects\Messages\Support\Image;
@@ -162,9 +161,9 @@
162161

163162
$response = Prism::text()
164163
->using('bedrock', 'anthropic.claude-3-5-haiku-20241022-v1:0')
165-
->withSystemPrompt(new SystemMessage('Old context'))->withProviderMeta(Provider::Anthropic, ['cacheType' => 'ephemeral'])
164+
->withSystemPrompt(new SystemMessage('Old context'))->withProviderOptions(['cacheType' => 'ephemeral'])
166165
->withMessages([
167-
(new UserMessage('New context'))->withProviderMeta(Provider::Anthropic, ['cacheType' => 'ephemeral']),
166+
(new UserMessage('New context'))->withProviderOptions(['cacheType' => 'ephemeral']),
168167
])
169168
->asText();
170169

@@ -188,7 +187,7 @@
188187

189188
Prism::text()
190189
->using('bedrock', 'anthropic.claude-3-5-haiku-20241022-v1:0')
191-
->withProviderMeta('bedrock', ['enableCaching' => true])
190+
->withProviderOptions(['enableCaching' => true])
192191
->withPrompt('Who are you?')
193192
->asText();
194193

0 commit comments

Comments
 (0)