-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
2,744 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
jQuery( function ( $ ) { | ||
var ajax; | ||
|
||
if (typeof ajax_object !== 'undefined') { | ||
ajax = ajax_object; | ||
} | ||
|
||
updateBalance(); | ||
|
||
$( '.autocomplete-enter-api-key-box a' ).on( 'click', function ( e ) { | ||
e.preventDefault(); | ||
|
||
var div = $( '.enter-api-key' ); | ||
div.show( 500 ); | ||
div.find( 'input[name=key]' ).focus(); | ||
|
||
$( this ).hide(); | ||
} ); | ||
|
||
$( '#autocomplete-job-output').on('click', function ( e ) { | ||
copyToClipboard($('#autocomplete-job-output span').html()); | ||
alertSuccess('Job output copied to clipboard!'); | ||
}); | ||
|
||
$( '#autocomplete-job-input').on('click', function ( e ) { | ||
copyToClipboard($('#autocomplete-job-input span').html()); | ||
alertSuccess('Job input copied to clipboard!'); | ||
}); | ||
|
||
function alertError(msg='') { | ||
return swal("AutoComplete Error", msg, "error"); | ||
} | ||
|
||
function alertSuccess(msg ='') { | ||
return swal('AutoComplete Success', msg, 'success'); | ||
} | ||
|
||
function alertWarning(msg='') { | ||
return swal('AutoComplete Warning', msg, 'warning'); | ||
} | ||
|
||
function updateBalance() { | ||
if (ajax) { | ||
let errMsg = 'Unable to fetch account details.'; | ||
$.ajax({ | ||
type: 'POST', | ||
url: ajax.ajax_url, | ||
data: { | ||
'action': 'fetch_account_details', | ||
}, | ||
datatype: 'json', | ||
success: function (response) { | ||
let data = JSON.parse(response) ?? {}; | ||
if (data.status && data.status !== 200) { | ||
if (data.message) { | ||
errMsg = data.message; | ||
} | ||
return alertError(errMsg); | ||
} | ||
if (data.username) { | ||
$('#autocomplete-username').html(data.username); | ||
$('#autocomplete-balance').html(data.balance); | ||
} | ||
}, error: function (response) { | ||
alertError(errMsg) | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
function showSpinner() | ||
{ | ||
$('#autocomplete .inside').prepend('<div id="autocomplete-spinner"><i class="autocomplete-spin"></i><span>Running job (be patient, complex jobs can take some time)...</span></div>'); | ||
} | ||
|
||
function hideSpinner() | ||
{ | ||
$('#autocomplete-spinner').remove(); | ||
} | ||
|
||
function copyToClipboard(text) { | ||
let $temp = $("<input>"); | ||
$("body").append($temp); | ||
$temp.val(text).select(); | ||
document.execCommand("copy"); | ||
$temp.remove(); | ||
} | ||
|
||
$('#autocomplete-submit').on('click', function ( e ) { | ||
e.preventDefault(); | ||
|
||
var input = ""; | ||
$('.is-root-container p[role="document"]').each(function(k,v) { | ||
input = input + v.innerText + "\n"; | ||
}); | ||
|
||
if (input.length < 1) { | ||
alertError('A Paragraph block is required.'); | ||
return; | ||
} | ||
|
||
input = input.trim(); | ||
let tokens = $('#autocomplete-tokens').val(); | ||
let temperature = $('#autocomplete-temperature').val(); | ||
let readability = $('#autocomplete-readability').is(':checked'); | ||
|
||
if (tokens < 1 || tokens > 2048) { | ||
alertError('Tokens out of range. (1 - 2048)'); | ||
return; | ||
} | ||
|
||
if (temperature > 1.0 || temperature < 0.1) { | ||
alertError('Temperature out of range. (0.1 - 1.0)'); | ||
return; | ||
} | ||
|
||
if (!input.length) { | ||
alertError('You must type something in your Paragraph or Code block.'); | ||
return; | ||
} | ||
|
||
if (ajax) { | ||
let errMsg = 'Oops! Something went wrong...'; | ||
$.ajax({ | ||
type: 'POST', | ||
url: ajax.ajax_url, | ||
data: { | ||
'action': 'text_generate', | ||
'input': input, | ||
'output_tokens': tokens, | ||
'optimize_readability': readability, | ||
'temperature': temperature | ||
}, | ||
datatype: 'json', | ||
beforeSend: function () { | ||
$('#autocomplete-job-output-container').addClass('autocomplete-hidden'); | ||
showSpinner(); | ||
}, | ||
complete: function () { | ||
hideSpinner(); | ||
}, | ||
success: function (response) { | ||
let data = JSON.parse(response); | ||
if (data.status && data.status !== 200) { | ||
if (data.message) { | ||
errMsg = data.message; | ||
} | ||
return alertError(errMsg); | ||
} | ||
|
||
let cost = data.cost ?? 0; | ||
|
||
$('#autocomplete-job-cost span').html(cost); | ||
|
||
let output = data.output.replace(/\\/g,"").trim(); | ||
if (output.length > 0) { | ||
let combined = data.combined.replace(/\\/g,"").trim(); | ||
$('#autocomplete-job-input span').html(data.input.trim()); | ||
$('#autocomplete-job-output span').html(data.output.trim()); | ||
/* | ||
* TODO: automatically insert into post body | ||
$('.wp-block-post-title').focus(); | ||
$block.html(combined.trim().replaceAll('\n', '<br data-rich-text-line-break="true">')); | ||
$('.is-root-container.block-editor-block-list__layout').click(); | ||
*/ | ||
alertSuccess(combined); | ||
} else { | ||
alertWarning('No output detected. Try adjusting the input and or the number of tokens used. If the problem persists please contact support.'); | ||
} | ||
|
||
$('#autocomplete-job-output-container').removeClass('autocomplete-hidden'); | ||
}, error: function (response) { | ||
alertError(errMsg); | ||
}, | ||
}).then(function () { | ||
updateBalance(); | ||
}); | ||
} | ||
}); | ||
|
||
$('#autocomplete .handlediv').html('<span aria-hidden="true"><svg width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" class="components-panel__arrow" role="img" aria-hidden="true" focusable="false"><path d="M17.5 11.6L12 16l-5.5-4.4.9-1.2L12 14l4.5-3.6 1 1.2z"></path></svg></span>'); | ||
$('#autocomplete .postbox').addClass('closed'); | ||
|
||
$('.postbox-header').on('click', function ( e ) { | ||
let $path = $('#autocomplete button.handlediv svg path'); | ||
if ($('#autocomplete .inside').is(':visible')) { | ||
$path.attr('d', 'M6.5 12.4L12 8l5.5 4.4-.9 1.2L12 10l-4.5 3.6-1-1.2z'); | ||
} else { | ||
$path.attr('d', 'M17.5 11.6L12 16l-5.5-4.4.9-1.2L12 14l4.5-3.6 1 1.2z'); | ||
} | ||
}); | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
/** | ||
* @package autocomplete | ||
*/ | ||
/* | ||
Plugin Name: AutoComplete.sh | ||
Plugin URI: https://www.autocomplete.sh | ||
Description: Make your blog posts intelligent with AutoComplete's NLP text generation API. | ||
Version: 1.0 | ||
Author: AutoComplete.sh | ||
Author URI: https://github.com/AutoComplete-sh | ||
License: GPLv2 or later | ||
License URI: https://www.gnu.org/licenses/gpl-2.0.html | ||
Text Domain: autocomplete | ||
*/ | ||
|
||
/* | ||
This program is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License | ||
as published by the Free Software Foundation; either version 2 | ||
of the License, or (at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
Copyright 2022 AutoComplete.sh. | ||
*/ | ||
|
||
// Make sure we don't expose any info if called directly | ||
if ( !function_exists( 'add_action' ) ) { | ||
echo 'This plugin cannot be called directly'; | ||
exit; | ||
} | ||
|
||
define( 'AUTOCOMPLETE_VERSION', '1.0.0-'.time() ); | ||
define( 'AUTOCOMPLETE_MINIMUM_WP_VERSION', '5.0' ); | ||
define( 'AUTOCOMPLETE_DESCRIPTION', 'Make your blog posts intelligent with AutoComplete\'s NLP text generation API'); | ||
define( 'AUTOCOMPLETE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); | ||
define( 'AUTOCOMPLETE_URL', 'https://autocomplete.sh'); | ||
define( 'AUTOCOMPLETE_ATTRIBUTION', '?r=ac-wp-plugin&cs=ac-wp-plugin&crs=1653005781'); | ||
define( 'AUTOCOMPLETE_URL_API', 'https://api.autocomplete.sh/v1'); | ||
define( 'AUTOCOMPLETE_EMAIL_SUPPORT', '[email protected]'); | ||
|
||
require_once(AUTOCOMPLETE_PLUGIN_DIR . 'helpers.php'); | ||
|
||
register_activation_hook( __FILE__, array( 'AutoComplete', 'plugin_activation' ) ); | ||
register_deactivation_hook( __FILE__, array( 'AutoComplete', 'plugin_deactivation' ) ); | ||
|
||
require_once( AUTOCOMPLETE_PLUGIN_DIR . 'class.autocomplete.php' ); | ||
require_once( AUTOCOMPLETE_PLUGIN_DIR . 'class.autocomplete_metabox.php' ); | ||
|
||
add_action( 'init', array( 'AutoComplete', 'init' ) ); | ||
|
||
if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { | ||
require_once( AUTOCOMPLETE_PLUGIN_DIR . 'class.autocomplete_admin.php' ); | ||
add_action( 'init', array( 'AutoComplete_Admin', 'init' ) ); | ||
} |
Oops, something went wrong.