mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 13:57:10 +00:00
feat: 主动聊天功能
This commit is contained in:
parent
5cbd2cad15
commit
7a320bc772
4 changed files with 114 additions and 2 deletions
|
|
@ -45,7 +45,8 @@ const defaultConfig = {
|
|||
noiseScale: 0.6,
|
||||
noiseScaleW: 0.668,
|
||||
lengthScale: 1.2,
|
||||
version: 'v2.0.18'
|
||||
initiativeChatGroups: [],
|
||||
version: 'v2.0.19'
|
||||
}
|
||||
const _path = process.cwd()
|
||||
let config = {}
|
||||
|
|
|
|||
37
utils/randomMessage.js
Normal file
37
utils/randomMessage.js
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import { Config } from './config.js'
|
||||
import { ChatGPTAPI } from 'chatgpt'
|
||||
import { getMessageById, upsertMessage } from './common.js'
|
||||
import fetch from 'node-fetch'
|
||||
let proxy
|
||||
if (Config.proxy) {
|
||||
try {
|
||||
proxy = (await import('https-proxy-agent')).default
|
||||
} catch (e) {
|
||||
console.warn('未安装https-proxy-agent,请在插件目录下执行pnpm add https-proxy-agent')
|
||||
}
|
||||
}
|
||||
const newFetch = (url, options = {}) => {
|
||||
const defaultOptions = Config.proxy
|
||||
? {
|
||||
agent: proxy(Config.proxy)
|
||||
}
|
||||
: {}
|
||||
|
||||
const mergedOptions = {
|
||||
...defaultOptions,
|
||||
...options
|
||||
}
|
||||
|
||||
return fetch(url, mergedOptions)
|
||||
}
|
||||
const question = '写一段话让大家来找我聊天。类似于“有人找我聊天吗?"这种风格,轻松随意一点控制在20个字以内'
|
||||
|
||||
export async function generateHello () {
|
||||
let api = new ChatGPTAPI({
|
||||
apiBaseUrl: Config.openAiBaseUrl,
|
||||
apiKey: Config.apiKey,
|
||||
fetch: newFetch
|
||||
})
|
||||
const res = await api.sendMessage(question)
|
||||
return res.text
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue