mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 13:27:08 +00:00
feat: 添加星火设定自定义代码功能
This commit is contained in:
parent
d9c25140ac
commit
007909a156
4 changed files with 27 additions and 2 deletions
|
|
@ -1916,7 +1916,11 @@ export class chatgpt extends plugin {
|
|||
})
|
||||
// 获取图片资源
|
||||
const image = await getImg(e)
|
||||
let response = await client.sendMessage(prompt, conversation?.conversationId, image ? image[0] : undefined)
|
||||
let response = await client.sendMessage(prompt, {
|
||||
e,
|
||||
chatId: conversation?.conversationId,
|
||||
image: image ? image[0] : undefined
|
||||
})
|
||||
return response
|
||||
}
|
||||
case 'azure': {
|
||||
|
|
|
|||
|
|
@ -778,6 +778,11 @@
|
|||
"label": "序列化设定",
|
||||
"data": "xhPromptSerialize"
|
||||
},
|
||||
{
|
||||
"type": "check",
|
||||
"label": "运行执行设定中的代码",
|
||||
"data": "xhPromptEval"
|
||||
},
|
||||
{
|
||||
"type": "textarea",
|
||||
"label": "设定",
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ const defaultConfig = {
|
|||
xhMaxTokens: 1024,
|
||||
xhPromptSerialize: false,
|
||||
xhPrompt: '',
|
||||
xhPromptEval: false,
|
||||
xhRetRegExp: '',
|
||||
xhRetReplace: '',
|
||||
promptPrefixOverride: 'Your answer shouldn\'t be too verbose. Prefer to answer in Chinese.',
|
||||
|
|
|
|||
|
|
@ -375,7 +375,10 @@ export default class XinghuoClient {
|
|||
})
|
||||
}
|
||||
|
||||
async sendMessage(prompt, chatId, image) {
|
||||
async sendMessage(prompt, option) {
|
||||
let chatId = option?.chatId
|
||||
let image = option?.image
|
||||
|
||||
// 对星火预设的问题进行重写,避免收到预设回答
|
||||
prompt = this.promptBypassPreset(prompt)
|
||||
if (Config.xhmode == 'api' || Config.xhmode == 'apiv2' || Config.xhmode == 'assistants') {
|
||||
|
|
@ -392,6 +395,18 @@ export default class XinghuoClient {
|
|||
} else {
|
||||
Prompt = Config.xhPrompt ? [{ "role": "user", "content": Config.xhPrompt }] : []
|
||||
}
|
||||
if(Config.xhPromptEval) {
|
||||
Prompt.forEach(obj => {
|
||||
try {
|
||||
obj.content = obj.content.replace(/{{(.*?)}}/g, (match, variable) => {
|
||||
return Function(`"use strict";return ((e)=>{return ${variable} })`)()(option.e)
|
||||
})
|
||||
} catch (error) {
|
||||
logger.error(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
let { response, id } = await this.apiMessage(prompt, chatId, Prompt)
|
||||
if (Config.xhRetRegExp) {
|
||||
response = response.replace(new RegExp(Config.xhRetRegExp, 'g'), Config.xhRetReplace)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue