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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ phpunit.xml
*.code-workspace
ray.php
CLAUDE.md
.claude/
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/Bedrock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
2 changes: 1 addition & 1 deletion src/BedrockServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
));
Expand Down
4 changes: 2 additions & 2 deletions src/Schemas/Anthropic/AnthropicStructuredHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
1 change: 1 addition & 0 deletions src/Schemas/Anthropic/AnthropicTextHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
10 changes: 5 additions & 5 deletions src/Schemas/Anthropic/Maps/MessageMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static function map(array $messages): array
}

return array_map(
fn (Message $message): array => self::mapMessage($message),
self::mapMessage(...),
$messages
);
}
Expand All @@ -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
);
}
Expand All @@ -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',
Expand Down Expand Up @@ -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() !== []) {
Expand All @@ -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 = [];

Expand Down
2 changes: 1 addition & 1 deletion src/Schemas/Anthropic/Maps/ToolMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/Schemas/Cohere/CohereEmbeddingsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
),
Expand Down
1 change: 1 addition & 0 deletions src/Schemas/Converse/ConverseTextHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
8 changes: 4 additions & 4 deletions src/Schemas/Converse/Maps/MessageMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static function map(array $messages): array
}

return array_map(
fn (Message $message): array => self::mapMessage($message),
self::mapMessage(...),
$messages
);
}
Expand All @@ -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]];
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion tests/BedrockServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion tests/Schemas/Anthropic/AnthropicStructuredHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/Schemas/Anthropic/AnthropicTextHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/Schemas/Cohere/CohereEmbeddingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion tests/Schemas/Converse/ConverseStructuredHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 3 additions & 6 deletions tests/Schemas/Converse/ConverseTextHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down