1414use PhpLlm \LlmChain \Bridge \HuggingFace \Output \TokenClassificationResult ;
1515use PhpLlm \LlmChain \Bridge \HuggingFace \Output \ZeroShotClassificationResult ;
1616use PhpLlm \LlmChain \Document \Vector ;
17+ use PhpLlm \LlmChain \Exception \InvalidArgumentException ;
18+ use PhpLlm \LlmChain \Exception \RuntimeException ;
1719use PhpLlm \LlmChain \Model \Model as BaseModel ;
1820use PhpLlm \LlmChain \Model \Response \BinaryResponse ;
1921use PhpLlm \LlmChain \Model \Response \ResponseInterface as LlmResponse ;
@@ -33,11 +35,11 @@ public function supports(BaseModel $model, array|string|object $input): bool
3335 public function convert (ResponseInterface $ response , array $ options = []): LlmResponse
3436 {
3537 if (503 === $ response ->getStatusCode ()) {
36- return throw new \ RuntimeException ('Service unavailable. ' );
38+ return throw new RuntimeException ('Service unavailable. ' );
3739 }
3840
3941 if (404 === $ response ->getStatusCode ()) {
40- return throw new \ InvalidArgumentException ('Model, provider or task not found (404). ' );
42+ return throw new InvalidArgumentException ('Model, provider or task not found (404). ' );
4143 }
4244
4345 $ headers = $ response ->getHeaders (false );
@@ -48,11 +50,11 @@ public function convert(ResponseInterface $response, array $options = []): LlmRe
4850 $ message = is_string ($ content ) ? $ content :
4951 (is_array ($ content ['error ' ]) ? $ content ['error ' ][0 ] : $ content ['error ' ]);
5052
51- throw new \ InvalidArgumentException (sprintf ('API Client Error (%d): %s ' , $ response ->getStatusCode (), $ message ));
53+ throw new InvalidArgumentException (sprintf ('API Client Error (%d): %s ' , $ response ->getStatusCode (), $ message ));
5254 }
5355
5456 if (200 !== $ response ->getStatusCode ()) {
55- throw new \ RuntimeException ('Unhandled response code: ' .$ response ->getStatusCode ());
57+ throw new RuntimeException ('Unhandled response code: ' .$ response ->getStatusCode ());
5658 }
5759
5860 $ task = $ options ['task ' ] ?? null ;
@@ -78,7 +80,7 @@ public function convert(ResponseInterface $response, array $options = []): LlmRe
7880 Task::TRANSLATION => new TextResponse ($ content [0 ]['translation_text ' ] ?? '' ),
7981 Task::ZERO_SHOT_CLASSIFICATION => new StructuredResponse (ZeroShotClassificationResult::fromArray ($ content )),
8082
81- default => throw new \ RuntimeException (sprintf ('Unsupported task: %s ' , $ task )),
83+ default => throw new RuntimeException (sprintf ('Unsupported task: %s ' , $ task )),
8284 };
8385 }
8486}
0 commit comments