Skip to content

Commit b3da0e0

Browse files
author
miroslav
committed
BUG: fix models result
1 parent d07012a commit b3da0e0

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/Services/API/ApiService.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@ public function __construct(
2222
*/
2323
public function sendRequest(string $method, string $url, array $parameters = []): ResponseInterface
2424
{
25-
return $this->client->request($method, $url, [
25+
$requestParams = [
2626
'headers' => [
2727
'Content-Type' => 'application/json',
2828
'Authorization' => 'Bearer '.$this->authService->getToken(),
29-
],
30-
'json' => $parameters
31-
]);
29+
]
30+
];
31+
32+
if ($parameters) {
33+
$requestParams['json'] = $parameters;
34+
}
35+
36+
return $this->client->request($method, $url, $requestParams);
3237
}
3338

3439
public function getResult(ResponseInterface $response, string $resultClass): ResultInterface

src/Services/API/Results/ModelsResult.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22

33
namespace Itsimiro\OpenAI\Services\API\Results;
44

5+
use Illuminate\Support\Collection;
56
use Spatie\LaravelData\Data;
6-
use Spatie\LaravelData\DataCollection;
77

88
class ModelsResult extends Data implements ResultInterface
99
{
1010
public function __construct(public array $result)
1111
{}
1212

13-
public function getModels(): DataCollection
13+
public function getModels(): Collection
1414
{
15-
return ModelResult::collection($this->result['data']);
15+
return Collection::make($this->result['data'])->map(
16+
fn (array $item) => new ModelResult($item)
17+
);
1618
}
1719
}

0 commit comments

Comments
 (0)