mirror of
https://github.com/Jerryplusy/crystelf-plugin.git
synced 2025-12-05 15:41:56 +00:00
✨ feat(ai): add max message length configuration and truncate long messages in chat history display
This commit is contained in:
parent
5c97c9cdf7
commit
bd6ad16445
@ -111,10 +111,17 @@ async function extractUserMessage(msg, nickname, e) {
|
||||
if (e.message && msg && msg.trim()!=='' && msg !== '\n') {
|
||||
let text = [];
|
||||
let at = [];
|
||||
const aiConfig = await ConfigControl.get('ai');
|
||||
const maxMessageLength = aiConfig?.maxMessageLength || 100;
|
||||
e.message.forEach((message) => {
|
||||
logger.info(message);
|
||||
if (message.type === 'text' && message.text !== '' && message.text !== '\n'){
|
||||
text.push(message.text);
|
||||
let displayText = msg.text;
|
||||
if (msg.text && msg.text.length > maxMessageLength) {
|
||||
const omittedChars = msg.text.length - maxMessageLength;
|
||||
displayText = msg.text.substring(0, maxMessageLength) + `...(省略${omittedChars}字)`;
|
||||
}
|
||||
text.push(displayText);
|
||||
} else if (message.type === 'at') {
|
||||
at.push(message.qq);
|
||||
}
|
||||
|
||||
@ -20,6 +20,8 @@
|
||||
"maxSessions": 10,
|
||||
"?chatHistory": "聊天上下文最大长度",
|
||||
"chatHistory": 10,
|
||||
"?maxMessageLength": "最大消息长度",
|
||||
"maxMessageLength": 100,
|
||||
"?getChatHistoryLength": "获取到的聊天上下文长度",
|
||||
"getChatHistoryLength":20,
|
||||
"?keywordCache": "是否缓存关键词到本地",
|
||||
|
||||
@ -164,13 +164,20 @@ class AiCaller {
|
||||
|
||||
const historyLen = await ConfigControl.get('ai').getChatHistoryLength || 10;
|
||||
const groupChatHistory = await e.group.getChatHistory(e.message_id, historyLen);
|
||||
const aiConfig = await ConfigControl.get('ai');
|
||||
const maxMessageLength = aiConfig?.maxMessageLength || 100;
|
||||
if(groupChatHistory && groupChatHistory.length > 0 ){
|
||||
contextIntro += '[群聊聊天记录(从旧到新)]\n'
|
||||
for (const message of groupChatHistory) {
|
||||
const msgArr = message.message;
|
||||
for (const msg of msgArr) {
|
||||
if(msg.type==='text'){
|
||||
contextIntro += `[${message.sender.user_id == e.bot.uin ? '你' : message.sender?.nickname},id:${message.sender?.user_id},seq:${message.message_id}]之前说过:${msg.text}\n`
|
||||
let displayText = msg.text;
|
||||
if (msg.text && msg.text.length > maxMessageLength) {
|
||||
const omittedChars = msg.text.length - maxMessageLength;
|
||||
displayText = msg.text.substring(0, maxMessageLength) + `...(省略${omittedChars}字)`;
|
||||
}
|
||||
contextIntro += `[${message.sender.user_id == e.bot.uin ? '你' : message.sender?.nickname},id:${message.sender?.user_id},seq:${message.message_id}]之前说过:${displayText}\n`
|
||||
}
|
||||
if(msg.type === 'at'){
|
||||
if(msg.qq == e.bot.uin){
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user