From 50152272afda6f9463b7fb734e009df0660e31f1 Mon Sep 17 00:00:00 2001 From: TJ Miller Date: Tue, 30 Dec 2025 10:47:19 -0500 Subject: [PATCH 1/2] wip --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 59bd23f..a7bc358 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ phpunit.xml *.code-workspace ray.php CLAUDE.md +.claude/ From 787a34593990a6fcc5dde7ba393605337d83e753 Mon Sep 17 00:00:00 2001 From: TJ Miller Date: Tue, 30 Dec 2025 11:31:39 -0500 Subject: [PATCH 2/2] Updates for lates Prism changes --- composer.json | 4 ++-- src/Bedrock.php | 2 +- src/BedrockServiceProvider.php | 2 +- src/Schemas/Anthropic/AnthropicStructuredHandler.php | 4 ++-- src/Schemas/Anthropic/AnthropicTextHandler.php | 1 + src/Schemas/Anthropic/Maps/MessageMap.php | 10 +++++----- src/Schemas/Anthropic/Maps/ToolMap.php | 2 +- src/Schemas/Cohere/CohereEmbeddingsHandler.php | 2 +- src/Schemas/Converse/ConverseTextHandler.php | 1 + src/Schemas/Converse/Maps/MessageMap.php | 8 ++++---- tests/BedrockServiceProviderTest.php | 2 +- .../Anthropic/AnthropicStructuredHandlerTest.php | 2 +- tests/Schemas/Anthropic/AnthropicTextHandlerTest.php | 2 +- tests/Schemas/Cohere/CohereEmbeddingsTest.php | 2 +- .../Schemas/Converse/ConverseStructuredHandlerTest.php | 2 +- tests/Schemas/Converse/ConverseTextHandlerTest.php | 9 +++------ 16 files changed, 27 insertions(+), 28 deletions(-) diff --git a/composer.json b/composer.json index 2e87153..90535e6 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "php": "^8.2", "laravel/framework": "^11.0|^12.0", "aws/aws-sdk-php": "^3.339", - "prism-php/prism": ">=0.88.0" + "prism-php/prism": ">=0.99.7" }, "config": { "allow-plugins": { @@ -39,7 +39,7 @@ "pestphp/pest-plugin-laravel": "^3.0", "phpstan/extension-installer": "^1.3", "phpstan/phpstan-deprecation-rules": "^2.0", - "rector/rector": "^2.1", + "rector/rector": "2.2.14", "projektgopher/whisky": "^0.7.0", "orchestra/testbench": "^9.4", "mockery/mockery": "^1.6", diff --git a/src/Bedrock.php b/src/Bedrock.php index f141dcb..198ba77 100644 --- a/src/Bedrock.php +++ b/src/Bedrock.php @@ -99,7 +99,7 @@ public function schema(PrismRequest $request): BedrockSchema { $override = $request->providerOptions(); - $override = data_get($override, 'apiSchema', null); + $override = data_get($override, 'apiSchema'); return $override ?? BedrockSchema::fromModelString($request->model()); } diff --git a/src/BedrockServiceProvider.php b/src/BedrockServiceProvider.php index 476db45..8ede8c5 100644 --- a/src/BedrockServiceProvider.php +++ b/src/BedrockServiceProvider.php @@ -35,7 +35,7 @@ public static function getCredentials(array $config): Credentials protected function registerWithPrism(): void { $this->app->extend(PrismManager::class, function (PrismManager $prismManager): \Prism\Prism\PrismManager { - $prismManager->extend(Bedrock::KEY, fn ($app, $config): Bedrock => new Bedrock( + $prismManager->extend(Bedrock::KEY, fn ($app, array $config): Bedrock => new Bedrock( credentials: BedrockServiceProvider::getCredentials($config), region: $config['region'] )); diff --git a/src/Schemas/Anthropic/AnthropicStructuredHandler.php b/src/Schemas/Anthropic/AnthropicStructuredHandler.php index 285ee92..896f7a2 100644 --- a/src/Schemas/Anthropic/AnthropicStructuredHandler.php +++ b/src/Schemas/Anthropic/AnthropicStructuredHandler.php @@ -105,8 +105,8 @@ protected function prepareTempResponse(): void usage: new Usage( promptTokens: data_get($data, 'usage.input_tokens'), completionTokens: data_get($data, 'usage.output_tokens'), - cacheWriteInputTokens: data_get($data, 'usage.cache_creation_input_tokens', null), - cacheReadInputTokens: data_get($data, 'usage.cache_read_input_tokens', null) + cacheWriteInputTokens: data_get($data, 'usage.cache_creation_input_tokens'), + cacheReadInputTokens: data_get($data, 'usage.cache_read_input_tokens') ), meta: new Meta( id: data_get($data, 'id'), diff --git a/src/Schemas/Anthropic/AnthropicTextHandler.php b/src/Schemas/Anthropic/AnthropicTextHandler.php index 5033b62..a17ca7f 100644 --- a/src/Schemas/Anthropic/AnthropicTextHandler.php +++ b/src/Schemas/Anthropic/AnthropicTextHandler.php @@ -155,6 +155,7 @@ protected function addStep(Request $request, array $toolResults = []): void finishReason: $this->tempResponse->finishReason, toolCalls: $this->tempResponse->toolCalls, toolResults: $toolResults, + providerToolCalls: [], usage: $this->tempResponse->usage, meta: $this->tempResponse->meta, messages: $request->messages(), diff --git a/src/Schemas/Anthropic/Maps/MessageMap.php b/src/Schemas/Anthropic/Maps/MessageMap.php index c8cc9f0..4cbfa48 100644 --- a/src/Schemas/Anthropic/Maps/MessageMap.php +++ b/src/Schemas/Anthropic/Maps/MessageMap.php @@ -28,7 +28,7 @@ public static function map(array $messages): array } return array_map( - fn (Message $message): array => self::mapMessage($message), + self::mapMessage(...), $messages ); } @@ -40,7 +40,7 @@ public static function map(array $messages): array public static function mapSystemMessages(array $messages): array { return array_map( - fn (Message $message): array => self::mapSystemMessage($message), + self::mapSystemMessage(...), $messages ); } @@ -65,7 +65,7 @@ protected static function mapSystemMessage(SystemMessage $systemMessage): array { $providerOptions = $systemMessage->providerOptions(); - $cacheType = data_get($providerOptions, 'cacheType', null); + $cacheType = data_get($providerOptions, 'cacheType'); return array_filter([ 'type' => 'text', @@ -96,7 +96,7 @@ protected static function mapUserMessage(UserMessage $message): array { $providerOptions = $message->providerOptions(); - $cacheType = data_get($providerOptions, 'cacheType', null); + $cacheType = data_get($providerOptions, 'cacheType'); $cache_control = $cacheType ? ['type' => $cacheType instanceof BackedEnum ? $cacheType->value : $cacheType] : null; if ($message->documents() !== []) { @@ -123,7 +123,7 @@ protected static function mapAssistantMessage(AssistantMessage $message): array { $providerOptions = $message->providerOptions(); - $cacheType = data_get($providerOptions, 'cacheType', null); + $cacheType = data_get($providerOptions, 'cacheType'); $content = []; diff --git a/src/Schemas/Anthropic/Maps/ToolMap.php b/src/Schemas/Anthropic/Maps/ToolMap.php index 26ff68c..c51f4cc 100644 --- a/src/Schemas/Anthropic/Maps/ToolMap.php +++ b/src/Schemas/Anthropic/Maps/ToolMap.php @@ -16,7 +16,7 @@ class ToolMap public static function map(array $tools): array { return array_map(function (PrismTool $tool): array { - $cacheType = data_get($tool->providerOptions(), 'cacheType', null); + $cacheType = data_get($tool->providerOptions(), 'cacheType'); return array_filter([ 'name' => $tool->name(), diff --git a/src/Schemas/Cohere/CohereEmbeddingsHandler.php b/src/Schemas/Cohere/CohereEmbeddingsHandler.php index 5dea71d..09a6fe4 100644 --- a/src/Schemas/Cohere/CohereEmbeddingsHandler.php +++ b/src/Schemas/Cohere/CohereEmbeddingsHandler.php @@ -65,7 +65,7 @@ protected function buildResponse(): EmbeddingsResponse $body = $this->httpResponse->json(); return new EmbeddingsResponse( - embeddings: array_map(fn (array $item): Embedding => Embedding::fromArray($item), data_get($body, 'embeddings', [])), + embeddings: array_map(Embedding::fromArray(...), data_get($body, 'embeddings', [])), usage: new EmbeddingsUsage( tokens: (int) $this->httpResponse->header('X-Amzn-Bedrock-Input-Token-Count') ), diff --git a/src/Schemas/Converse/ConverseTextHandler.php b/src/Schemas/Converse/ConverseTextHandler.php index 2ba6e5e..91505ec 100644 --- a/src/Schemas/Converse/ConverseTextHandler.php +++ b/src/Schemas/Converse/ConverseTextHandler.php @@ -161,6 +161,7 @@ protected function addStep(Request $request, array $toolResults = []): void finishReason: $this->tempResponse->finishReason, toolCalls: $this->tempResponse->toolCalls, toolResults: $toolResults, + providerToolCalls: [], usage: $this->tempResponse->usage, meta: $this->tempResponse->meta, messages: $request->messages(), diff --git a/src/Schemas/Converse/Maps/MessageMap.php b/src/Schemas/Converse/Maps/MessageMap.php index d3af8f7..6c57bdf 100644 --- a/src/Schemas/Converse/Maps/MessageMap.php +++ b/src/Schemas/Converse/Maps/MessageMap.php @@ -28,7 +28,7 @@ public static function map(array $messages): array } return array_map( - fn (Message $message): array => self::mapMessage($message), + self::mapMessage(...), $messages ); } @@ -44,7 +44,7 @@ public static function mapSystemMessages(array $systemPrompts): array foreach ($systemPrompts as $prompt) { $output[] = self::mapSystemMessage($prompt); - $cacheType = data_get($prompt->providerOptions(), 'cacheType', null); + $cacheType = data_get($prompt->providerOptions(), 'cacheType'); if ($cacheType) { $output[] = ['cachePoint' => ['type' => $cacheType]]; @@ -102,7 +102,7 @@ protected static function mapToolResultMessage(ToolResultMessage $message): arra */ protected static function mapUserMessage(UserMessage $message): array { - $cacheType = data_get($message->providerOptions(), 'cacheType', null); + $cacheType = data_get($message->providerOptions(), 'cacheType'); return [ 'role' => 'user', @@ -120,7 +120,7 @@ protected static function mapUserMessage(UserMessage $message): array */ protected static function mapAssistantMessage(AssistantMessage $message): array { - $cacheType = data_get($message->providerOptions(), 'cacheType', null); + $cacheType = data_get($message->providerOptions(), 'cacheType'); return [ 'role' => 'assistant', diff --git a/tests/BedrockServiceProviderTest.php b/tests/BedrockServiceProviderTest.php index c1cc40e..7d3e2f0 100644 --- a/tests/BedrockServiceProviderTest.php +++ b/tests/BedrockServiceProviderTest.php @@ -4,7 +4,7 @@ use Prism\Bedrock\Bedrock; use Prism\Bedrock\Enums\BedrockSchema; use Prism\Prism\Exceptions\PrismException; -use Prism\Prism\Prism; +use Prism\Prism\Facades\Prism; it('registers itself as a provider with prism', function (): void { $pendingRequest = Prism::text()->using('bedrock', 'test-model'); diff --git a/tests/Schemas/Anthropic/AnthropicStructuredHandlerTest.php b/tests/Schemas/Anthropic/AnthropicStructuredHandlerTest.php index 98712f7..813ea9c 100644 --- a/tests/Schemas/Anthropic/AnthropicStructuredHandlerTest.php +++ b/tests/Schemas/Anthropic/AnthropicStructuredHandlerTest.php @@ -6,7 +6,7 @@ use Illuminate\Http\Client\Request; use Illuminate\Support\Facades\Http; -use Prism\Prism\Prism; +use Prism\Prism\Facades\Prism; use Prism\Prism\Schema\BooleanSchema; use Prism\Prism\Schema\ObjectSchema; use Prism\Prism\Schema\StringSchema; diff --git a/tests/Schemas/Anthropic/AnthropicTextHandlerTest.php b/tests/Schemas/Anthropic/AnthropicTextHandlerTest.php index 3f03fe4..31c0226 100644 --- a/tests/Schemas/Anthropic/AnthropicTextHandlerTest.php +++ b/tests/Schemas/Anthropic/AnthropicTextHandlerTest.php @@ -4,8 +4,8 @@ use Illuminate\Http\Client\Request; use Illuminate\Support\Facades\Http; +use Prism\Prism\Facades\Prism; use Prism\Prism\Facades\Tool; -use Prism\Prism\Prism; use Prism\Prism\ValueObjects\Media\Image; use Prism\Prism\ValueObjects\Messages\SystemMessage; use Prism\Prism\ValueObjects\Messages\UserMessage; diff --git a/tests/Schemas/Cohere/CohereEmbeddingsTest.php b/tests/Schemas/Cohere/CohereEmbeddingsTest.php index d5cbd65..6260fa4 100644 --- a/tests/Schemas/Cohere/CohereEmbeddingsTest.php +++ b/tests/Schemas/Cohere/CohereEmbeddingsTest.php @@ -5,7 +5,7 @@ namespace Tests\Schemas\Cohere; use Illuminate\Support\Facades\Http; -use Prism\Prism\Prism; +use Prism\Prism\Facades\Prism; use Prism\Prism\ValueObjects\Embedding; use Tests\Fixtures\FixtureResponse; diff --git a/tests/Schemas/Converse/ConverseStructuredHandlerTest.php b/tests/Schemas/Converse/ConverseStructuredHandlerTest.php index 63b7337..a959228 100644 --- a/tests/Schemas/Converse/ConverseStructuredHandlerTest.php +++ b/tests/Schemas/Converse/ConverseStructuredHandlerTest.php @@ -7,7 +7,7 @@ use Illuminate\Http\Client\Request; use Illuminate\Support\Facades\Http; use Prism\Bedrock\Enums\BedrockSchema; -use Prism\Prism\Prism; +use Prism\Prism\Facades\Prism; use Prism\Prism\Schema\BooleanSchema; use Prism\Prism\Schema\ObjectSchema; use Prism\Prism\Schema\StringSchema; diff --git a/tests/Schemas/Converse/ConverseTextHandlerTest.php b/tests/Schemas/Converse/ConverseTextHandlerTest.php index 5284319..e0c8a7a 100644 --- a/tests/Schemas/Converse/ConverseTextHandlerTest.php +++ b/tests/Schemas/Converse/ConverseTextHandlerTest.php @@ -7,8 +7,8 @@ use Illuminate\Http\Client\Request; use Illuminate\Support\Facades\Http; use Prism\Bedrock\Enums\BedrockSchema; +use Prism\Prism\Facades\Prism; use Prism\Prism\Facades\Tool; -use Prism\Prism\Prism; use Prism\Prism\Testing\TextStepFake; use Prism\Prism\Text\ResponseBuilder; use Prism\Prism\ValueObjects\Media\Document; @@ -299,11 +299,8 @@ ->asText(); Http::assertSent(function (Request $request): bool { - expect($request->data())->toMatchArray([ - 'inferenceConfig' => [ - 'temperature' => 0, - 'maxTokens' => 2048, - ], + expect($request->data()['inferenceConfig'])->toMatchArray([ + 'temperature' => 0, ]); return true;