14
14
use PhpLlm \LlmChain \Bridge \HuggingFace \Output \TokenClassificationResult ;
15
15
use PhpLlm \LlmChain \Bridge \HuggingFace \Output \ZeroShotClassificationResult ;
16
16
use PhpLlm \LlmChain \Document \Vector ;
17
+ use PhpLlm \LlmChain \Exception \InvalidArgumentException ;
18
+ use PhpLlm \LlmChain \Exception \RuntimeException ;
17
19
use PhpLlm \LlmChain \Model \Model as BaseModel ;
18
20
use PhpLlm \LlmChain \Model \Response \BinaryResponse ;
19
21
use PhpLlm \LlmChain \Model \Response \ResponseInterface as LlmResponse ;
@@ -33,11 +35,11 @@ public function supports(BaseModel $model, array|string|object $input): bool
33
35
public function convert (ResponseInterface $ response , array $ options = []): LlmResponse
34
36
{
35
37
if (503 === $ response ->getStatusCode ()) {
36
- return throw new \ RuntimeException ('Service unavailable. ' );
38
+ return throw new RuntimeException ('Service unavailable. ' );
37
39
}
38
40
39
41
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). ' );
41
43
}
42
44
43
45
$ headers = $ response ->getHeaders (false );
@@ -48,11 +50,11 @@ public function convert(ResponseInterface $response, array $options = []): LlmRe
48
50
$ message = is_string ($ content ) ? $ content :
49
51
(is_array ($ content ['error ' ]) ? $ content ['error ' ][0 ] : $ content ['error ' ]);
50
52
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 ));
52
54
}
53
55
54
56
if (200 !== $ response ->getStatusCode ()) {
55
- throw new \ RuntimeException ('Unhandled response code: ' .$ response ->getStatusCode ());
57
+ throw new RuntimeException ('Unhandled response code: ' .$ response ->getStatusCode ());
56
58
}
57
59
58
60
$ task = $ options ['task ' ] ?? null ;
@@ -78,7 +80,7 @@ public function convert(ResponseInterface $response, array $options = []): LlmRe
78
80
Task::TRANSLATION => new TextResponse ($ content [0 ]['translation_text ' ] ?? '' ),
79
81
Task::ZERO_SHOT_CLASSIFICATION => new StructuredResponse (ZeroShotClassificationResult::fromArray ($ content )),
80
82
81
- default => throw new \ RuntimeException (sprintf ('Unsupported task: %s ' , $ task )),
83
+ default => throw new RuntimeException (sprintf ('Unsupported task: %s ' , $ task )),
82
84
};
83
85
}
84
86
}
0 commit comments