mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 05:17:10 +00:00
feat: support system message in api mode
This commit is contained in:
parent
7dbb3ad0b5
commit
17fb123e3b
4 changed files with 137 additions and 157 deletions
|
|
@ -671,21 +671,22 @@ export class chatgpt extends plugin {
|
|||
if (Config.model) {
|
||||
completionParams.model = Config.model
|
||||
}
|
||||
const currentDate = new Date().toISOString().split('T')[0]
|
||||
let promptPrefix = `You are ${Config.assistantLabel}, a large language model trained by OpenAI. ${Config.promptPrefixOverride || defaultPropmtPrefix}
|
||||
Current date: ${currentDate}`
|
||||
this.chatGPTApi = new ChatGPTAPI({
|
||||
apiKey: Config.apiKey,
|
||||
debug: false,
|
||||
upsertMessage,
|
||||
getMessageById,
|
||||
systemMessage: promptPrefix,
|
||||
completionParams,
|
||||
assistantLabel: Config.assistantLabel,
|
||||
fetch
|
||||
})
|
||||
const currentDate = new Date().toISOString().split('T')[0]
|
||||
let promptPrefix = `You are ${Config.assistantLabel}, a large language model trained by OpenAI. ${Config.promptPrefixOverride || defaultPropmtPrefix}
|
||||
Current date: ${currentDate}`
|
||||
let option = {
|
||||
timeoutMs: 120000,
|
||||
promptPrefix
|
||||
systemMessage: promptPrefix
|
||||
}
|
||||
if (conversation) {
|
||||
option = Object.assign(option, conversation)
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ export default {
|
|||
// 模型名称,选填。如无特殊需求保持默认即可,会使用chatgpt-api库提供的当前可用的最适合的默认值。保底可用的是 text-davinci-003。当发现新的可用的chatGPT模型会更新这里的值
|
||||
// 20230211: text-chat-davinci-002-sh-alpha-aoruigiofdj83 中午存活了几分钟
|
||||
// model: '',
|
||||
// temperature: 0.8,
|
||||
// ***********************************************************************************************************************************
|
||||
// 以下为API3方式的配置 *
|
||||
// ***********************************************************************************************************************************
|
||||
|
|
@ -48,16 +49,6 @@ export default {
|
|||
// 或者 https://gpt.pawan.krd/backend-api
|
||||
// apiBaseUrl: 'https://chatgpt.duti.tech/api',
|
||||
// ***********************************************************************************************************************************
|
||||
// 以下为API2方式的配置 *
|
||||
// ***********************************************************************************************************************************
|
||||
// 如果购买了plus,改为true将使用收费模型,响应更快
|
||||
// plus: false,
|
||||
// 使用谁提供的第三方API。github开源的有几个,没特别要求保持默认就好
|
||||
// https://chatgpt.pawan.krd/api/completions 来自https://github.com/PawanOsman 使用Cloudflare CDN,三网延迟可能都较高。目前看起来最稳定
|
||||
// https://chatgpt.roki.best/api/completions 对上面那个的二次反代,搭建在Hong Kong(本人自建,不保证稳定性)
|
||||
// https://chatgpt.hato.ai/completions 来自https://github.com/waylaidwanderer(本插件使用的chatgpt库之一的作者)
|
||||
// reverseProxy: 'https://chatgpt.pawan.krd/api/completions',
|
||||
// ***********************************************************************************************************************************
|
||||
// 以下为API/API2方式公用的配置 *
|
||||
// ***********************************************************************************************************************************
|
||||
// 给模型的前言promt。选填。默认完整值:`You are ${this._assistantLabel}, a large language model trained by OpenAI. You answer as concisely as possible for each response (e.g. don’t be verbose). It is very important that you answer as concisely as possible, so please remember this. If you are generating a list, do not have too many items. Keep the number of items short. Current date: ${currentDate}\n\n
|
||||
|
|
|
|||
268
guoba.support.js
268
guoba.support.js
|
|
@ -1,7 +1,7 @@
|
|||
import { Config } from './utils/config.js'
|
||||
|
||||
// 支持锅巴
|
||||
export function supportGuoba() {
|
||||
export function supportGuoba () {
|
||||
return {
|
||||
// 插件信息,将会显示在前端页面
|
||||
// 如果你的插件没有在插件库里,那么需要填上补充信息
|
||||
|
|
@ -19,7 +19,7 @@ export function supportGuoba() {
|
|||
// 图标可在 https://icon-sets.iconify.design 这里进行搜索
|
||||
icon: 'simple-icons:openai',
|
||||
// 图标颜色,例:#FF0000 或 rgb(255, 0, 0)
|
||||
iconColor: '#00c3ff',
|
||||
iconColor: '#00c3ff'
|
||||
},
|
||||
// 配置项信息
|
||||
configInfo: {
|
||||
|
|
@ -29,51 +29,51 @@ export function supportGuoba() {
|
|||
field: 'blockWords',
|
||||
label: '输出黑名单',
|
||||
bottomHelpMessage: '检查输出结果中是否有违禁词,如果存在黑名单中的违禁词则不输出',
|
||||
component: 'InputTextArea',
|
||||
component: 'InputTextArea'
|
||||
},
|
||||
{
|
||||
field: 'promptBlockWords',
|
||||
label: '输入黑名单',
|
||||
bottomHelpMessage: '检查输入结果中是否有违禁词,如果存在黑名单中的违禁词则不输出',
|
||||
component: 'InputTextArea',
|
||||
component: 'InputTextArea'
|
||||
},
|
||||
{
|
||||
field: 'imgOcr',
|
||||
label: '图片识别',
|
||||
bottomHelpMessage: '是否识别消息中图片的文字内容,需要同时包含图片和消息才生效',
|
||||
component: 'Switch',
|
||||
component: 'Switch'
|
||||
},
|
||||
{
|
||||
field: 'defaultUsePicture',
|
||||
label: '全局图片模式',
|
||||
bottomHelpMessage: '全局默认以图片形式回复,并自动发出Continue命令补全回答。长回复可能会有bug。',
|
||||
component: 'Switch',
|
||||
component: 'Switch'
|
||||
},
|
||||
{
|
||||
field: 'autoUsePicture',
|
||||
label: '长文本自动转图片',
|
||||
bottomHelpMessage: '字数大于阈值会自动用图片发送,即使是文本模式。',
|
||||
component: 'Switch',
|
||||
field: 'autoUsePicture',
|
||||
label: '长文本自动转图片',
|
||||
bottomHelpMessage: '字数大于阈值会自动用图片发送,即使是文本模式。',
|
||||
component: 'Switch'
|
||||
},
|
||||
{
|
||||
field: 'autoUsePictureThreshold',
|
||||
label: '自动转图片阈值',
|
||||
helpMessage: '长文本自动转图片开启后才生效',
|
||||
bottomHelpMessage: '自动转图片的字数阈值。',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
min: 0,
|
||||
},
|
||||
field: 'autoUsePictureThreshold',
|
||||
label: '自动转图片阈值',
|
||||
helpMessage: '长文本自动转图片开启后才生效',
|
||||
bottomHelpMessage: '自动转图片的字数阈值。',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
min: 0
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'conversationPreserveTime',
|
||||
label: '对话保留时长',
|
||||
helpMessage: '单位:秒',
|
||||
bottomHelpMessage: '每个人发起的对话保留时长。超过这个时长没有进行对话,再进行对话将开启新的对话。',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
min: 0,
|
||||
},
|
||||
field: 'conversationPreserveTime',
|
||||
label: '对话保留时长',
|
||||
helpMessage: '单位:秒',
|
||||
bottomHelpMessage: '每个人发起的对话保留时长。超过这个时长没有进行对话,再进行对话将开启新的对话。',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
min: 0
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'toggleMode',
|
||||
|
|
@ -82,207 +82,195 @@ export function supportGuoba() {
|
|||
component: 'Select',
|
||||
componentProps: {
|
||||
options: [
|
||||
{label: 'at', value: 'at'},
|
||||
{label: '#chat', value: 'prefix'},
|
||||
],
|
||||
},
|
||||
{ label: 'at', value: 'at' },
|
||||
{ label: '#chat', value: 'prefix' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'quoteReply',
|
||||
label: '图片引用消息',
|
||||
bottomHelpMessage: '在回复图片时引用原始消息',
|
||||
component: 'Switch',
|
||||
field: 'quoteReply',
|
||||
label: '图片引用消息',
|
||||
bottomHelpMessage: '在回复图片时引用原始消息',
|
||||
component: 'Switch'
|
||||
},
|
||||
{
|
||||
field: 'showQRCode',
|
||||
label: '启用二维码',
|
||||
bottomHelpMessage: '在图片模式中启用二维码。该对话内容将被发送至第三方服务器以进行渲染展示,如果不希望对话内容被上传到第三方服务器请关闭此功能。',
|
||||
component: 'Switch',
|
||||
field: 'showQRCode',
|
||||
label: '启用二维码',
|
||||
bottomHelpMessage: '在图片模式中启用二维码。该对话内容将被发送至第三方服务器以进行渲染展示,如果不希望对话内容被上传到第三方服务器请关闭此功能。',
|
||||
component: 'Switch'
|
||||
},
|
||||
{
|
||||
field: 'cacheUrl',
|
||||
label: '渲染服务器地址',
|
||||
bottomHelpMessage: '用于缓存图片模式会话内容并渲染的服务器地址。',
|
||||
component: 'Input',
|
||||
component: 'Input'
|
||||
},
|
||||
{
|
||||
field: 'cacheEntry',
|
||||
label: '预制渲染服务器访问代码',
|
||||
bottomHelpMessage: '图片内容渲染服务器开启预制访问代码,当渲染服务器访问较慢时可以开启,但无法保证访问代码可以正常访问页面。',
|
||||
component: 'Switch',
|
||||
field: 'cacheEntry',
|
||||
label: '预制渲染服务器访问代码',
|
||||
bottomHelpMessage: '图片内容渲染服务器开启预制访问代码,当渲染服务器访问较慢时可以开启,但无法保证访问代码可以正常访问页面。',
|
||||
component: 'Switch'
|
||||
},
|
||||
{
|
||||
field: 'drawCD',
|
||||
label: '绘图CD',
|
||||
helpMessage: '单位:秒',
|
||||
bottomHelpMessage: '绘图指令的CD时间,主人不受限制',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
min: 0,
|
||||
},
|
||||
field: 'drawCD',
|
||||
label: '绘图CD',
|
||||
helpMessage: '单位:秒',
|
||||
bottomHelpMessage: '绘图指令的CD时间,主人不受限制',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
min: 0
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'proxy',
|
||||
label: '代理服务器地址',
|
||||
bottomHelpMessage: '数据通过代理服务器发送,http或socks5代理。',
|
||||
component: 'Input',
|
||||
component: 'Input'
|
||||
},
|
||||
{
|
||||
field: 'debug',
|
||||
label: '调试信息',
|
||||
bottomHelpMessage: '将输出更多调试信息,如果不希望控制台刷屏的话,可以关闭。',
|
||||
component: 'Switch',
|
||||
field: 'debug',
|
||||
label: '调试信息',
|
||||
bottomHelpMessage: '将输出更多调试信息,如果不希望控制台刷屏的话,可以关闭。',
|
||||
component: 'Switch'
|
||||
},
|
||||
{
|
||||
label: '以下为服务超时配置。',
|
||||
component: 'Divider',
|
||||
label: '以下为服务超时配置。',
|
||||
component: 'Divider'
|
||||
},
|
||||
{
|
||||
field: 'defaultTimeoutMs',
|
||||
label: '默认超时时间',
|
||||
helpMessage: '单位:毫秒',
|
||||
bottomHelpMessage: '各个地方的默认超时时间。',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
min: 0,
|
||||
},
|
||||
field: 'defaultTimeoutMs',
|
||||
label: '默认超时时间',
|
||||
helpMessage: '单位:毫秒',
|
||||
bottomHelpMessage: '各个地方的默认超时时间。',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
min: 0
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'chromeTimeoutMS',
|
||||
label: '浏览器超时时间',
|
||||
helpMessage: '单位:毫秒',
|
||||
bottomHelpMessage: '浏览器默认超时,浏览器可能需要更高的超时时间。',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
min: 0,
|
||||
},
|
||||
field: 'chromeTimeoutMS',
|
||||
label: '浏览器超时时间',
|
||||
helpMessage: '单位:毫秒',
|
||||
bottomHelpMessage: '浏览器默认超时,浏览器可能需要更高的超时时间。',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
min: 0
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '以下为API方式(默认)的配置',
|
||||
component: 'Divider',
|
||||
component: 'Divider'
|
||||
},
|
||||
{
|
||||
field: 'apiKey',
|
||||
label: 'OpenAI API Key',
|
||||
bottomHelpMessage: 'OpenAI的ApiKey,用于访问OpenAI的API接口。',
|
||||
component: 'InputPassword',
|
||||
component: 'InputPassword'
|
||||
},
|
||||
{
|
||||
field: 'model',
|
||||
label: '模型',
|
||||
bottomHelpMessage: '模型名称,如无特殊需求保持默认即可,会使用chatgpt-api库提供的当前可用的最适合的默认值。保底可用的是 text-davinci-003。当发现新的可用的chatGPT模型会更新这里的值。',
|
||||
component: 'Input',
|
||||
component: 'Input'
|
||||
},
|
||||
{
|
||||
field: 'thinkingTips',
|
||||
label: '思考提示',
|
||||
bottomHelpMessage: '是否开启AI正在思考中的提示信息。',
|
||||
component: 'Switch',
|
||||
},
|
||||
{
|
||||
label: '以下为API2方式的配置',
|
||||
component: 'Divider',
|
||||
},
|
||||
{
|
||||
field: 'plus',
|
||||
label: 'ChatGPT Plus',
|
||||
bottomHelpMessage: 'ChatGPT Plus访问,如果购买了ChatGPT Plus请开启,响应更快。',
|
||||
component: 'Switch',
|
||||
},
|
||||
{
|
||||
field: 'reverseProxy',
|
||||
label: '第三方API接口',
|
||||
bottomHelpMessage: '使用第三方API。github开源的有几个,没特别要求保持默认就好。',
|
||||
component: 'Input',
|
||||
},
|
||||
{
|
||||
label: '以下为API3方式的配置。',
|
||||
component: 'Divider',
|
||||
},
|
||||
{
|
||||
field: 'api',
|
||||
label: 'ChatGPT API反代服务器地址',
|
||||
bottomHelpMessage: 'ChatGPT的API反代服务器,用于绕过Cloudflare访问ChatGPT API',
|
||||
component: 'Input',
|
||||
},
|
||||
{
|
||||
field: 'apiBaseUrl',
|
||||
label: 'apiBaseUrl地址',
|
||||
bottomHelpMessage: 'apiBaseUrl地址',
|
||||
component: 'Input',
|
||||
},
|
||||
{
|
||||
label: '以下为API/API2方式公用的配置',
|
||||
component: 'Divider',
|
||||
field: 'thinkingTips',
|
||||
label: '思考提示',
|
||||
bottomHelpMessage: '是否开启AI正在思考中的提示信息。',
|
||||
component: 'Switch'
|
||||
},
|
||||
{
|
||||
field: 'promptPrefixOverride',
|
||||
label: 'AI风格',
|
||||
bottomHelpMessage: '你可以在这里写入你希望AI回答的风格,比如希望优先回答中文,回答长一点等。',
|
||||
component: 'InputTextArea',
|
||||
component: 'InputTextArea'
|
||||
},
|
||||
{
|
||||
field: 'assistantLabel',
|
||||
label: 'AI名字',
|
||||
bottomHelpMessage: 'AI认为的自己的名字,当你问他你是谁是他会回答这里的名字。',
|
||||
component: 'Input',
|
||||
component: 'Input'
|
||||
},
|
||||
{
|
||||
field: 'temperature',
|
||||
label: 'temperature',
|
||||
bottomHelpMessage: 'temperature。',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
min: 0,
|
||||
max: 2
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '以下为API3方式的配置。',
|
||||
component: 'Divider'
|
||||
},
|
||||
{
|
||||
field: 'api',
|
||||
label: 'ChatGPT API反代服务器地址',
|
||||
bottomHelpMessage: 'ChatGPT的API反代服务器,用于绕过Cloudflare访问ChatGPT API',
|
||||
component: 'Input'
|
||||
},
|
||||
{
|
||||
field: 'apiBaseUrl',
|
||||
label: 'apiBaseUrl地址',
|
||||
bottomHelpMessage: 'apiBaseUrl地址',
|
||||
component: 'Input'
|
||||
},
|
||||
{
|
||||
label: '以下为浏览器方式的配置',
|
||||
component: 'Divider',
|
||||
component: 'Divider'
|
||||
},
|
||||
{
|
||||
field: 'username',
|
||||
label: '用户名',
|
||||
bottomHelpMessage: 'OpenAI用户名。',
|
||||
component: 'Input',
|
||||
component: 'Input'
|
||||
},
|
||||
{
|
||||
field: 'password',
|
||||
label: '密码',
|
||||
bottomHelpMessage: 'OpenAI密码。',
|
||||
component: 'InputPassword',
|
||||
component: 'InputPassword'
|
||||
},
|
||||
{
|
||||
field: 'UA',
|
||||
label: '浏览器UA',
|
||||
bottomHelpMessage: '模拟浏览器UA,无特殊需求保持默认即可。',
|
||||
component: 'InputTextArea',
|
||||
component: 'InputTextArea'
|
||||
},
|
||||
{
|
||||
field: 'headless',
|
||||
label: '无头模式',
|
||||
bottomHelpMessage: '无界面的服务器可以开启,但遇到验证码时可能无法使用。(实测很容易卡住,几乎不可用)。',
|
||||
component: 'Switch',
|
||||
field: 'headless',
|
||||
label: '无头模式',
|
||||
bottomHelpMessage: '无界面的服务器可以开启,但遇到验证码时可能无法使用。(实测很容易卡住,几乎不可用)。',
|
||||
component: 'Switch'
|
||||
},
|
||||
{
|
||||
field: 'chromePath',
|
||||
label: 'Chrome路径',
|
||||
bottomHelpMessage: '为空使用默认puppeteer的chromium,也可以传递自己本机安装的Chrome可执行文件地址,提高通过率。windows可以是‘C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe’,linux通过which查找路径。',
|
||||
component: 'Input',
|
||||
component: 'Input'
|
||||
},
|
||||
{
|
||||
field: '2captchaToken',
|
||||
label: '验证码平台Token',
|
||||
bottomHelpMessage: '可注册2captcha实现跳过验证码,收费服务但很便宜。否则可能会遇到验证码而卡住。',
|
||||
component: 'InputPassword',
|
||||
},
|
||||
component: 'InputPassword'
|
||||
}
|
||||
],
|
||||
// 获取配置数据方法(用于前端填充显示数据)
|
||||
getConfigData() {
|
||||
getConfigData () {
|
||||
return Config
|
||||
},
|
||||
// 设置配置的方法(前端点确定后调用的方法)
|
||||
setConfigData(data, {Result}) {
|
||||
setConfigData (data, { Result }) {
|
||||
for (let [keyPath, value] of Object.entries(data)) {
|
||||
// 处理黑名单
|
||||
if (keyPath === 'blockWords' || keyPath === 'promptBlockWords')
|
||||
value = value.toString().split(/[,,;;\|]/)
|
||||
if (Config[keyPath] != value)
|
||||
Config[keyPath] = value
|
||||
// 处理黑名单
|
||||
if (keyPath === 'blockWords' || keyPath === 'promptBlockWords') { value = value.toString().split(/[,,;;\|]/) }
|
||||
if (Config[keyPath] != value) { Config[keyPath] = value }
|
||||
}
|
||||
return Result.ok({}, '保存成功~')
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,11 +16,11 @@ const defaultConfig = {
|
|||
apiKey: '',
|
||||
drawCD: 30,
|
||||
model: '',
|
||||
temperature: 0.8,
|
||||
api: 'https://chatgpt.duti.tech/api/conversation',
|
||||
apiBaseUrl: 'https://chatgpt.duti.tech/api',
|
||||
plus: false,
|
||||
reverseProxy: 'https://chatgpt.pawan.krd/api/completions',
|
||||
promptPrefixOverride: 'Your answer shouldn\'t be too verbose. If you are generating a list, do not have too many items. Keep the number of items short. Prefer to answer in Chinese.',
|
||||
promptPrefixOverride: 'Your answer shouldn\'t be too verbose. Prefer to answer in Chinese.',
|
||||
assistantLabel: 'ChatGPT',
|
||||
thinkingTips: true,
|
||||
username: '',
|
||||
|
|
@ -33,7 +33,7 @@ const defaultConfig = {
|
|||
debug: true,
|
||||
defaultTimeoutMs: 120000,
|
||||
chromeTimeoutMS: 120000,
|
||||
version: '2.0.5'
|
||||
version: '2.0.6'
|
||||
}
|
||||
const _path = process.cwd()
|
||||
let config = {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue