From fea873ad4f1a95880fc95109978eecf3b4c5c5dd Mon Sep 17 00:00:00 2001 From: Gabriel Sousa Date: Tue, 27 Jan 2026 00:45:35 -0300 Subject: [PATCH] feat(ToolChoiceMap): add 'required' mapping for ToolChoice::Any and update tests accordingly --- src/Providers/Groq/Maps/ToolChoiceMap.php | 1 + tests/Providers/Groq/GroqTextTest.php | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Providers/Groq/Maps/ToolChoiceMap.php b/src/Providers/Groq/Maps/ToolChoiceMap.php index 0566525af..e5ffd06c2 100644 --- a/src/Providers/Groq/Maps/ToolChoiceMap.php +++ b/src/Providers/Groq/Maps/ToolChoiceMap.php @@ -25,6 +25,7 @@ public static function map(string|ToolChoice|null $toolChoice): string|array|nul return match ($toolChoice) { ToolChoice::Auto => 'auto', + ToolChoice::Any => 'required', null => $toolChoice, default => throw new PrismException('Invalid tool choice') }; diff --git a/tests/Providers/Groq/GroqTextTest.php b/tests/Providers/Groq/GroqTextTest.php index 98ba516f4..6f3ae72c3 100644 --- a/tests/Providers/Groq/GroqTextTest.php +++ b/tests/Providers/Groq/GroqTextTest.php @@ -9,7 +9,6 @@ use Illuminate\Support\Facades\Http; use Prism\Prism\Enums\Provider; use Prism\Prism\Enums\ToolChoice; -use Prism\Prism\Exceptions\PrismException; use Prism\Prism\Exceptions\PrismRateLimitedException; use Prism\Prism\Facades\Prism; use Prism\Prism\Facades\Tool; @@ -132,15 +131,14 @@ }); it('throws an exception for ToolChoice::Any', function (): void { - $this->expectException(PrismException::class); - $this->expectExceptionMessage('Invalid tool choice'); + FixtureResponse::fakeResponseSequence('v1/chat/completions', 'groq/generate-text-with-required-tool-call'); Prism::text() ->using('groq', 'gpt-4') ->withPrompt('Who are you?') ->withToolChoice(ToolChoice::Any) ->asText(); - }); + })->throwsNoExceptions(); }); describe('Image support with grok', function (): void {