Skip to content

Commit

Permalink
feat: 更换chatgpt模型
Browse files Browse the repository at this point in the history
  • Loading branch information
BUB97 committed Jul 29, 2023
1 parent 819c0f9 commit 5c74bcc
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
29 changes: 20 additions & 9 deletions dist/cherry-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -66426,9 +66426,9 @@

var inputText = selection || this.$cherry.editor.editor.getValue();
queryMap[name].apply(this, [inputText]).then(function (res) {
var _res$data, _res$data$choices, _res$data$choices$;
var _res$data, _res$data$choices, _res$data$choices$, _res$data$choices$$me;

return _this2.concatText(_this2, [selection, ((_res$data = res.data) === null || _res$data === void 0 ? void 0 : (_res$data$choices = _res$data.choices) === null || _res$data$choices === void 0 ? void 0 : (_res$data$choices$ = _res$data$choices[0]) === null || _res$data$choices$ === void 0 ? void 0 : _res$data$choices$.text) || '']);
return _this2.concatText(selection, ((_res$data = res.data) === null || _res$data === void 0 ? void 0 : (_res$data$choices = _res$data.choices) === null || _res$data$choices === void 0 ? void 0 : (_res$data$choices$ = _res$data$choices[0]) === null || _res$data$choices$ === void 0 ? void 0 : (_res$data$choices$$me = _res$data$choices$.message) === null || _res$data$choices$$me === void 0 ? void 0 : _res$data$choices$$me.content) || '');
})["catch"](function (res) {
var _res$response, _res$response$data, _res$response$data$er;

Expand All @@ -66446,18 +66446,29 @@

return ChatGpt;
}(MenuBase);
var generatePromptMap = (_generatePromptMap = {}, _defineProperty(_generatePromptMap, FUNC_MAP.COMPLEMENT, function (text) {
var generatePromptMap = (_generatePromptMap = {}, _defineProperty(_generatePromptMap, FUNC_MAP.COMPLEMENT, function (text, language) {
if (language === 'zh_CN') {
return "\u8BF7\u7EED\u5199\u4EE5\u4E0B\u6587\u5B57: ".concat(text);
}

return "continue writing with the following text: ".concat(text);
}), _defineProperty(_generatePromptMap, FUNC_MAP.SUMMARY, function (text) {
}), _defineProperty(_generatePromptMap, FUNC_MAP.SUMMARY, function (text, language) {
if (language === 'zh_CN') {
return "\u8BF7\u603B\u7ED3\u4EE5\u4E0B\u6587\u5B57: ".concat(text);
}

return "summary the following text: ".concat(text);
}), _generatePromptMap);

function queryCompletion(type, input) {
return this.openai.createCompletion({
model: 'text-davinci-003',
prompt: generatePromptMap[type](input),
temperature: 0.6,
max_tokens: 500
return this.openai.createChatCompletion({
model: 'gpt-3.5-turbo',
messages: [{
role: 'user',
content: generatePromptMap[type](input, this.$cherry.options.locale || '')
}] // temperature: 0.6,
// max_tokens: 500,

}, {
proxy: this.proxy
});
Expand Down
2 changes: 1 addition & 1 deletion dist/cherry-markdown.js.map

Large diffs are not rendered by default.

27 changes: 19 additions & 8 deletions src/toolbars/hooks/ChatGpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default class ChatGpt extends MenuBase {
const inputText = selection || this.$cherry.editor.editor.getValue();
queryMap[name]
.apply(this, [inputText])
.then((res) => this.concatText(this, [selection, res.data?.choices?.[0]?.text || '']))
.then((res) => this.concatText(selection, res.data?.choices?.[0]?.message?.content || ''))
.catch((res) => {
// 请求失败处理,两种方案
// 1. 抛出一个事件给第三方使用者,在cherry里怎么实现?
Expand All @@ -129,21 +129,32 @@ export default class ChatGpt extends MenuBase {
}

const generatePromptMap = {
[FUNC_MAP.COMPLEMENT](text) {
[FUNC_MAP.COMPLEMENT](text, language) {
if (language === 'zh_CN') {
return `请续写以下文字: ${text}`;
}
return `continue writing with the following text: ${text}`;
},
[FUNC_MAP.SUMMARY](text) {
[FUNC_MAP.SUMMARY](text, language) {
if (language === 'zh_CN') {
return `请总结以下文字: ${text}`;
}
return `summary the following text: ${text}`;
},
};

function queryCompletion(type, input) {
return this.openai.createCompletion(
return this.openai.createChatCompletion(
{
model: 'text-davinci-003',
prompt: generatePromptMap[type](input),
temperature: 0.6,
max_tokens: 500,
model: 'gpt-3.5-turbo',
messages: [
{
role: 'user',
content: generatePromptMap[type](input, this.$cherry.options.locale || ''),
},
],
// temperature: 0.6,
// max_tokens: 500,
},
{
proxy: this.proxy,
Expand Down

0 comments on commit 5c74bcc

Please sign in to comment.