fix: 上下文、文件、ocr等进一步适配shamrock

This commit is contained in:
ikechan8370 2023-12-10 23:08:10 +08:00
parent 46328a9716
commit 247f3e15d0
4 changed files with 70 additions and 33 deletions

View file

@ -797,7 +797,7 @@ export class chatgpt extends plugin {
* #chatgpt
*/
async chatgpt (e) {
let msg = Version.isTrss ? e.msg : e.raw_message
let msg = (Version.isTrss || e.adapter === 'shamrock') ? e.msg : e.raw_message
let prompt
if (this.toggleMode === 'at') {
if (!msg || e.msg?.startsWith('#')) {
@ -1669,7 +1669,11 @@ export class chatgpt extends plugin {
let toSummaryFileContent
try {
if (e.source) {
let msgs = e.isGroup ? await e.group.getChatHistory(e.source.seq, 1) : await e.friend.getChatHistory(e.source.time, 1)
let seq = e.isGroup ? e.source.seq : e.source.time
if (e.adapter === 'shamrock') {
seq = e.source.message_id
}
let msgs = e.isGroup ? await e.group.getChatHistory(seq, 1) : await e.friend.getChatHistory(seq, 1)
let sourceMsg = msgs[0]
let fileMsgElem = sourceMsg.message.find(msg => msg.type === 'file')
if (fileMsgElem) {
@ -2127,6 +2131,7 @@ export class chatgpt extends plugin {
}
}
default: {
// openai api
let completionParams = {}
if (Config.model) {
completionParams.model = Config.model
@ -2317,27 +2322,7 @@ export class chatgpt extends plugin {
}
}
}
let img = []
if (e.source) {
// 优先从回复找图
let reply
if (e.isGroup) {
reply = (await e.group.getChatHistory(e.source.seq, 1)).pop()?.message
} else {
reply = (await e.friend.getChatHistory(e.source.time, 1)).pop()?.message
}
if (reply) {
for (let val of reply) {
if (val.type === 'image') {
console.log(val)
img.push(val.url)
}
}
}
}
if (e.img) {
img.push(...e.img)
}
let img = await getImg(e)
if (img.length > 0 && Config.extraUrl) {
tools.push(new ImageCaptionTool())
tools.push(new ProcessPictureTool())