Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix recall chat history #51

Merged
merged 2 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions assets/js/alpaca-bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function onClickChange() {
copyMessage();
}

function performEventListener(input, action, target, scroll_to) {
function performEventListener(input, action, target, scroll_to, callback = null) {
input.addEventListener(action, function () {
// Do not submit if the message is empty
if (isBlank(target.value)) {
Expand All @@ -173,6 +173,11 @@ function performEventListener(input, action, target, scroll_to) {

// Submit form
onClickChange();

// Callback
if (callback) {
callback();
}
});
}

Expand Down Expand Up @@ -296,7 +301,7 @@ if (message) {
performEventListener(submit, 'click', message, 'loading');

// On #chat_history_id select change
performEventListener(chat_history_id, 'change', chat_history_id, 'dialog');
performEventListener(chat_history_id, 'change', chat_history_id, 'dialog', clearChat);

// On page load focus on the textarea #prompt
window.onload = function () {
Expand Down
4 changes: 2 additions & 2 deletions src/Api/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ abstract class Base
public function get_item_permissions_check($request)
{
if (!current_user_can(apply_filters(Options::appendPrefix('api-permissions-get'), self::PERMISSION_READ))) {
return new WP_Error('rest_forbidden', esc_html__('You cannot access this resource.'), ['status' => $this->authorization_status_code()]);
return new WP_Error('rest_forbidden', esc_html__('You cannot access this resource.', 'alpaca-bot'), ['status' => $this->authorization_status_code()]);
}
return true;
}
Expand All @@ -39,7 +39,7 @@ public function get_item_permissions_check($request)
public function update_item_permissions_check($request)
{
if (!current_user_can(apply_filters(Options::appendPrefix('api-permissions-update'), self::PERMISSION_WRITE))) {
return new WP_Error('rest_forbidden', esc_html__('You cannot modify this resource.'), ['status' => $this->authorization_status_code()]);
return new WP_Error('rest_forbidden', esc_html__('You cannot modify this resource.', 'alpaca-bot'), ['status' => $this->authorization_status_code()]);
}
return true;
}
Expand Down