File tree Expand file tree Collapse file tree 3 files changed +13
-5
lines changed
Providers/Anthropic/Handlers
tests/Providers/Anthropic Expand file tree Collapse file tree 3 files changed +13
-5
lines changed Original file line number Diff line number Diff line change 8
8
use Illuminate \Support \Collection ;
9
9
use InvalidArgumentException ;
10
10
use Prism \Prism \Contracts \PrismRequest ;
11
+ use Prism \Prism \Exceptions \PrismException ;
11
12
use Prism \Prism \Providers \Anthropic \Maps \FinishReasonMap ;
12
13
use Prism \Prism \Providers \Anthropic \Maps \MessageMap ;
13
14
use Prism \Prism \Structured \Request as StructuredRequest ;
@@ -105,7 +106,7 @@ public static function buildHttpRequestPayload(PrismRequest $request): array
105
106
106
107
// Validate options
107
108
if ($ request ->providerOptions ('citations ' ) === true && $ request ->providerOptions ('use_tool_calling ' ) === true ) {
108
- throw new InvalidArgumentException (
109
+ throw new PrismException (
109
110
'Citations are not supported with tool calling mode. ' .
110
111
'Please set use_tool_calling to false in provider options to use citations. '
111
112
);
@@ -300,7 +301,7 @@ protected function shouldUseToolCalling(): bool
300
301
protected function validateProviderOptions (): void
301
302
{
302
303
if ($ this ->request ->providerOptions ('citations ' ) === true && $ this ->shouldUseToolCalling ()) {
303
- throw new InvalidArgumentException (
304
+ throw new PrismException (
304
305
'Citations are not supported with tool calling mode. ' .
305
306
'Please set use_tool_calling to false in provider options to use citations. '
306
307
);
Original file line number Diff line number Diff line change 14
14
use Prism \Prism \Concerns \HasSchema ;
15
15
use Prism \Prism \Exceptions \PrismException ;
16
16
use Prism \Prism \ValueObjects \Messages \UserMessage ;
17
+ use Throwable ;
17
18
18
19
class PendingRequest
19
20
{
@@ -36,7 +37,13 @@ public function generate(): Response
36
37
37
38
public function asStructured (): Response
38
39
{
39
- return $ this ->provider ->structured ($ this ->toRequest ());
40
+ $ request = $ this ->toRequest ();
41
+
42
+ try {
43
+ return $ this ->provider ->structured ($ request );
44
+ } catch (Throwable $ e ) {
45
+ $ this ->provider ->handleRequestExceptions ($ request ->model (), $ e );
46
+ }
40
47
}
41
48
42
49
public function toRequest (): Request
Original file line number Diff line number Diff line change 5
5
namespace Tests \Providers \Anthropic ;
6
6
7
7
use Illuminate \Support \Carbon ;
8
- use InvalidArgumentException ;
9
8
use Prism \Prism \Enums \Provider ;
9
+ use Prism \Prism \Exceptions \PrismException ;
10
10
use Prism \Prism \Prism ;
11
11
use Prism \Prism \Providers \Anthropic \Handlers \Structured ;
12
12
use Prism \Prism \Providers \Anthropic \ValueObjects \MessagePartWithCitations ;
220
220
->withPrompt ('What is the answer? ' )
221
221
->withProviderOptions (['citations ' => true , 'use_tool_calling ' => true ])
222
222
->asStructured ()
223
- )->toThrow (InvalidArgumentException ::class, 'Citations are not supported with tool calling mode ' );
223
+ )->toThrow (PrismException ::class, 'Citations are not supported with tool calling mode ' );
224
224
});
225
225
226
226
it ('returns structured output with default JSON mode ' , function (): void {
You can’t perform that action at this time.
0 commit comments