This commit is contained in:
privet.fun 2023-06-01 10:35:15 -07:00
parent d8aece5f8c
commit 1e4c06f497
7 changed files with 47 additions and 40 deletions

View file

@ -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
## <a name="changelog"></a>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

View file

@ -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",

View file

@ -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 = '/<QUOTE\sauthor="' . $this->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();

View file

@ -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,12 +32,11 @@ 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&amp;u=' . $row['poster_id'], true, '');
$row['ailabs_user_url'] = '/' . append_sid("memberlist.$this->php_ext", 'mode=viewprofile&amp;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&amp;u=' . $row['poster_id'], true, '');
$row['ailabs_user_url'] = generate_board_url() . '/' . append_sid("memberlist.$this->php_ext", 'mode=viewprofile&amp;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, '');
}
}

View file

@ -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,9 +312,9 @@ class listener implements EventSubscriberInterface
$ailabs = array();
foreach ($jobs as $key => $value) {
$value->user_url = '/' . append_sid("memberlist.$this->php_ext", 'mode=viewprofile&amp;u=' . $value->ailabs_user_id, true, '');
$value->user_url = generate_board_url() . '/' . append_sid("memberlist.$this->php_ext", 'mode=viewprofile&amp;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);

View file

@ -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 = [];

View file

@ -14,5 +14,5 @@ namespace privet\ailabs\includes;
class resultSubmit
{
public string $response;
public array $responseCodes;
public $responseCodes;
};