1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace app\models;
- use yii;
- use yii\helpers\Url;
- class OllamaAI extends \app\models\base\BaseAI
- {
- public $host = 'http://192.168.0.20:11434';
- public $model = 'gemma2';
- public static $urlgen = '/api/generate';
- public $res = '';
- function OllamaAI(){
- $this->SetHeader();
- }
- public function generate( $promt, $context = '' ){
- $url = $this->host.self::$urlgen;
- $cmd = array(
- "model" => $this->model,
- "prompt" => $promt,
- "stream" => false,
- 'keep_alive' =>'60m'
- );
- if( $context ){
- $cmd['context'] = $context;
- }
- $r = $this->Send( $url, $cmd );
- $this->res = $r;
- return $r;
- }
- public function GetTime(){
- $r = $this->res;
- $robj = json_decode($r);
- return $robj->eval_duration/1000000000;
- }
- public function Getres(){
- $r = $this->res;
- $robj = json_decode($r);
- return nl2br($robj->response);
- }
- public function Getcontext(){
- $r = $this->res;
- $robj = json_decode($r);
- return $robj->context;
- }
- }
|