diff --git a/privet/ailabs/README.md b/privet/ailabs/README.md index e9d96bc..fcce7fd 100644 --- a/privet/ailabs/README.md +++ b/privet/ailabs/README.md @@ -1,4 +1,4 @@ -# AI Labs v 1.0.4 RC +# AI Labs v 1.0.5 ##### [Changelog](#changelog_link) Incorporate AI into your phpBB board and get ready for an exciting experience. diff --git a/privet/ailabs/composer.json b/privet/ailabs/composer.json index c2d6d9e..de1a24a 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.4", - "time": "2023-06-04", + "version": "1.0.5", + "time": "2023-10-01", "keywords": [ "phpbb", "extension", diff --git a/privet/ailabs/config/routing.yml b/privet/ailabs/config/routing.yml index 14226d2..ea61f99 100644 --- a/privet/ailabs/config/routing.yml +++ b/privet/ailabs/config/routing.yml @@ -10,6 +10,21 @@ privet_stablediffusion_page: path: /ailabs/stablediffusion defaults: { _controller: privet.ailabs.controller_stablediffusion:execute } +privet_midjourney_page: + path: /ailabs/midjourney + defaults: { _controller: privet.ailabs.controller_midjourney:execute } + +privet_midjourney_callback: + path: /ailabs/midjourney/callback/{job_id}/{ref}/{action} + methods: [POST] + defaults: + _controller: privet.ailabs.controller_midjourney:callback + mode: 'post' + requirements: + job_id: \d+ + ref: "[a-zA-Z0-9]+" + action: posted|reply + privet_scriptexecute_page: path: /ailabs/scriptexecute defaults: { _controller: privet.ailabs.controller_scriptexecute:execute } diff --git a/privet/ailabs/config/services.yml b/privet/ailabs/config/services.yml index 57240b1..3c716ba 100644 --- a/privet/ailabs/config/services.yml +++ b/privet/ailabs/config/services.yml @@ -85,6 +85,23 @@ services: - '%privet.ailabs.tables.users%' - '%privet.ailabs.tables.jobs%' + privet.ailabs.controller_midjourney: + class: privet\ailabs\controller\midjourney + arguments: + - '@auth' + - '@config' + - '@dbal.conn' + - '@controller.helper' + - '@language' + - '@request' + - '@template' + - '@user' + - '@service_container' + - '%core.php_ext%' + - '%core.root_path%' + - '%privet.ailabs.tables.users%' + - '%privet.ailabs.tables.jobs%' + privet.ailabs.controller_scriptexecute: class: privet\ailabs\controller\scriptexecute arguments: diff --git a/privet/ailabs/controller/acp_controller.php b/privet/ailabs/controller/acp_controller.php index e653c57..fcc0003 100644 --- a/privet/ailabs/controller/acp_controller.php +++ b/privet/ailabs/controller/acp_controller.php @@ -38,6 +38,7 @@ class acp_controller //implements acp_interface '/ailabs/chatgpt', '/ailabs/dalle', '/ailabs/stablediffusion', + '/ailabs/midjourney', '/ailabs/scriptexecute' ]; diff --git a/privet/ailabs/controller/chatgpt.php b/privet/ailabs/controller/chatgpt.php index 1362060..c6d7677 100644 --- a/privet/ailabs/controller/chatgpt.php +++ b/privet/ailabs/controller/chatgpt.php @@ -18,7 +18,8 @@ use privet\ailabs\includes\resultParse; /* -config +config (example) + { "api_key": "", "url_chat": "https://api.openai.com/v1/chat/completions", @@ -31,10 +32,13 @@ config "presence_penalty": 0.6, "prefix": "This is optional field you can remove it or populate with something like this -> Pretend your are Bender from Futurma", "prefix_tokens": 16 +"max_quote_length": 10 } template + {info}[quote={poster_name} post_id={post_id} user_id={poster_id}]{request}[/quote]{response} + */ class chatgpt extends AIController @@ -92,7 +96,7 @@ class chatgpt extends AIController $post_first_discarded = null; $mode = $this->job['post_mode']; - $history = ['post_text' => $this->job['post_text']]; + $history = ['post_text' => $this->job['post_text']]; $pattern = '/job['ailabs_username'] . '"\spost_id="(.*)"\stime="(.*)"\suser_id="' . $this->job['ailabs_user_id'] . '">/'; @@ -116,7 +120,7 @@ class chatgpt extends AIController if ($matches != null && !empty($matches) && !empty($matches[1][0])) { $postid = (int) $matches[1][0]; - $sql = 'SELECT j.job_id, j.post_id, j.response_post_id, j.request, j.response, p.post_text, j.request_tokens, j.response_tokens ' . + $sql = 'SELECT j.job_id, j.post_id, j.response_post_id, j.request, j.response, p.post_text, p.post_time, j.request_tokens, j.response_tokens ' . 'FROM ' . $this->jobs_table . ' j ' . 'JOIN ' . POSTS_TABLE . ' p ON p.post_id = j.post_id ' . 'WHERE ' . $this->db->sql_build_array('SELECT', ['response_post_id' => $postid]); @@ -145,11 +149,34 @@ class chatgpt extends AIController $post_first_taken = $postid; $history_tokens += $count_tokens; + $history_decoded_request = utf8_decode_ncr($history['request']); + $history_decoded_response = utf8_decode_ncr($history['response']); + array_unshift( $messages, - ['role' => 'user', 'content' => trim($history['request'])], - ['role' => 'assistant', 'content' => trim($history['response'])] + ['role' => 'user', 'content' => trim($history_decoded_request)], + ['role' => 'assistant', 'content' => trim($history_decoded_response)] ); + + if ($round == 0) { + // Remove quoted content from the quoted post + $post_text = sprintf( + '[quote=%1$s post_id=%2$s time=%3$s user_id=%4$s]%6$s[/quote]%5$s', + $this->job['ailabs_username'], + (string) $postid, + (string) $this->job['post_time'], + (string) $this->job['ailabs_user_id'], + $this->job['request'], + property_exists($this->cfg, 'max_quote_length') ? + $this->trim_words($history_decoded_response, (int) $this->cfg->max_quote_length) : $history_decoded_response, + ); + + $sql = 'UPDATE ' . POSTS_TABLE . + ' SET ' . $this->db->sql_build_array('UPDATE', ['post_text' => utf8_encode_ucr($post_text)]) . + ' WHERE post_id = ' . (int) $this->job['post_id']; + $result = $this->db->sql_query($sql); + $this->db->sql_freeresult($result); + } } } } while (!empty($history)); @@ -269,7 +296,7 @@ class chatgpt extends AIController 'status' => $this->job['status'], 'attempts' => $this->job['attempts'] + 1, 'response_time' => $this->job['response_time'], - 'response' => $api_response, + 'response' => utf8_encode_ucr($api_response), 'request_tokens' => $request_tokens - $history_tokens - $prefix_tokens, 'response_post_id' => $this->job['response_post_id'], 'response_tokens' => $response_tokens, diff --git a/privet/ailabs/controller/dalle.php b/privet/ailabs/controller/dalle.php index d22b371..ffc1d81 100644 --- a/privet/ailabs/controller/dalle.php +++ b/privet/ailabs/controller/dalle.php @@ -159,7 +159,7 @@ class dalle extends GenericController array_push($images, $item->url); } else { $filename = $this->save_base64_to_temp_file($item->b64_json, $ind); - $item->b64_json = ''; + $item->b64_json = ''; array_push($images, $filename); } $ind++; diff --git a/privet/ailabs/controller/midjourney.php b/privet/ailabs/controller/midjourney.php new file mode 100644 index 0000000..9aaa3c5 --- /dev/null +++ b/privet/ailabs/controller/midjourney.php @@ -0,0 +1,359 @@ +", + "url_imagine": "https://api.useapi.net/v1/jobs/imagine", + "url_button": "https://api.useapi.net/v1/jobs/button", + "discord": "", + "server": "", + "channel": "", + "maxJobs": "", + "retryCount": "", + "timeoutBeforeRetrySec": "