Skip to content

Commit

Permalink
Makes use of streams on API responses
Browse files Browse the repository at this point in the history
  • Loading branch information
marianoarga authored Jan 11, 2024
1 parent 656e38e commit 7d08354
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Traits/MakesHttpRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Cloudstudio\Ollama\Traits;

use Illuminate\Support\Facades\Http;
use GuzzleHttp\Client;

trait MakesHttpRequests
{
Expand All @@ -17,8 +18,19 @@ trait MakesHttpRequests
protected function sendRequest(string $urlSuffix, array $data, string $method = 'post')
{
$url = config('ollama-laravel.url') . $urlSuffix;
$response = Http::timeout(config('ollama-laravel.connection.timeout'))->$method($url, $data);

return $response->json();
if (!empty($data['stream']) && $data['stream'] === true) {
$client = new Client();
$response = $client->request($method, $url, [
'json' => $data,
'stream' => true,
'timeout' => config('ollama-laravel.connection.timeout'),
]);

return $response;
} else {
$response = Http::timeout(config('ollama-laravel.connection.timeout'))->$method($url, $data);
return $response->json();
}
}
}

0 comments on commit 7d08354

Please sign in to comment.