new params for ollama client
This commit is contained in:
@@ -35,8 +35,9 @@ final class OllamaClient
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
string $apiUrl,
|
string $apiUrl,
|
||||||
string $model,
|
string $model,
|
||||||
int $timeoutSeconds,
|
int $timeoutSeconds,
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
$this->apiUrl = $apiUrl;
|
$this->apiUrl = $apiUrl;
|
||||||
$this->model = $model;
|
$this->model = $model;
|
||||||
$this->timeoutSeconds = $timeoutSeconds;
|
$this->timeoutSeconds = $timeoutSeconds;
|
||||||
@@ -52,14 +53,23 @@ final class OllamaClient
|
|||||||
*/
|
*/
|
||||||
public function stream(string $prompt): Generator
|
public function stream(string $prompt): Generator
|
||||||
{
|
{
|
||||||
|
$json = [];
|
||||||
|
|
||||||
$payload = json_encode([
|
$payload = json_encode([
|
||||||
'model' => $this->model,
|
'model' => $this->model,
|
||||||
'prompt' => $prompt,
|
'prompt' => $prompt,
|
||||||
'stream' => true,
|
'stream' => true,
|
||||||
|
'options' => [
|
||||||
|
"temperature" => 0.9,
|
||||||
|
"top_k" => 35,
|
||||||
|
"top_p" => 0.9,
|
||||||
|
"repeat_penalty" => 1.1,
|
||||||
|
"num_ctx" => 8192
|
||||||
|
]
|
||||||
], JSON_THROW_ON_ERROR);
|
], JSON_THROW_ON_ERROR);
|
||||||
|
|
||||||
$buffer = '';
|
$buffer = '';
|
||||||
$done = false;
|
$done = false;
|
||||||
|
|
||||||
$ch = curl_init($this->apiUrl);
|
$ch = curl_init($this->apiUrl);
|
||||||
if ($ch === false) {
|
if ($ch === false) {
|
||||||
@@ -67,12 +77,12 @@ final class OllamaClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
curl_setopt_array($ch, [
|
curl_setopt_array($ch, [
|
||||||
CURLOPT_POST => true,
|
CURLOPT_POST => true,
|
||||||
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
|
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
|
||||||
CURLOPT_POSTFIELDS => $payload,
|
CURLOPT_POSTFIELDS => $payload,
|
||||||
CURLOPT_RETURNTRANSFER => false,
|
CURLOPT_RETURNTRANSFER => false,
|
||||||
CURLOPT_TIMEOUT => $this->timeoutSeconds,
|
CURLOPT_TIMEOUT => $this->timeoutSeconds,
|
||||||
CURLOPT_WRITEFUNCTION => function ($curl, string $data) use (&$buffer, &$done): int {
|
CURLOPT_WRITEFUNCTION => function ($curl, string $data) use (&$buffer, &$done): int {
|
||||||
$buffer .= $data;
|
$buffer .= $data;
|
||||||
return strlen($data);
|
return strlen($data);
|
||||||
},
|
},
|
||||||
@@ -135,7 +145,7 @@ final class OllamaClient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$json['response']){
|
if (!isset($json['response'])) {
|
||||||
yield $json;
|
yield $json;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user