1414use Symfony \AI \Platform \Bridge \OpenAi \Gpt ;
1515use Symfony \AI \Platform \Exception \AuthenticationException ;
1616use Symfony \AI \Platform \Exception \BadRequestException ;
17- use Symfony \AI \Platform \Exception \ContentFilterException ;
1817use Symfony \AI \Platform \Exception \RateLimitExceededException ;
18+ use Symfony \AI \Platform \Exception \ResultException ;
1919use Symfony \AI \Platform \Exception \RuntimeException ;
2020use Symfony \AI \Platform \Model ;
2121use Symfony \AI \Platform \Result \ChoiceResult ;
@@ -47,8 +47,8 @@ public function convert(RawResultInterface|RawHttpResult $result, array $options
4747 $ response = $ result ->getObject ();
4848
4949 if (401 === $ response ->getStatusCode ()) {
50- $ errorMessage = json_decode ( $ response ->getContent (false ), true )[ ' error ' ][ ' message ' ] ;
51- throw new AuthenticationException ($ errorMessage );
50+ $ data = $ response ->toArray (false );
51+ throw new AuthenticationException ($ data [ ' error ' ][ ' message ' ], $ data [ ' error ' ] );
5252 }
5353
5454 if (400 === $ response ->getStatusCode ()) {
@@ -66,21 +66,21 @@ public function convert(RawResultInterface|RawHttpResult $result, array $options
6666 }
6767
6868 if ($ options ['stream ' ] ?? false ) {
69- return new StreamResult ($ this ->convertStream ($ response ));
69+ return new StreamResult ($ this ->convertStream ($ result -> getObject () ));
7070 }
7171
7272 $ data = $ result ->getData ();
7373
74- if (isset ($ data ['error ' ][ ' code ' ]) && ' content_filter ' === $ data [ ' error ' ][ ' code ' ] ) {
75- throw new ContentFilterException ($ data ['error ' ]['message ' ]);
74+ if (isset ($ data ['error ' ]) ) {
75+ throw new ResultException ($ data ['error ' ]['message ' ], $ data [ ' error ' ]);
7676 }
7777
7878 if (isset ($ data ['error ' ])) {
7979 throw new RuntimeException (\sprintf ('Error "%s"-%s (%s): "%s". ' , $ data ['error ' ]['code ' ], $ data ['error ' ]['type ' ], $ data ['error ' ]['param ' ], $ data ['error ' ]['message ' ]));
8080 }
8181
8282 if (!isset ($ data ['choices ' ])) {
83- throw new RuntimeException ( ' Response does not contain choices. ' );
83+ throw new ResultException ( ' Result does not contain choices. ' );
8484 }
8585
8686 $ choices = array_map ($ this ->convertChoice (...), $ data ['choices ' ]);
0 commit comments