From 915a5d0361aef1120b920ee69353b851e6e6a148 Mon Sep 17 00:00:00 2001 From: "P. K. Tharindu" Date: Fri, 8 Aug 2025 10:56:42 +0530 Subject: [PATCH 1/8] fix: correct error message inconsistencies across handlers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix ConverseTextHandler error message that incorrectly referenced 'Anthropic' - Standardize exception types to use PrismException instead of generic Exception - Add consistent provider prefixes to error messages for better debugging - Ensure all error messages correctly identify their respective handlers Fixes: - ConverseTextHandler: 'Anthropic: unknown finish reason' → 'Converse: unknown finish reason' - AnthropicMessageMap: Use PrismException with 'Anthropic:' prefix for consistency - ConverseMessageMap: Use PrismException with 'Converse:' prefix for consistency --- src/Schemas/Anthropic/Maps/MessageMap.php | 7 +++---- src/Schemas/Converse/ConverseTextHandler.php | 2 +- src/Schemas/Converse/Maps/MessageMap.php | 3 +-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Schemas/Anthropic/Maps/MessageMap.php b/src/Schemas/Anthropic/Maps/MessageMap.php index 4f2451b..c8cc9f0 100644 --- a/src/Schemas/Anthropic/Maps/MessageMap.php +++ b/src/Schemas/Anthropic/Maps/MessageMap.php @@ -5,7 +5,6 @@ namespace Prism\Bedrock\Schemas\Anthropic\Maps; use BackedEnum; -use Exception; use Prism\Prism\Contracts\Message; use Prism\Prism\Exceptions\PrismException; use Prism\Prism\ValueObjects\Media\Image; @@ -55,7 +54,7 @@ protected static function mapMessage(Message $message): array UserMessage::class => self::mapUserMessage($message), AssistantMessage::class => self::mapAssistantMessage($message), ToolResultMessage::class => self::mapToolResultMessage($message), - default => throw new Exception('Could not map message type '.$message::class), + default => throw new PrismException('Anthropic: Could not map message type '.$message::class), }; } @@ -101,7 +100,7 @@ protected static function mapUserMessage(UserMessage $message): array $cache_control = $cacheType ? ['type' => $cacheType instanceof BackedEnum ? $cacheType->value : $cacheType] : null; if ($message->documents() !== []) { - throw new Exception('Documents are not yet supported by Anthropic on Bedrock.'); + throw new PrismException('Anthropic: Documents are not yet supported by Anthropic on Bedrock.'); } return [ @@ -129,7 +128,7 @@ protected static function mapAssistantMessage(AssistantMessage $message): array $content = []; if (isset($message->additionalContent['messagePartsWithCitations'])) { - throw new Exception('Citations are not yet supported by Anthropic on Bedrock.'); + throw new PrismException('Anthropic: Citations are not yet supported by Anthropic on Bedrock.'); // TODO: update once citation support is supported by Anthropic on Bedrock // foreach ($message->additionalContent['messagePartsWithCitations'] as $part) { // $content[] = array_filter([ diff --git a/src/Schemas/Converse/ConverseTextHandler.php b/src/Schemas/Converse/ConverseTextHandler.php index eb18aca..8e48db1 100644 --- a/src/Schemas/Converse/ConverseTextHandler.php +++ b/src/Schemas/Converse/ConverseTextHandler.php @@ -59,7 +59,7 @@ public function handle(Request $request): TextResponse return match ($this->tempResponse->finishReason) { FinishReason::ToolCalls => $this->handleToolCalls($request), FinishReason::Stop, FinishReason::Length => $this->handleStop($request), - default => throw new PrismException('Anthropic: unknown finish reason'), + default => throw new PrismException('Converse: unknown finish reason'), }; } diff --git a/src/Schemas/Converse/Maps/MessageMap.php b/src/Schemas/Converse/Maps/MessageMap.php index 5170266..d3af8f7 100644 --- a/src/Schemas/Converse/Maps/MessageMap.php +++ b/src/Schemas/Converse/Maps/MessageMap.php @@ -4,7 +4,6 @@ namespace Prism\Bedrock\Schemas\Converse\Maps; -use Exception; use Prism\Prism\Contracts\Message; use Prism\Prism\Exceptions\PrismException; use Prism\Prism\ValueObjects\Media\Document; @@ -65,7 +64,7 @@ protected static function mapMessage(Message $message): array AssistantMessage::class => self::mapAssistantMessage($message), ToolResultMessage::class => self::mapToolResultMessage($message), SystemMessage::class => self::mapSystemMessage($message), - default => throw new Exception('Could not map message type '.$message::class), + default => throw new PrismException('Converse: Could not map message type '.$message::class), }; } From 666c2159495c3d1c8c9e8cc9c90740db4a323f02 Mon Sep 17 00:00:00 2001 From: "P. K. Tharindu" Date: Fri, 8 Aug 2025 11:32:37 +0530 Subject: [PATCH 2/8] refactor: remove redundant `ExtractsText` trait. --- .../Anthropic/AnthropicStructuredHandler.php | 2 +- .../Anthropic/AnthropicTextHandler.php | 2 +- .../Anthropic/Concerns/ExtractsText.php | 24 ------------------- 3 files changed, 2 insertions(+), 26 deletions(-) delete mode 100644 src/Schemas/Anthropic/Concerns/ExtractsText.php diff --git a/src/Schemas/Anthropic/AnthropicStructuredHandler.php b/src/Schemas/Anthropic/AnthropicStructuredHandler.php index 285ee92..9a589b9 100644 --- a/src/Schemas/Anthropic/AnthropicStructuredHandler.php +++ b/src/Schemas/Anthropic/AnthropicStructuredHandler.php @@ -5,10 +5,10 @@ use Illuminate\Http\Client\Response; use Illuminate\Support\Collection; use Prism\Bedrock\Contracts\BedrockStructuredHandler; -use Prism\Bedrock\Schemas\Anthropic\Concerns\ExtractsText; use Prism\Bedrock\Schemas\Anthropic\Maps\FinishReasonMap; use Prism\Bedrock\Schemas\Anthropic\Maps\MessageMap; use Prism\Prism\Exceptions\PrismException; +use Prism\Prism\Providers\Anthropic\Concerns\ExtractsText; use Prism\Prism\Structured\Request; use Prism\Prism\Structured\Response as StructuredResponse; use Prism\Prism\Structured\ResponseBuilder; diff --git a/src/Schemas/Anthropic/AnthropicTextHandler.php b/src/Schemas/Anthropic/AnthropicTextHandler.php index 5033b62..d881e1a 100644 --- a/src/Schemas/Anthropic/AnthropicTextHandler.php +++ b/src/Schemas/Anthropic/AnthropicTextHandler.php @@ -5,7 +5,6 @@ use Illuminate\Http\Client\Response; use Illuminate\Support\Collection; use Prism\Bedrock\Contracts\BedrockTextHandler; -use Prism\Bedrock\Schemas\Anthropic\Concerns\ExtractsText; use Prism\Bedrock\Schemas\Anthropic\Concerns\ExtractsToolCalls; use Prism\Bedrock\Schemas\Anthropic\Maps\FinishReasonMap; use Prism\Bedrock\Schemas\Anthropic\Maps\MessageMap; @@ -14,6 +13,7 @@ use Prism\Prism\Concerns\CallsTools; use Prism\Prism\Enums\FinishReason; use Prism\Prism\Exceptions\PrismException; +use Prism\Prism\Providers\Anthropic\Concerns\ExtractsText; use Prism\Prism\Text\Request; use Prism\Prism\Text\Response as TextResponse; use Prism\Prism\Text\ResponseBuilder; diff --git a/src/Schemas/Anthropic/Concerns/ExtractsText.php b/src/Schemas/Anthropic/Concerns/ExtractsText.php deleted file mode 100644 index c940a2d..0000000 --- a/src/Schemas/Anthropic/Concerns/ExtractsText.php +++ /dev/null @@ -1,24 +0,0 @@ - $data - */ - protected function extractText(array $data): string - { - return array_reduce( - data_get($data, 'content', []), - function (string $text, array $content): string { - if (data_get($content, 'type') === 'text') { - $text .= data_get($content, 'text'); - } - - return $text; - }, - '' - ); - } -} From 3e2d9576badad8f1a8fca78d41b151e5f3a5a53f Mon Sep 17 00:00:00 2001 From: "P. K. Tharindu" Date: Fri, 8 Aug 2025 12:35:14 +0530 Subject: [PATCH 3/8] feat: extracts text from response content This commit introduces a new trait `ExtractsText` to handle the extraction of text content from the Converse API response. The `ConverseTextHandler` is updated to utilize this trait, replacing the previous hardcoded path with a more robust extraction method. This ensures that the text content is correctly parsed, even when nested within reasoning content. A new test case is added to verify the functionality with reasoning content. --- .../Converse/Concerns/ExtractsText.php | 22 +++++++++++++++++++ src/Schemas/Converse/ConverseTextHandler.php | 5 +++-- ...enerate-text-with-reasoning-content-1.json | 1 + .../Converse/ConverseTextHandlerTest.php | 15 +++++++++++++ 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 src/Schemas/Converse/Concerns/ExtractsText.php create mode 100644 tests/Fixtures/converse/generate-text-with-reasoning-content-1.json diff --git a/src/Schemas/Converse/Concerns/ExtractsText.php b/src/Schemas/Converse/Concerns/ExtractsText.php new file mode 100644 index 0000000..28e344f --- /dev/null +++ b/src/Schemas/Converse/Concerns/ExtractsText.php @@ -0,0 +1,22 @@ + $data + */ + protected function extractText(array $data): string + { + $content = data_get($data, 'output.message.content', []); + + foreach ($content as $item) { + if ($text = data_get($item, 'text')) { + return $text; + } + } + + return ''; + } +} diff --git a/src/Schemas/Converse/ConverseTextHandler.php b/src/Schemas/Converse/ConverseTextHandler.php index 8e48db1..dbec519 100644 --- a/src/Schemas/Converse/ConverseTextHandler.php +++ b/src/Schemas/Converse/ConverseTextHandler.php @@ -5,6 +5,7 @@ use Illuminate\Http\Client\Response; use Illuminate\Support\Collection; use Prism\Bedrock\Contracts\BedrockTextHandler; +use Prism\Bedrock\Schemas\Converse\Concerns\ExtractsText; use Prism\Bedrock\Schemas\Converse\Concerns\ExtractsToolCalls; use Prism\Bedrock\Schemas\Converse\Maps\FinishReasonMap; use Prism\Bedrock\Schemas\Converse\Maps\MessageMap; @@ -26,7 +27,7 @@ class ConverseTextHandler extends BedrockTextHandler { - use CallsTools, ExtractsToolCalls; + use CallsTools, ExtractsText, ExtractsToolCalls; protected TextResponse $tempResponse; @@ -110,6 +111,7 @@ protected function prepareTempResponse(): void $this->tempResponse = new TextResponse( steps: new Collection, text: data_get($data, 'output.message.content.0.text', ''), + messages: new Collection, finishReason: FinishReasonMap::map(data_get($data, 'stopReason')), toolCalls: $this->extractToolCalls($data), toolResults: [], @@ -118,7 +120,6 @@ protected function prepareTempResponse(): void completionTokens: data_get($data, 'usage.outputTokens') ), meta: new Meta(id: '', model: ''), // Not provided in Converse response. - messages: new Collection ); } diff --git a/tests/Fixtures/converse/generate-text-with-reasoning-content-1.json b/tests/Fixtures/converse/generate-text-with-reasoning-content-1.json new file mode 100644 index 0000000..8eabf27 --- /dev/null +++ b/tests/Fixtures/converse/generate-text-with-reasoning-content-1.json @@ -0,0 +1 @@ +{"metrics":{"latencyMs":8274},"output":{"message":{"content":[{"reasoningContent":{"reasoningText":{"text":"We need to respond. The user asks \"Tell me a short story about a brave knight.\" Ask for a short story. Need to follow formatting \"role... content?\". The guideli\n\nThus we produce:\n\nrole: assistant\ncontent: |-\n ... story.\n\nWill ensure it's a short story about a brave knight. Should be creative.\n\nWe can produce a short story of maybe few paragraphs. Likely 3-5 paragraphs.\n\nLet's do.\n\n"}}},{"text":"role: assistant\ncontent: |-\n In the mist‑shrouded kingdom of Eldoria, tales of dragons and dark sorcery were as common as the sunrise. Yet none captured the hearts of the people quite li\n\n Alden had not earned his reputation through grand tournaments or lavish banquets. He grew up as the youngest son of a humble blacksmith, learning the clang o\n\n Without hesitation, Alden strapped his father's modest sword to his belt, took his battered shield—etched with a single oak leaf—and set out into the dying w\n\n At the heart of the forest, beneath a gnarled oak, Alden found the source of the curse: a crystal orb pulsing with black mist. As he approached, a specter of\n\n Light burst forth, bathing the forest in golden hues. Trees unfurled fresh leaves, and the sickly fog dissolved like a dream at dawn. The kingdom rejoiced, a\n\n Sir Alden's legend endured not because he wielded a mighty sword, but because his bravery was rooted in humility and love for his people. And when the wind r"}],"role":"assistant"}},"stopReason":"end_turn","usage":{"inputTokens":21,"outputTokens":765,"totalTokens":786}} \ No newline at end of file diff --git a/tests/Schemas/Converse/ConverseTextHandlerTest.php b/tests/Schemas/Converse/ConverseTextHandlerTest.php index b2b7f1f..0006221 100644 --- a/tests/Schemas/Converse/ConverseTextHandlerTest.php +++ b/tests/Schemas/Converse/ConverseTextHandlerTest.php @@ -33,6 +33,21 @@ expect($response->text)->toBe("I'm an AI system created by a team of inventors at Amazon. My purpose is to assist and provide information to the best of my ability. If you have any questions or need assistance, feel free to ask!"); }); +it('can generate text with reasoning content', function (): void { + FixtureResponse::fakeResponseSequence('converse', 'converse/generate-text-with-reasoning-content'); + + $response = Prism::text() + ->using('bedrock', 'amazon.nova-micro-v1:0') + ->withPrompt('Tell me a short story about a brave knight.') + ->asText(); + + expect($response->usage->promptTokens) + ->toBe(21) + ->and($response->usage->completionTokens)->toBe(765) + ->and($response->text)->toContain('In the mist‑shrouded kingdom of Eldoria') + ->and($response->text)->toContain('Sir Alden\'s legend endured'); +}); + it('can generate text with a system prompt', function (): void { FixtureResponse::fakeResponseSequence('converse', 'converse/generate-text-with-system-prompt'); From 3c8006964eaed9e092c74976cfc987667d6e1ebf Mon Sep 17 00:00:00 2001 From: "P. K. Tharindu" Date: Fri, 8 Aug 2025 13:29:53 +0530 Subject: [PATCH 4/8] test: make the test more realistic with an actual model ID --- tests/Schemas/Converse/ConverseTextHandlerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Schemas/Converse/ConverseTextHandlerTest.php b/tests/Schemas/Converse/ConverseTextHandlerTest.php index 0006221..e583b74 100644 --- a/tests/Schemas/Converse/ConverseTextHandlerTest.php +++ b/tests/Schemas/Converse/ConverseTextHandlerTest.php @@ -37,7 +37,7 @@ FixtureResponse::fakeResponseSequence('converse', 'converse/generate-text-with-reasoning-content'); $response = Prism::text() - ->using('bedrock', 'amazon.nova-micro-v1:0') + ->using('bedrock', 'openai.gpt-oss-120b-1:0') ->withPrompt('Tell me a short story about a brave knight.') ->asText(); From f90babf0fa9547f797dcdd0fe30d9ae00ceef24a Mon Sep 17 00:00:00 2001 From: Chris Bridges Date: Fri, 22 Aug 2025 16:19:36 +0100 Subject: [PATCH 5/8] Re-introduce ExtractsText --- .../Anthropic/AnthropicStructuredHandler.php | 2 +- .../Anthropic/AnthropicTextHandler.php | 2 +- .../Anthropic/Concerns/ExtractsText.php | 24 +++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 src/Schemas/Anthropic/Concerns/ExtractsText.php diff --git a/src/Schemas/Anthropic/AnthropicStructuredHandler.php b/src/Schemas/Anthropic/AnthropicStructuredHandler.php index 9a589b9..285ee92 100644 --- a/src/Schemas/Anthropic/AnthropicStructuredHandler.php +++ b/src/Schemas/Anthropic/AnthropicStructuredHandler.php @@ -5,10 +5,10 @@ use Illuminate\Http\Client\Response; use Illuminate\Support\Collection; use Prism\Bedrock\Contracts\BedrockStructuredHandler; +use Prism\Bedrock\Schemas\Anthropic\Concerns\ExtractsText; use Prism\Bedrock\Schemas\Anthropic\Maps\FinishReasonMap; use Prism\Bedrock\Schemas\Anthropic\Maps\MessageMap; use Prism\Prism\Exceptions\PrismException; -use Prism\Prism\Providers\Anthropic\Concerns\ExtractsText; use Prism\Prism\Structured\Request; use Prism\Prism\Structured\Response as StructuredResponse; use Prism\Prism\Structured\ResponseBuilder; diff --git a/src/Schemas/Anthropic/AnthropicTextHandler.php b/src/Schemas/Anthropic/AnthropicTextHandler.php index d881e1a..5033b62 100644 --- a/src/Schemas/Anthropic/AnthropicTextHandler.php +++ b/src/Schemas/Anthropic/AnthropicTextHandler.php @@ -5,6 +5,7 @@ use Illuminate\Http\Client\Response; use Illuminate\Support\Collection; use Prism\Bedrock\Contracts\BedrockTextHandler; +use Prism\Bedrock\Schemas\Anthropic\Concerns\ExtractsText; use Prism\Bedrock\Schemas\Anthropic\Concerns\ExtractsToolCalls; use Prism\Bedrock\Schemas\Anthropic\Maps\FinishReasonMap; use Prism\Bedrock\Schemas\Anthropic\Maps\MessageMap; @@ -13,7 +14,6 @@ use Prism\Prism\Concerns\CallsTools; use Prism\Prism\Enums\FinishReason; use Prism\Prism\Exceptions\PrismException; -use Prism\Prism\Providers\Anthropic\Concerns\ExtractsText; use Prism\Prism\Text\Request; use Prism\Prism\Text\Response as TextResponse; use Prism\Prism\Text\ResponseBuilder; diff --git a/src/Schemas/Anthropic/Concerns/ExtractsText.php b/src/Schemas/Anthropic/Concerns/ExtractsText.php new file mode 100644 index 0000000..c940a2d --- /dev/null +++ b/src/Schemas/Anthropic/Concerns/ExtractsText.php @@ -0,0 +1,24 @@ + $data + */ + protected function extractText(array $data): string + { + return array_reduce( + data_get($data, 'content', []), + function (string $text, array $content): string { + if (data_get($content, 'type') === 'text') { + $text .= data_get($content, 'text'); + } + + return $text; + }, + '' + ); + } +} From 6106fbe383c490400ab912a2643ad26a6a7d57dc Mon Sep 17 00:00:00 2001 From: Chris Bridges Date: Fri, 3 Oct 2025 13:31:39 +0100 Subject: [PATCH 6/8] use extractText --- src/Schemas/Converse/ConverseTextHandler.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Schemas/Converse/ConverseTextHandler.php b/src/Schemas/Converse/ConverseTextHandler.php index dbec519..2ba6e5e 100644 --- a/src/Schemas/Converse/ConverseTextHandler.php +++ b/src/Schemas/Converse/ConverseTextHandler.php @@ -110,8 +110,7 @@ protected function prepareTempResponse(): void $this->tempResponse = new TextResponse( steps: new Collection, - text: data_get($data, 'output.message.content.0.text', ''), - messages: new Collection, + text: $this->extractText($data), finishReason: FinishReasonMap::map(data_get($data, 'stopReason')), toolCalls: $this->extractToolCalls($data), toolResults: [], @@ -119,7 +118,8 @@ protected function prepareTempResponse(): void promptTokens: data_get($data, 'usage.inputTokens'), completionTokens: data_get($data, 'usage.outputTokens') ), - meta: new Meta(id: '', model: ''), // Not provided in Converse response. + meta: new Meta(id: '', model: ''), + messages: new Collection, // Not provided in Converse response. ); } From 30b56e471b288fc74afb1302a8391a515b8cd416 Mon Sep 17 00:00:00 2001 From: Chris Bridges Date: Fri, 3 Oct 2025 13:38:00 +0100 Subject: [PATCH 7/8] rector fixes --- tests/Schemas/Anthropic/AnthropicStructuredHandlerTest.php | 2 +- tests/Schemas/Anthropic/AnthropicTextHandlerTest.php | 2 +- tests/Schemas/Converse/ConverseStructuredHandlerTest.php | 2 +- tests/Schemas/Converse/ConverseTextHandlerTest.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Schemas/Anthropic/AnthropicStructuredHandlerTest.php b/tests/Schemas/Anthropic/AnthropicStructuredHandlerTest.php index c4b6cde..1b0e8b4 100644 --- a/tests/Schemas/Anthropic/AnthropicStructuredHandlerTest.php +++ b/tests/Schemas/Anthropic/AnthropicStructuredHandlerTest.php @@ -135,7 +135,7 @@ ->usingTemperature(0) ->asStructured(); - Http::assertSent(fn (Request $request): \Pest\Mixins\Expectation|\Pest\Expectation => expect($request->data())->toMatchArray([ + Http::assertSent(fn (Request $request): \Pest\Mixins\Expectation => expect($request->data())->toMatchArray([ 'temperature' => 0, ])); }); diff --git a/tests/Schemas/Anthropic/AnthropicTextHandlerTest.php b/tests/Schemas/Anthropic/AnthropicTextHandlerTest.php index e678916..d3ce83c 100644 --- a/tests/Schemas/Anthropic/AnthropicTextHandlerTest.php +++ b/tests/Schemas/Anthropic/AnthropicTextHandlerTest.php @@ -203,7 +203,7 @@ ->usingTemperature(0) ->asText(); - Http::assertSent(fn (Request $request): \Pest\Mixins\Expectation|\Pest\Expectation => expect($request->data())->toMatchArray([ + Http::assertSent(fn (Request $request): \Pest\Mixins\Expectation => expect($request->data())->toMatchArray([ 'temperature' => 0, ])); }); diff --git a/tests/Schemas/Converse/ConverseStructuredHandlerTest.php b/tests/Schemas/Converse/ConverseStructuredHandlerTest.php index ae3e9d5..810cb26 100644 --- a/tests/Schemas/Converse/ConverseStructuredHandlerTest.php +++ b/tests/Schemas/Converse/ConverseStructuredHandlerTest.php @@ -193,7 +193,7 @@ ->usingTemperature(0) ->asStructured(); - Http::assertSent(fn (Request $request): \Pest\Mixins\Expectation|\Pest\Expectation => expect($request->data())->toMatchArray([ + Http::assertSent(fn (Request $request): \Pest\Mixins\Expectation => expect($request->data())->toMatchArray([ 'inferenceConfig' => [ 'maxTokens' => 2048, 'temperature' => 0, diff --git a/tests/Schemas/Converse/ConverseTextHandlerTest.php b/tests/Schemas/Converse/ConverseTextHandlerTest.php index e583b74..c4c8e97 100644 --- a/tests/Schemas/Converse/ConverseTextHandlerTest.php +++ b/tests/Schemas/Converse/ConverseTextHandlerTest.php @@ -298,7 +298,7 @@ ->usingTemperature(0) ->asText(); - Http::assertSent(fn (Request $request): \Pest\Mixins\Expectation|\Pest\Expectation => expect($request->data())->toMatchArray([ + Http::assertSent(fn (Request $request): \Pest\Mixins\Expectation => expect($request->data())->toMatchArray([ 'inferenceConfig' => [ 'temperature' => 0, 'maxTokens' => 2048, From 49e0021da11ea2efdb947639909662efcd934c0a Mon Sep 17 00:00:00 2001 From: Chris Bridges Date: Fri, 3 Oct 2025 13:48:04 +0100 Subject: [PATCH 8/8] fix rector types issue --- .../AnthropicStructuredHandlerTest.php | 10 +++++++--- .../Anthropic/AnthropicTextHandlerTest.php | 10 +++++++--- .../Converse/ConverseStructuredHandlerTest.php | 18 ++++++++++++------ .../Converse/ConverseTextHandlerTest.php | 16 ++++++++++------ 4 files changed, 36 insertions(+), 18 deletions(-) diff --git a/tests/Schemas/Anthropic/AnthropicStructuredHandlerTest.php b/tests/Schemas/Anthropic/AnthropicStructuredHandlerTest.php index 1b0e8b4..98712f7 100644 --- a/tests/Schemas/Anthropic/AnthropicStructuredHandlerTest.php +++ b/tests/Schemas/Anthropic/AnthropicStructuredHandlerTest.php @@ -135,7 +135,11 @@ ->usingTemperature(0) ->asStructured(); - Http::assertSent(fn (Request $request): \Pest\Mixins\Expectation => expect($request->data())->toMatchArray([ - 'temperature' => 0, - ])); + Http::assertSent(function (Request $request): bool { + expect($request->data())->toMatchArray([ + 'temperature' => 0, + ]); + + return true; + }); }); diff --git a/tests/Schemas/Anthropic/AnthropicTextHandlerTest.php b/tests/Schemas/Anthropic/AnthropicTextHandlerTest.php index d3ce83c..3f03fe4 100644 --- a/tests/Schemas/Anthropic/AnthropicTextHandlerTest.php +++ b/tests/Schemas/Anthropic/AnthropicTextHandlerTest.php @@ -203,7 +203,11 @@ ->usingTemperature(0) ->asText(); - Http::assertSent(fn (Request $request): \Pest\Mixins\Expectation => expect($request->data())->toMatchArray([ - 'temperature' => 0, - ])); + Http::assertSent(function (Request $request): bool { + expect($request->data())->toMatchArray([ + 'temperature' => 0, + ]); + + return true; + }); }); diff --git a/tests/Schemas/Converse/ConverseStructuredHandlerTest.php b/tests/Schemas/Converse/ConverseStructuredHandlerTest.php index 810cb26..63b7337 100644 --- a/tests/Schemas/Converse/ConverseStructuredHandlerTest.php +++ b/tests/Schemas/Converse/ConverseStructuredHandlerTest.php @@ -193,10 +193,16 @@ ->usingTemperature(0) ->asStructured(); - Http::assertSent(fn (Request $request): \Pest\Mixins\Expectation => expect($request->data())->toMatchArray([ - 'inferenceConfig' => [ - 'maxTokens' => 2048, - 'temperature' => 0, - ], - ])->not()->toHaveKey('guardRailConfig')); + Http::assertSent(function (Request $request): bool { + expect($request->data())->toMatchArray([ + 'inferenceConfig' => [ + 'maxTokens' => 2048, + 'temperature' => 0, + ], + ]) + ->not() + ->toHaveKey('guardRailConfig'); + + return true; + }); }); diff --git a/tests/Schemas/Converse/ConverseTextHandlerTest.php b/tests/Schemas/Converse/ConverseTextHandlerTest.php index c4c8e97..5284319 100644 --- a/tests/Schemas/Converse/ConverseTextHandlerTest.php +++ b/tests/Schemas/Converse/ConverseTextHandlerTest.php @@ -298,10 +298,14 @@ ->usingTemperature(0) ->asText(); - Http::assertSent(fn (Request $request): \Pest\Mixins\Expectation => expect($request->data())->toMatchArray([ - 'inferenceConfig' => [ - 'temperature' => 0, - 'maxTokens' => 2048, - ], - ])); + Http::assertSent(function (Request $request): bool { + expect($request->data())->toMatchArray([ + 'inferenceConfig' => [ + 'temperature' => 0, + 'maxTokens' => 2048, + ], + ]); + + return true; + }); });