Vanessa 2024-01-25 20:15:31 +08:00
parent eb9de3cbb9
commit be0a0a5f33
2 changed files with 33 additions and 18 deletions

View file

@ -32,7 +32,7 @@ export const AIActions = (elements: Element[], protyle: IProtyle) => {
ids.push(item.getAttribute("data-node-id"));
});
const customMenu: IMenu[] = [{
iconHTML: Constants.ZWSP,
iconHTML: "",
label: window.siyuan.languages.aiCustomAction,
click() {
const dialog = new Dialog({
@ -92,7 +92,7 @@ export const AIActions = (elements: Element[], protyle: IProtyle) => {
}
window.siyuan.storage[Constants.LOCAL_AI].forEach((item: { name: string, memo: string }) => {
customMenu.push({
iconHTML: Constants.ZWSP,
iconHTML: "",
action: "iconEdit",
label: `<div aria-label="${escapeAriaLabel(item.memo)}" class="ariaLabel">${escapeHtml(item.name)}</div>`,
bind: (element) => {
@ -172,7 +172,7 @@ export const AIActions = (elements: Element[], protyle: IProtyle) => {
label: window.siyuan.languages.ai,
type: "submenu",
submenu: [{
iconHTML: Constants.ZWSP,
iconHTML: "",
label: window.siyuan.languages.aiContinueWrite,
click() {
fetchPost("/api/ai/chatGPTWithAction", {ids, action: "Continue writing"}, (response) => {
@ -180,11 +180,11 @@ export const AIActions = (elements: Element[], protyle: IProtyle) => {
});
}
}, {
iconHTML: Constants.ZWSP,
iconHTML: "",
label: window.siyuan.languages.aiTranslate,
type: "submenu",
submenu: [{
iconHTML: Constants.ZWSP,
iconHTML: "",
label: window.siyuan.languages.aiTranslate_zh_Hans,
click() {
fetchPost("/api/ai/chatGPTWithAction", {
@ -195,7 +195,7 @@ export const AIActions = (elements: Element[], protyle: IProtyle) => {
});
}
}, {
iconHTML: Constants.ZWSP,
iconHTML: "",
label: window.siyuan.languages.aiTranslate_zh_Hant,
click() {
fetchPost("/api/ai/chatGPTWithAction", {
@ -206,7 +206,7 @@ export const AIActions = (elements: Element[], protyle: IProtyle) => {
});
}
}, {
iconHTML: Constants.ZWSP,
iconHTML: "",
label: window.siyuan.languages.aiTranslate_ja_JP,
click() {
fetchPost("/api/ai/chatGPTWithAction", {
@ -217,7 +217,7 @@ export const AIActions = (elements: Element[], protyle: IProtyle) => {
});
}
}, {
iconHTML: Constants.ZWSP,
iconHTML: "",
label: window.siyuan.languages.aiTranslate_ko_KR,
click() {
fetchPost("/api/ai/chatGPTWithAction", {
@ -228,7 +228,7 @@ export const AIActions = (elements: Element[], protyle: IProtyle) => {
});
}
}, {
iconHTML: Constants.ZWSP,
iconHTML: "",
label: window.siyuan.languages.aiTranslate_en_US,
click() {
fetchPost("/api/ai/chatGPTWithAction", {
@ -239,7 +239,7 @@ export const AIActions = (elements: Element[], protyle: IProtyle) => {
});
}
}, {
iconHTML: Constants.ZWSP,
iconHTML: "",
label: window.siyuan.languages.aiTranslate_es_ES,
click() {
fetchPost("/api/ai/chatGPTWithAction", {
@ -250,7 +250,7 @@ export const AIActions = (elements: Element[], protyle: IProtyle) => {
});
}
}, {
iconHTML: Constants.ZWSP,
iconHTML: "",
label: window.siyuan.languages.aiTranslate_fr_FR,
click() {
fetchPost("/api/ai/chatGPTWithAction", {
@ -261,7 +261,7 @@ export const AIActions = (elements: Element[], protyle: IProtyle) => {
});
}
}, {
iconHTML: Constants.ZWSP,
iconHTML: "",
label: window.siyuan.languages.aiTranslate_de_DE,
click() {
fetchPost("/api/ai/chatGPTWithAction", {
@ -273,7 +273,7 @@ export const AIActions = (elements: Element[], protyle: IProtyle) => {
}
}]
}, {
iconHTML: Constants.ZWSP,
iconHTML: "",
label: window.siyuan.languages.aiExtractSummary,
click() {
fetchPost("/api/ai/chatGPTWithAction", {
@ -284,7 +284,7 @@ export const AIActions = (elements: Element[], protyle: IProtyle) => {
});
}
}, {
iconHTML: Constants.ZWSP,
iconHTML: "",
label: window.siyuan.languages.aiBrainStorm,
click() {
fetchPost("/api/ai/chatGPTWithAction", {
@ -295,7 +295,7 @@ export const AIActions = (elements: Element[], protyle: IProtyle) => {
});
}
}, {
iconHTML: Constants.ZWSP,
iconHTML: "",
label: window.siyuan.languages.aiFixGrammarSpell,
click() {
fetchPost("/api/ai/chatGPTWithAction", {
@ -306,7 +306,18 @@ export const AIActions = (elements: Element[], protyle: IProtyle) => {
});
}
}, {
iconHTML: Constants.ZWSP,
iconHTML: "",
label: window.siyuan.languages.aiFixGrammarSpell,
click() {
fetchPost("/api/ai/chatGPTWithAction", {
ids,
action: "Clear context"
}, (response) => {
fillContent(protyle, response.data, elements);
});
}
}, {
iconHTML: "",
label: window.siyuan.languages.custom,
type: "submenu",
submenu: customMenu

View file

@ -23,15 +23,19 @@ export const AIChat = (protyle: IProtyle, element: Element) => {
dialog.destroy();
});
btnsElement[1].addEventListener("click", () => {
let inputValue = inputElement.value;
fetchPost("/api/ai/chatGPT", {
msg: inputElement.value,
msg: inputValue,
}, (response) => {
dialog.destroy();
let respContent = "";
if (response.data && "" !== response.data) {
respContent = "\n\n" + response.data;
}
fillContent(protyle, `${inputElement.value}${respContent}`, [element]);
if (inputValue === "Clear context") {
inputValue = "";
}
fillContent(protyle, `${inputValue}${respContent}`, [element]);
});
});
};