Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Schemas/Anthropic/AnthropicStructuredHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static function buildPayload(Request $request, ?string $apiVersion): arra
'system' => MessageMap::mapSystemMessages($request->systemPrompts()),
'temperature' => $request->temperature(),
'top_p' => $request->topP(),
]);
], fn ($value): bool => $value !== null);
}

protected function sendRequest(Request $request): void
Expand Down
2 changes: 1 addition & 1 deletion src/Schemas/Anthropic/AnthropicTextHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static function buildPayload(Request $request, ?string $apiVersion): arra
'top_p' => $request->topP(),
'tools' => ToolMap::map($request->tools()),
'tool_choice' => ToolChoiceMap::map($request->toolChoice()),
]);
], fn ($value): bool => $value !== null);
}

protected function sendRequest(Request $request): void
Expand Down
2 changes: 1 addition & 1 deletion src/Schemas/Converse/ConverseStructuredHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static function buildPayload(Request $request): array
'maxTokens' => $request->maxTokens(),
'temperature' => $request->temperature(),
'topP' => $request->topP(),
]),
], fn ($value): bool => $value !== null),
'messages' => MessageMap::map($request->messages()),
'performanceConfig' => $request->providerOptions('performanceConfig'),
'promptVariables' => $request->providerOptions('promptVariables'),
Expand Down
2 changes: 1 addition & 1 deletion src/Schemas/Converse/ConverseTextHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static function buildPayload(Request $request, int $stepCount = 0): array
'maxTokens' => $request->maxTokens(),
'temperature' => $request->temperature(),
'topP' => $request->topP(),
]),
], fn ($value): bool => $value !== null),
'messages' => MessageMap::map($request->messages()),
'system' => MessageMap::mapSystemMessages($request->systemPrompts()),
'toolConfig' => $request->tools() === []
Expand Down
31 changes: 31 additions & 0 deletions tests/Schemas/Anthropic/AnthropicStructuredHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Tests\Schemas\Anthropic;

use Illuminate\Http\Client\Request;
use Illuminate\Support\Facades\Http;
use Prism\Prism\Prism;
use Prism\Prism\Schema\BooleanSchema;
use Prism\Prism\Schema\ObjectSchema;
Expand Down Expand Up @@ -41,3 +43,32 @@
expect($response->structured['game_time'])->toBeString();
expect($response->structured['coat_required'])->toBeBool();
});

it('does not remove 0 values from payloads', function (): void {
FixtureResponse::fakeResponseSequence('invoke', 'anthropic/structured');

$schema = new ObjectSchema(
'output',
'the output object',
[
new StringSchema('weather', 'The weather forecast'),
new StringSchema('game_time', 'The tigers game time'),
new BooleanSchema('coat_required', 'whether a coat is required'),
],
['weather', 'game_time', 'coat_required']
);

Prism::structured()
->withSchema($schema)
->using('bedrock', 'anthropic.claude-3-5-haiku-20241022-v1:0')
->withProviderOptions([
'guardRailConfig' => null,
])
->withMaxTokens(2048)
->usingTemperature(0)
->asStructured();

Http::assertSent(fn (Request $request): \Pest\Mixins\Expectation|\Pest\Expectation => expect($request->data())->toMatchArray([
'temperature' => 0,
]));
});
14 changes: 14 additions & 0 deletions tests/Schemas/Anthropic/AnthropicTextHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,17 @@

Http::assertSent(fn (Request $request): bool => $request->header('explicitPromptCaching')[0] === 'enabled');
});

it('does not remove 0 values from payloads', function (): void {
FixtureResponse::fakeResponseSequence('invoke', 'anthropic/generate-text-with-a-prompt');

Prism::text()
->using('bedrock', 'anthropic.claude-3-5-haiku-20241022-v1:0')
->withPrompt('Who are you?')
->usingTemperature(0)
->asText();

Http::assertSent(fn (Request $request): \Pest\Mixins\Expectation|\Pest\Expectation => expect($request->data())->toMatchArray([
'temperature' => 0,
]));
});
35 changes: 35 additions & 0 deletions tests/Schemas/Converse/ConverseStructuredHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Tests\Schemas\Converse;

use Illuminate\Http\Client\Request;
use Illuminate\Support\Facades\Http;
use Prism\Bedrock\Enums\BedrockSchema;
use Prism\Prism\Prism;
use Prism\Prism\Schema\BooleanSchema;
Expand Down Expand Up @@ -94,3 +96,36 @@

$fake->assertRequest(fn (array $requests): mixed => expect($requests[0]->providerOptions())->toBe($providerOptions));
});

it('does not remove 0 values from payloads', function (): void {
FixtureResponse::fakeResponseSequence('converse', 'converse/structured');

$schema = new ObjectSchema(
'output',
'the output object',
[
new StringSchema('weather', 'The weather forecast'),
new StringSchema('game_time', 'The tigers game time'),
new BooleanSchema('coat_required', 'whether a coat is required'),
],
['weather', 'game_time', 'coat_required']
);

Prism::structured()
->withSchema($schema)
->using('bedrock', 'anthropic.claude-3-5-haiku-20241022-v1:0')
->withProviderOptions([
'apiSchema' => BedrockSchema::Converse,
'guardRailConfig' => null,
])
->withMaxTokens(2048)
->usingTemperature(0)
->asStructured();

Http::assertSent(fn (Request $request): \Pest\Mixins\Expectation|\Pest\Expectation => expect($request->data())->toMatchArray([
'inferenceConfig' => [
'maxTokens' => 2048,
'temperature' => 0,
],
])->not()->toHaveKey('guardRailConfig'));
});
17 changes: 17 additions & 0 deletions tests/Schemas/Converse/ConverseTextHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,20 @@

$fake->assertRequest(fn (array $requests): mixed => expect($requests[0]->providerOptions())->toBe($providerOptions));
});

it('does not remove zero values from payload', function (): void {
FixtureResponse::fakeResponseSequence('converse', 'converse/generate-text-with-a-prompt');

Prism::text()
->using('bedrock', 'amazon.nova-micro-v1:0')
->withPrompt('Who are you?')
->usingTemperature(0)
->asText();

Http::assertSent(fn (Request $request): \Pest\Mixins\Expectation|\Pest\Expectation => expect($request->data())->toMatchArray([
'inferenceConfig' => [
'temperature' => 0,
'maxTokens' => 2048,
],
]));
});