diff --git a/privet/ailabs/README.md b/privet/ailabs/README.md index 3875bf5..c261714 100644 --- a/privet/ailabs/README.md +++ b/privet/ailabs/README.md @@ -1,4 +1,5 @@ -# AI Labs v 1.0.1 RC +# AI Labs v 1.0.2 RC +##### [Changelog](#changelog) Incorporate AI into your phpBB board and get ready for an exciting experience. Currently supported ChatGPT, DALL-E (OpenAI) and Stable Diffusion (Stability AI). @@ -108,10 +109,17 @@ Refer to https://platform.openai.com/docs/api-reference/images/create to learn m This extension is currently being actively developed. For communication, please use https://github.com/privet-fun/phpbb_ailabs/issues. -## Changelog +## Changelog + +* 1.0.2 June 1, 2023 + - Only apply `utf8_encode_ucr` if present, reported by [Vlad__](https://www.phpbbguru.net/community/viewtopic.php?p=561158#p561158) + This will allow phpBB 3.2.1 support without any modifications. + - Removed `...` and `array` to support php 7.1, reported by [Vlad__](https://www.phpbbguru.net/community/viewtopic.php?p=561163#p561163) + - Added missing `reply` processing for chatgpt controller, reported by [Vlad__](https://www.phpbbguru.net/community/viewtopic.php?p=561205#p561205) + - Added board prefix to all links, reported by [Miri4ever](https://www.phpbb.com/community/viewtopic.php?p=15958961#p15958961) * 1.0.1 May 29, 2023 - - Fixed issues reported by [ Miri4ever](https://www.phpbb.com/community/viewtopic.php?p=15958523#p15958523) + - Fixed issues reported by [Miri4ever](https://www.phpbb.com/community/viewtopic.php?p=15958523#p15958523) - Removed all MySQL specific SQL, going forward extension should be SQL server agnostic - Better language management - Minor code cleanup diff --git a/privet/ailabs/composer.json b/privet/ailabs/composer.json index d9841dc..cf228b4 100644 --- a/privet/ailabs/composer.json +++ b/privet/ailabs/composer.json @@ -3,8 +3,8 @@ "type": "phpbb-extension", "description": "AI Labs", "homepage": "https://privet.fun", - "version": "1.0.1", - "time": "2023-05-29", + "version": "1.0.2", + "time": "2023-06-01", "keywords": [ "phpbb", "extension", diff --git a/privet/ailabs/controller/chatgpt.php b/privet/ailabs/controller/chatgpt.php index 8f76646..292e9f6 100644 --- a/privet/ailabs/controller/chatgpt.php +++ b/privet/ailabs/controller/chatgpt.php @@ -90,8 +90,9 @@ class chatgpt extends AIController $posts = []; $post_first_taken = null; $post_first_discarded = null; + $mode = $this->job['post_mode']; - if ($this->job['post_mode'] == 'quote') { + if ($mode == 'reply' || $mode == 'quote') { $history = ['post_text' => $this->job['post_text']]; $pattern = '/job['ailabs_username'] . '"\spost_id="(.*)"\stime="(.*)"\suser_id="' . $this->job['ailabs_user_id'] . '">/'; @@ -144,15 +145,11 @@ class chatgpt extends AIController $post_first_taken = $postid; $history_tokens += $count_tokens; - $post_messages = [ + array_unshift( + $messages, ['role' => 'user', 'content' => trim($history['request'])], - ['role' => 'assistant', 'content' => trim($history['response'])], - ]; - - $messages = [ - ...$post_messages, - ...$messages - ]; + ['role' => 'assistant', 'content' => trim($history['response'])] + ); } } } while (!empty($history)); @@ -164,16 +161,13 @@ class chatgpt extends AIController } if (!empty($this->cfg->prefix)) { - $messages = [ + array_unshift( + $messages, ['role' => 'system', 'content' => $this->cfg->prefix], - ...$messages - ]; + ); } - $messages = [ - ...$messages, - ['role' => 'user', 'content' => trim($this->job['request'])] - ]; + $messages[] = ['role' => 'user', 'content' => trim($this->job['request'])]; $this->log['request.messages'] = $messages; $this->log_flush(); diff --git a/privet/ailabs/controller/log.php b/privet/ailabs/controller/log.php index a966649..c0a765b 100644 --- a/privet/ailabs/controller/log.php +++ b/privet/ailabs/controller/log.php @@ -18,9 +18,9 @@ class log extends AIController { public function view_log($post_id) { - if ($this->user->data['user_id'] == ANONYMOUS || $this->user->data['is_bot']) { - throw new http_exception(401); - } + if ($this->user->data['user_id'] == ANONYMOUS || $this->user->data['is_bot'] || !$this->auth->acl_get('a_', 'm_')) { + throw new http_exception(401); + } $where = [ 'post_id' => $post_id @@ -32,13 +32,12 @@ class log extends AIController $this->db->sql_freeresult($result); if (!empty($data)) { - foreach($data as &$row) - { - $row['poster_user_url'] = '/' . append_sid("memberlist.$this->php_ext", 'mode=viewprofile&u=' . $row['poster_id'], true, ''); - $row['ailabs_user_url'] = '/' . append_sid("memberlist.$this->php_ext", 'mode=viewprofile&u=' . $row['ailabs_user_id'], true, ''); + foreach ($data as &$row) { + $row['poster_user_url'] = generate_board_url() . '/' . append_sid("memberlist.$this->php_ext", 'mode=viewprofile&u=' . $row['poster_id'], true, ''); + $row['ailabs_user_url'] = generate_board_url() . '/' . append_sid("memberlist.$this->php_ext", 'mode=viewprofile&u=' . $row['ailabs_user_id'], true, ''); if (!empty($row['response_post_id'])) { - $row['response_url'] = '/viewtopic.php?p=' . $row['response_post_id'] . '#p' . $row['response_post_id']; - } + $row['response_url'] = generate_board_url() . '/' . append_sid('viewtopic.php?p=' . $row['response_post_id'] . '#p' . $row['response_post_id'], true, ''); + } } $this->template->assign_block_vars('ailabs_log', [ diff --git a/privet/ailabs/event/listener.php b/privet/ailabs/event/listener.php index 334548e..a76a8b4 100644 --- a/privet/ailabs/event/listener.php +++ b/privet/ailabs/event/listener.php @@ -148,6 +148,12 @@ class listener implements EventSubscriberInterface // Remove leading and trailing spaces as well as all doublespaces $request = trim(str_replace(' ', ' ', $request)); + // utf8_encode_ucr added in phpBB v3.2.7 + // See comments at http://area51.phpbb.com/code-changes/3.2.7/side-by-side/3.2.11/phpbb-includes-utf-utf_tools.php.html + if (function_exists('utf8_encode_ucr')) { + $request = utf8_encode_ucr($request); + } + // https://area51.phpbb.com/docs/dev/master/db/dbal.html foreach ($ailabs_users as $user) { $data = [ @@ -306,16 +312,16 @@ class listener implements EventSubscriberInterface $ailabs = array(); foreach ($jobs as $key => $value) { - $value->user_url = '/' . append_sid("memberlist.$this->php_ext", 'mode=viewprofile&u=' . $value->ailabs_user_id, true, ''); + $value->user_url = generate_board_url() . '/' . append_sid("memberlist.$this->php_ext", 'mode=viewprofile&u=' . $value->ailabs_user_id, true, ''); if (!empty($value->response_post_id)) { - $value->response_url = '/viewtopic.php?p=' . $value->response_post_id . '#p' . $value->response_post_id; + $value->response_url = generate_board_url() . '/' . append_sid('viewtopic.php?p=' . $value->response_post_id . '#p' . $value->response_post_id, true, ''); } $value->status = $this->get_status(empty($value->status) ? null : $value->status); array_push($ailabs, $value); } if (!empty($ailabs)) { - $event['post_row'] = array_merge($event['post_row'], [ + $event['post_row'] = array_merge($event['post_row'], [ 'U_AILABS' => $ailabs, ]); if ($this->auth->acl_get('a_', 'm_')) { diff --git a/privet/ailabs/includes/GenericCurl.php b/privet/ailabs/includes/GenericCurl.php index a8c45b2..9a6c1cf 100644 --- a/privet/ailabs/includes/GenericCurl.php +++ b/privet/ailabs/includes/GenericCurl.php @@ -13,15 +13,15 @@ namespace privet\ailabs\includes; class GenericCurl { - private array $headers; - private array $contentTypes; + private $headers; + private $contentTypes; private int $timeout = 0; private object $stream_method; private string $proxy = ""; - private array $curlInfo = []; + private $curlInfo = []; public int $retryCount; public int $timeoutBeforeRetrySec; - public array $responseCodes = []; + public $responseCodes = []; public function __construct($API_KEY, $retryCount = 3, $timeoutBeforeRetrySec = 10) { @@ -71,7 +71,7 @@ class GenericCurl * @param array $header * @return void */ - public function setHeader(array $header) + public function setHeader($header) { if ($header) { foreach ($header as $key => $value) { @@ -86,7 +86,7 @@ class GenericCurl * @param array $opts * @return bool|string */ - public function sendRequest(string $url, string $method, array $opts = []) + public function sendRequest(string $url, string $method, $opts = []) { $this->responseCodes = []; diff --git a/privet/ailabs/includes/resultSubmit.php b/privet/ailabs/includes/resultSubmit.php index cce64d6..aaf199f 100644 --- a/privet/ailabs/includes/resultSubmit.php +++ b/privet/ailabs/includes/resultSubmit.php @@ -14,5 +14,5 @@ namespace privet\ailabs\includes; class resultSubmit { public string $response; - public array $responseCodes; + public $responseCodes; }; \ No newline at end of file