Skip to content

Commit

Permalink
feat: 增加chatgpt输入联想功能
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsonliu committed Jul 31, 2023
1 parent ede7e45 commit 6714211
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/core/hooks/Suggester.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default class Suggester extends SyntaxBase {
*/
getSystemSuggestList() {
const locales = this.$locale;
return [
const suggestList = [
{
icon: 'h1',
label: locales['H1 Heading'],
Expand Down Expand Up @@ -146,7 +146,32 @@ export default class Suggester extends SyntaxBase {
keyword: 'detail',
value: `+++ 点击展开更多\n内容\n++- 默认展开\n内容\n++ 默认收起\n内容\n+++\n`,
},
{
icon: 'pen',
label: '续写',
keyword: 'xu xie chatgpt',
value: () => {
if (!this.$engine.$cherry.options.openai.apiKey) {
return '请先配置openai apiKey';
}
this.$engine.$cherry.toolbar.toolbarHandlers.chatgpt('complement');
return `\n`;
},
},
{
icon: 'pen',
label: '总结',
keyword: 'zong jie chatgpt',
value: () => {
if (!this.$engine.$cherry.options.openai.apiKey) {
return '请先配置openai apiKey';
}
this.$engine.$cherry.toolbar.toolbarHandlers.chatgpt('summary');
return `\n`;
},
},
];
return suggestList;
}

/**
Expand Down Expand Up @@ -536,6 +561,13 @@ class SuggesterPanel {
) {
result = this.optionList[idx].value;
}
if (
typeof this.optionList[idx] === 'object' &&
this.optionList[idx] !== null &&
typeof this.optionList[idx].value === 'function'
) {
result = this.optionList[idx].value();
}
if (typeof this.optionList[idx] === 'string') {
result = ` ${this.keyword}${this.optionList[idx]} `;
}
Expand Down

0 comments on commit 6714211

Please sign in to comment.