123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- namespace app\models;
- use yii;
- use yii\helpers\Url;
- class NvidiaAI extends \app\models\base\BaseAI
- {
- public $host = 'https://integrate.api.nvidia.com/';
- public $model = 'google/gemma-2-27b-it';
- public static $urlgen = 'v1/chat/completions';
- public $res = '';
- public $key = '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';
- function __construct(){
- $header = array(
- 'Content-Type: application/json',
- 'Authorization: Bearer '.$this->key
- );
- $this->SetHeader($header);
- }
- public function generate( $promt, $context = '' ){
- $url = $this->host.self::$urlgen;
- $cmd = array(
- "model" => $this->model,
- "messages" =>array(array("role"=>"user", "content"=>$promt)),
- "stream" => false,
- "temperature" => 0.2,
- "top_p" => 0.7,
- "max_tokens" => 1024,
- );
- if( $context ){
- // $cmd['context'] = $context;
- }
- // echo json_encode($cmd); exit;
- $r = $this->Send( $url, $cmd );
- $this->res = $r;
- return $r;
- }
- public function Getres(){
- $r = $this->res;
- $robj = json_decode($r);
- return nl2br($robj->choices[0]->message->content);
- }
- }
|