mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 21:37:11 +00:00
Merge branch 'v2' of github.com:ikechan8370/chatgpt-plugin into v2
This commit is contained in:
commit
2ca27dae8d
8 changed files with 168 additions and 32 deletions
|
|
@ -81,7 +81,7 @@ export default class SydneyAIClient {
|
|||
'x-ms-useragent': 'azsdk-js-api-client-factory/1.0.0-beta.1 core-rest-pipeline/1.10.3 OS/macOS',
|
||||
// cookie: this.opts.cookies || `_U=${this.opts.userToken}`,
|
||||
Referer: 'https://edgeservices.bing.com/edgesvc/chat?udsframed=1&form=SHORUN&clientscopes=chat,noheader,channelstable,',
|
||||
'Referrer-Policy': 'origin-when-cross-origin',
|
||||
'Referrer-Policy': 'origin-when-cross-origin'
|
||||
// Workaround for request being blocked due to geolocation
|
||||
// 'x-forwarded-for': '1.1.1.1'
|
||||
}
|
||||
|
|
@ -94,9 +94,11 @@ export default class SydneyAIClient {
|
|||
} else {
|
||||
fetchOptions.headers.cookie = this.opts.cookies
|
||||
}
|
||||
let proTag = await redis.get('CHATGPT:COPILOT_PRO_TAG:' + this.opts.userToken)
|
||||
// let hash = md5(this.opts.cookies || this.opts.userToken)
|
||||
let hash = crypto.createHash('md5').update(this.opts.cookies || this.opts.userToken).digest('hex')
|
||||
let proTag = await redis.get('CHATGPT:COPILOT_PRO_TAG:' + hash)
|
||||
if (!proTag) {
|
||||
let indexContentRes = await fetch('https://www.bing.com', {
|
||||
let indexContentRes = await fetch('https://www.bing.com/chat', {
|
||||
headers: {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0',
|
||||
Cookie: `_U=${this.opts.userToken}`
|
||||
|
|
@ -108,7 +110,7 @@ export default class SydneyAIClient {
|
|||
} else {
|
||||
proTag = 'false'
|
||||
}
|
||||
await redis.set('CHATGPT:COPILOT_PRO_TAG:' + this.opts.userToken, proTag, { EX: 7200 })
|
||||
await redis.set('CHATGPT:COPILOT_PRO_TAG:' + hash, proTag, { EX: 7200 })
|
||||
}
|
||||
if (proTag === 'true') {
|
||||
logger.info('当前账户为copilot pro用户')
|
||||
|
|
@ -338,6 +340,21 @@ export default class SydneyAIClient {
|
|||
if (!text) {
|
||||
previousMessages = pm
|
||||
} else {
|
||||
let example = []
|
||||
for (let i = 1; i < 4; i++) {
|
||||
if (Config[`chatExampleUser${i}`]) {
|
||||
example.push(...[
|
||||
{
|
||||
text: Config[`chatExampleUser${i}`],
|
||||
author: 'user'
|
||||
},
|
||||
{
|
||||
text: Config[`chatExampleBot${i}`],
|
||||
author: 'bot'
|
||||
}
|
||||
])
|
||||
}
|
||||
}
|
||||
previousMessages = [
|
||||
{
|
||||
text,
|
||||
|
|
@ -347,6 +364,7 @@ export default class SydneyAIClient {
|
|||
text: '好的。',
|
||||
author: 'bot'
|
||||
},
|
||||
...example,
|
||||
...pm
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,12 @@ const defaultConfig = {
|
|||
sydneyGPTs: 'Copilot',
|
||||
sydneyImageRecognition: false,
|
||||
sydneyMoodTip: 'Your response should be divided into two parts, namely, the text and your mood. The mood available to you can only include: blandness, happy, shy, frustrated, disgusted, and frightened.All content should be replied in this format {"text": "", "mood": ""}.All content except mood should be placed in text, It is important to ensure that the content you reply to can be parsed by json.',
|
||||
chatExampleUser1: '',
|
||||
chatExampleUser2: '',
|
||||
chatExampleUser3: '',
|
||||
chatExampleBot1: '',
|
||||
chatExampleBot2: '',
|
||||
chatExampleBot3: '',
|
||||
enableSuggestedResponses: false,
|
||||
sydneyEnableSearch: false,
|
||||
api: defaultChatGPTAPI,
|
||||
|
|
@ -66,13 +72,8 @@ const defaultConfig = {
|
|||
xhRetReplace: '',
|
||||
promptPrefixOverride: 'Your answer shouldn\'t be too verbose. Prefer to answer in Chinese.',
|
||||
assistantLabel: 'ChatGPT',
|
||||
// thinkingTips: true,
|
||||
username: '',
|
||||
password: '',
|
||||
UA: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36',
|
||||
headless: false,
|
||||
chromePath: '',
|
||||
'2captchaToken': '',
|
||||
proxy: '',
|
||||
debug: true,
|
||||
defaultTimeoutMs: 120000,
|
||||
|
|
|
|||
|
|
@ -11,9 +11,19 @@ export function readPrompts () {
|
|||
txtFiles.forEach(txtFile => {
|
||||
let name = _.trimEnd(txtFile, '.txt')
|
||||
const content = fs.readFileSync(`${_path}/plugins/chatgpt-plugin/prompts/${txtFile}`, 'utf8')
|
||||
let example = []
|
||||
try {
|
||||
if (fs.existsSync(`${_path}/plugins/chatgpt-plugin/prompts/${name}_example.json`)) {
|
||||
example = fs.readFileSync(`${_path}/plugins/chatgpt-plugin/prompts/${name}_example.json`, 'utf8')
|
||||
example = JSON.parse(example)
|
||||
}
|
||||
} catch (err) {
|
||||
logger.debug(err)
|
||||
}
|
||||
prompts.push({
|
||||
name,
|
||||
content
|
||||
content,
|
||||
example
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
@ -34,11 +44,15 @@ export function getPromptByName (name) {
|
|||
}
|
||||
}
|
||||
|
||||
export function saveOnePrompt (name, content) {
|
||||
export function saveOnePrompt (name, content, examples) {
|
||||
const _path = process.cwd()
|
||||
mkdirs(`${_path}/plugins/chatgpt-plugin/prompts`)
|
||||
let filePath = `${_path}/plugins/chatgpt-plugin/prompts/${name}.txt`
|
||||
fs.writeFileSync(filePath, content)
|
||||
if (examples) {
|
||||
let examplePath = `${_path}/plugins/chatgpt-plugin/prompts/${name}_example.json`
|
||||
fs.writeFileSync(examplePath, JSON.stringify(examples))
|
||||
}
|
||||
}
|
||||
|
||||
export function deleteOnePrompt (name) {
|
||||
|
|
@ -46,4 +60,8 @@ export function deleteOnePrompt (name) {
|
|||
mkdirs(`${_path}/plugins/chatgpt-plugin/prompts`)
|
||||
let filePath = `${_path}/plugins/chatgpt-plugin/prompts/${name}.txt`
|
||||
fs.unlinkSync(filePath)
|
||||
try {
|
||||
let examplePath = `${_path}/plugins/chatgpt-plugin/prompts/${name}_example.json`
|
||||
fs.unlinkSync(examplePath)
|
||||
} catch (err) {}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue