Skip to content

Commit cb6fc83

Browse files
authored
refactor!: improve types in platform api (#376)
I was just tired of doing those `assert($response instanceof ...);` statements also resolves the special status of `AsyncResponse` by decoupling it from the `ResponseInterface` WDYT?
1 parent 7cd36eb commit cb6fc83

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+436
-236
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ use PhpLlm\LlmChain\Platform\Bridge\OpenAI\Embeddings;
680680

681681
$embeddings = new Embeddings($platform, Embeddings::TEXT_3_SMALL);
682682

683-
$vectors = $platform->request($embeddings, $textInput)->getContent();
683+
$vectors = $platform->request($embeddings, $textInput)->asVectors();
684684

685685
dump($vectors[0]->getData()); // Array of float values
686686
```
@@ -703,7 +703,7 @@ foreach ($inputs as $input) {
703703
}
704704

705705
foreach ($responses as $response) {
706-
echo $response->getContent().PHP_EOL;
706+
echo $response->asText().PHP_EOL;
707707
}
708708
```
709709

@@ -822,7 +822,7 @@ $response = $platform->request($model, $image, [
822822
'task' => Task::OBJECT_DETECTION, // defining a task is mandatory for internal request & response handling
823823
]);
824824

825-
dump($response->getContent());
825+
dump($response->asObject());
826826
```
827827

828828
#### Code Examples
@@ -867,7 +867,7 @@ $response = $platform->request($model, 'How many continents are there in the wor
867867
'task' => Task::Text2TextGeneration,
868868
]);
869869

870-
echo $response->getContent().PHP_EOL;
870+
echo $response->asText().PHP_EOL;
871871
```
872872

873873
#### Code Examples

examples/azure/audio-transcript.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@
2525

2626
$response = $platform->request($model, $file);
2727

28-
echo $response->getContent().\PHP_EOL;
28+
echo $response->asText().\PHP_EOL;

examples/azure/embeddings.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use PhpLlm\LlmChain\Platform\Bridge\Azure\OpenAI\PlatformFactory;
44
use PhpLlm\LlmChain\Platform\Bridge\OpenAI\Embeddings;
5-
use PhpLlm\LlmChain\Platform\Response\VectorResponse;
65
use Symfony\Component\Dotenv\Dotenv;
76

87
require_once dirname(__DIR__, 2).'/vendor/autoload.php';
@@ -28,6 +27,4 @@
2827
country was very peaceful and prosperous. The people lived happily ever after.
2928
TEXT);
3029

31-
assert($response instanceof VectorResponse);
32-
33-
echo 'Dimensions: '.$response->getContent()[0]->getDimensions().\PHP_EOL;
30+
echo 'Dimensions: '.$response->asVectors()[0]->getDimensions().\PHP_EOL;

examples/huggingface/audio-classification.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
'task' => Task::AUDIO_CLASSIFICATION,
2323
]);
2424

25-
dump($response->getContent());
25+
dump($response->asObject());

examples/huggingface/automatic-speech-recognition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
'task' => Task::AUTOMATIC_SPEECH_RECOGNITION,
2323
]);
2424

25-
echo $response->getContent().\PHP_EOL;
25+
echo $response->asText().\PHP_EOL;

examples/huggingface/chat-completion.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323
'task' => Task::CHAT_COMPLETION,
2424
]);
2525

26-
echo $response->getContent().\PHP_EOL;
26+
echo $response->asText().\PHP_EOL;

examples/huggingface/feature-extraction.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use PhpLlm\LlmChain\Platform\Bridge\HuggingFace\PlatformFactory;
44
use PhpLlm\LlmChain\Platform\Bridge\HuggingFace\Task;
55
use PhpLlm\LlmChain\Platform\Model;
6-
use PhpLlm\LlmChain\Platform\Response\VectorResponse;
76
use Symfony\Component\Dotenv\Dotenv;
87

98
require_once dirname(__DIR__, 2).'/vendor/autoload.php';
@@ -21,6 +20,4 @@
2120
'task' => Task::FEATURE_EXTRACTION,
2221
]);
2322

24-
assert($response instanceof VectorResponse);
25-
26-
echo 'Dimensions: '.$response->getContent()[0]->getDimensions().\PHP_EOL;
23+
echo 'Dimensions: '.$response->asVectors()[0]->getDimensions().\PHP_EOL;

examples/huggingface/fill-mask.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
'task' => Task::FILL_MASK,
2121
]);
2222

23-
dump($response->getContent());
23+
dump($response->asObject());

examples/huggingface/image-classification.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
'task' => Task::IMAGE_CLASSIFICATION,
2323
]);
2424

25-
dump($response->getContent());
25+
dump($response->asObject());

examples/huggingface/image-segmentation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
'task' => Task::IMAGE_SEGMENTATION,
2323
]);
2424

25-
dump($response->getContent());
25+
dump($response->asObject());

0 commit comments

Comments
 (0)