1313
1414use Symfony \AI \Platform \Exception \RuntimeException ;
1515use Symfony \AI \Platform \Model ;
16- use Symfony \AI \Platform \Response \ResponseInterface as LlmResponse ;
16+ use Symfony \AI \Platform \Response \RawHttpResponse ;
17+ use Symfony \AI \Platform \Response \RawResponseInterface ;
18+ use Symfony \AI \Platform \Response \ResponseInterface ;
1719use Symfony \AI \Platform \Response \StreamResponse ;
1820use Symfony \AI \Platform \Response \TextResponse ;
1921use Symfony \AI \Platform \Response \ToolCall ;
2224use Symfony \Component \HttpClient \Chunk \ServerSentEvent ;
2325use Symfony \Component \HttpClient \EventSourceHttpClient ;
2426use Symfony \Component \HttpClient \Exception \JsonException ;
25- use Symfony \Contracts \HttpClient \ResponseInterface ;
27+ use Symfony \Contracts \HttpClient \ResponseInterface as HttpResponse ;
2628
2729/**
2830 * @author Christopher Hertel <mail@christopher-hertel.de>
@@ -34,13 +36,13 @@ public function supports(Model $model): bool
3436 return $ model instanceof Claude;
3537 }
3638
37- public function convert (ResponseInterface $ response , array $ options = []): LlmResponse
39+ public function convert (RawHttpResponse | RawResponseInterface $ response , array $ options = []): ResponseInterface
3840 {
3941 if ($ options ['stream ' ] ?? false ) {
40- return new StreamResponse ($ this ->convertStream ($ response ));
42+ return new StreamResponse ($ this ->convertStream ($ response-> getRawObject () ));
4143 }
4244
43- $ data = $ response ->toArray ();
45+ $ data = $ response ->getRawData ();
4446
4547 if (!isset ($ data ['content ' ]) || [] === $ data ['content ' ]) {
4648 throw new RuntimeException ('Response does not contain any content ' );
@@ -64,7 +66,7 @@ public function convert(ResponseInterface $response, array $options = []): LlmRe
6466 return new TextResponse ($ data ['content ' ][0 ]['text ' ]);
6567 }
6668
67- private function convertStream (ResponseInterface $ response ): \Generator
69+ private function convertStream (HttpResponse $ response ): \Generator
6870 {
6971 foreach ((new EventSourceHttpClient ())->stream ($ response ) as $ chunk ) {
7072 if (!$ chunk instanceof ServerSentEvent || '[DONE] ' === $ chunk ->getData ()) {
0 commit comments