⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.23
Server IP:
178.33.27.10
Server:
Linux cpanel.dev-unit.com 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
Server Software:
Apache/2.4.57 (Unix) OpenSSL/1.0.2k-fips
PHP Version:
8.2.11
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
id
/
b2c-booking.dev-unit.com
/
pro
/
Ai
/
Drivers
/
View File Name :
OpenAi.php
<?php namespace Pro\Ai\Drivers; use Illuminate\Support\Facades\Http; use Pro\Ai\Exceptions\DriverNotReady; class OpenAi extends AiDriver { protected $endpoint = 'https://api.openai.com/v1/chat/completions'; public function generate($message, $options = []) { if (!$this->isEnable()) { throw new DriverNotReady(); } $json = $this->call($message, $options)->json(); if (!empty($json['error']['message'])) { throw new \Exception($json['error']['message']); } $message = $json['choices'][0]['message']['content']; return trim($message, '"'); } protected function call($message, $options = []) { return Http::withHeaders([ 'Content-Type' => 'application/json', "Authorization" => "Bearer " . $this->settings['api_key'] ])->post($this->endpoint, [ 'model' => $this->settings['model'], 'temperature' => $this->settings['temperature'] ?? 1, 'max_tokens' => $this->settings['max_tokens'] ?? 2048, "messages" => [ [ "role" => "user", "content" => $message ] ], ...$options ]); } public function isEnable() { return !empty($this->settings['api_key']) and !empty($this->settings['model']); } }