mirror of
https://github.com/Jerryplusy/crystelf-plugin.git
synced 2025-12-05 15:41:56 +00:00
Compare commits
4 Commits
fa0f3ceb4e
...
d72db21461
| Author | SHA1 | Date | |
|---|---|---|---|
| d72db21461 | |||
| bef44e65c9 | |||
| 414fe08f45 | |||
| 6c726f242f |
10
apps/ai.js
10
apps/ai.js
@ -89,10 +89,10 @@ async function index(e) {
|
||||
return;
|
||||
}
|
||||
if (e.user_id === e.bot.uin) {
|
||||
return;
|
||||
return e.reply(segment.image(await Meme.getMeme(aiConfig.character, 'default')));
|
||||
}
|
||||
const userMessage = await extractUserMessage(e.msg, nickname, e);
|
||||
if (!userMessage) {
|
||||
if (!userMessage || userMessage.length === 0) {
|
||||
return;
|
||||
}
|
||||
const adapter = await YunzaiUtils.getAdapter(e);
|
||||
@ -130,6 +130,9 @@ async function extractUserMessage(msg, nickname, e) {
|
||||
returnMessage += `[${e.sender?.nickname},id:${e.user_id}]说:${message}\n`;
|
||||
});
|
||||
}
|
||||
if(at.length === 1 && at[0] === e.bot.uin){
|
||||
return [];
|
||||
}
|
||||
if (at.length > 0) {
|
||||
at.forEach((at) => {
|
||||
if (at === e.bot.uin) {
|
||||
@ -146,7 +149,7 @@ async function extractUserMessage(msg, nickname, e) {
|
||||
return returnMessage;
|
||||
}
|
||||
logger.warn('[crystelf-ai] 字符串匹配失败,使用空字符串操作');
|
||||
return '';
|
||||
return [''];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -272,6 +275,7 @@ async function callAiForResponse(userMessage, e, aiConfig) {
|
||||
const aiResult = await AiCaller.callAi(userMessage, chatHistory, memories, e);
|
||||
if (!aiResult.success) {
|
||||
logger.error(`[crystelf-ai] AI调用失败: ${aiResult.error}`);
|
||||
SessionManager.deactivateSession(e.group_id, e.user_id);
|
||||
return [
|
||||
{
|
||||
type: 'meme',
|
||||
|
||||
@ -33,7 +33,7 @@ export const RESPONSE_FORMAT = `请严格按照以下格式按顺序返回你的
|
||||
|
||||
支持的消息类型(type):
|
||||
常规消息:
|
||||
- message(必须,其他均为可选): 普通文本消息,请将长句子分成多个message块返回(如果有多句话),data:回复内容,at:是否在发送本条消息的时候提醒用户,一般只在需要让用户注意的时候为true,quote:是否引用用户的问题,一般只需要在回答用户问题或第一条回复或需要用到用户问题的时候为true
|
||||
- message(必须,其他均为可选): 普通文本消息,请将长句子分成多个message块返回(如果有多句话),data:回复内容,at:是否在发送本条消息的时候提醒用户,一般只在需要让用户注意的时候为true(另外,不要在message里面加@qq号),quote:是否引用用户的问题,一般只需要在回答用户问题或第一条回复或需要用到用户问题的时候为true
|
||||
- at: @某人(需要提供id,被at人qq号(number)),一般用于提醒用户,不常用
|
||||
- meme: 表情包(data值为情绪名称:angry、bye、confused、default、good、goodmorning、goodnight、happy、sad、shy、sorry、surprise),请根据聊天语境灵活选择需不需要表情包,如果感觉语境尴尬或需要表情包,那么发送一个default值的表情包,其他情绪的表情包按照当前你的情绪按需选择,注意:并不是每个聊天都需要有表情包,并且一次聊天最多回复一个表情包
|
||||
- poke: 戳一戳某人(需要提供id,被戳人qq号(number)),一般用户与用户互动,当想逗用户的时候可以使用
|
||||
|
||||
@ -2,6 +2,7 @@ import ConfigControl from '../config/configControl.js';
|
||||
import OpenaiChat from '../../modules/openai/openaiChat.js';
|
||||
import OllamaChat from '../../modules/ollama/ollamaChat.js';
|
||||
import { getSystemPrompt, getStreamSystemPrompt } from '../../constants/ai/prompts.js';
|
||||
import SessionManager from "./sessionManager.js";
|
||||
|
||||
//ai调用器
|
||||
class AiCaller {
|
||||
@ -77,6 +78,7 @@ class AiCaller {
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(`[crystelf-ai] 调用失败: ${error.message}`);
|
||||
SessionManager.deactivateSession(e.group_id, e.user_id);
|
||||
return {
|
||||
success: false,
|
||||
error: error.message,
|
||||
@ -176,7 +178,6 @@ class AiCaller {
|
||||
`[你的信息]`,
|
||||
`- 你的昵称:${botInfo.name}`,
|
||||
`- 你的qq号:${botInfo.id}`,
|
||||
`- 目前北京时间: ${new Date()}```,
|
||||
`[跟你对话的用户的信息]`,
|
||||
`- 他的名字:${userInfo.name}`,
|
||||
`- 他的qq号(id):${userInfo.id}`,
|
||||
@ -188,7 +189,7 @@ class AiCaller {
|
||||
].join('\n');
|
||||
return `${contextIntro}${basePrompt}`;
|
||||
} catch (error) {
|
||||
logger.error(`[crystelf-ai] 生成系统提示词失败: ${error.message}`);
|
||||
logger.error(`[crystelf-ai] 生成系统提示词失败: ${error}`);
|
||||
return await getSystemPrompt();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user