From 5b2a633a99d46762c1d63cc7ce5bad192c94696f Mon Sep 17 00:00:00 2001 From: team2 Date: Tue, 17 Feb 2026 19:29:25 +0100 Subject: [PATCH] new params for ollama client --- src/Infrastructure/OllamaClient.php | 30 +++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/Infrastructure/OllamaClient.php b/src/Infrastructure/OllamaClient.php index 5ff7cad..4a407a4 100644 --- a/src/Infrastructure/OllamaClient.php +++ b/src/Infrastructure/OllamaClient.php @@ -35,8 +35,9 @@ final class OllamaClient public function __construct( string $apiUrl, string $model, - int $timeoutSeconds, - ) { + int $timeoutSeconds, + ) + { $this->apiUrl = $apiUrl; $this->model = $model; $this->timeoutSeconds = $timeoutSeconds; @@ -52,14 +53,23 @@ final class OllamaClient */ public function stream(string $prompt): Generator { + $json = []; + $payload = json_encode([ - 'model' => $this->model, + 'model' => $this->model, 'prompt' => $prompt, 'stream' => true, + 'options' => [ + "temperature" => 0.9, + "top_k" => 35, + "top_p" => 0.9, + "repeat_penalty" => 1.1, + "num_ctx" => 8192 + ] ], JSON_THROW_ON_ERROR); $buffer = ''; - $done = false; + $done = false; $ch = curl_init($this->apiUrl); if ($ch === false) { @@ -67,12 +77,12 @@ final class OllamaClient } curl_setopt_array($ch, [ - CURLOPT_POST => true, - CURLOPT_HTTPHEADER => ['Content-Type: application/json'], - CURLOPT_POSTFIELDS => $payload, + CURLOPT_POST => true, + CURLOPT_HTTPHEADER => ['Content-Type: application/json'], + CURLOPT_POSTFIELDS => $payload, CURLOPT_RETURNTRANSFER => false, - CURLOPT_TIMEOUT => $this->timeoutSeconds, - CURLOPT_WRITEFUNCTION => function ($curl, string $data) use (&$buffer, &$done): int { + CURLOPT_TIMEOUT => $this->timeoutSeconds, + CURLOPT_WRITEFUNCTION => function ($curl, string $data) use (&$buffer, &$done): int { $buffer .= $data; return strlen($data); }, @@ -135,7 +145,7 @@ final class OllamaClient } } - if(!$json['response']){ + if (!isset($json['response'])) { yield $json; return; }