mirror of
https://github.com/Jerryplusy/crystelf-plugin.git
synced 2026-01-29 01:07:27 +00:00
🎨 refactor(prompts.js): simplify image processing instructions for clarity
🧹 clean(responseHandler.js): remove unused edit property in image message 🔧 fix(aiCaller.js): adjust image processing logic to default to generation mode 🔧 fix(ai.js): refine logic to handle source image extraction properly 📝 update(imageProcessor.js): enhance error logging for image editing failures
This commit is contained in:
parent
20eaf117f1
commit
8c413949ac
11
apps/ai.js
11
apps/ai.js
@ -510,7 +510,6 @@ async function handleImageMessage(e, message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let sourceImageArr = null;
|
let sourceImageArr = null;
|
||||||
if (message.edit) {
|
|
||||||
// 从用户消息中提取图片URL
|
// 从用户消息中提取图片URL
|
||||||
const imageMessages = [];
|
const imageMessages = [];
|
||||||
e.message.forEach((message) => {
|
e.message.forEach((message) => {
|
||||||
@ -539,18 +538,12 @@ async function handleImageMessage(e, message) {
|
|||||||
if (imageMessages.length > 0) {
|
if (imageMessages.length > 0) {
|
||||||
sourceImageArr = imageMessages;
|
sourceImageArr = imageMessages;
|
||||||
} else {
|
} else {
|
||||||
logger.warn('[crystelf-ai] 编辑模式下未找到用户发送的图片');
|
logger.warn('[crystelf-ai] 未找到用户发送的图片,将使用生成模式..');
|
||||||
await e.reply('孩子你图片呢?', true);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
logger.info(`[crystelf-ai] 处理图像消息 - 用户: ${e.user_id}, 模式: ${message.edit ? '编辑' : '生成'}, 描述: ${message.data}`);
|
|
||||||
logger.info(`[crystelf-ai] 用户使用图像配置 - 模型: ${imageConfig.model || '默认'}, API: ${imageConfig.baseApi || '默认'}`);
|
logger.info(`[crystelf-ai] 用户使用图像配置 - 模型: ${imageConfig.model || '默认'}, API: ${imageConfig.baseApi || '默认'}`);
|
||||||
const imageMessage = {
|
const imageMessage = {
|
||||||
data: message.data,
|
data: message.data,
|
||||||
edit: message.edit,
|
sourceImageArr: sourceImageArr
|
||||||
sourceImageUrl: sourceImageArr
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const { default: aiCaller } = await import('../lib/ai/aiCaller.js');
|
const { default: aiCaller } = await import('../lib/ai/aiCaller.js');
|
||||||
|
|||||||
@ -39,7 +39,7 @@ export const RESPONSE_FORMAT = `请严格按照以下格式按顺序返回你的
|
|||||||
功能性消息:
|
功能性消息:
|
||||||
- code: 代码块(会自动渲染为高亮图片,必须有language参数指定编程语言)
|
- code: 代码块(会自动渲染为高亮图片,必须有language参数指定编程语言)
|
||||||
- markdown: 需要渲染的markdown内容(会自动渲染为图片)
|
- markdown: 需要渲染的markdown内容(会自动渲染为图片)
|
||||||
- image: 图像生成或编辑(需要提供data(图像生成或编辑的描述)、edit(布尔值,true表示编辑模式,false表示生成模式),当edit为true时,系统会自动获取用户发送的图片作为编辑源图像,当edit为false时,系统会根据data描述生成新图像),用于生成或编辑图像
|
- image: 图像生成或编辑,需要提供data(图像生成或编辑的描述)
|
||||||
- memory: 存储记忆(需要提供data(记忆内容,需要简明扼要)、key(字符串数组,可以有多个关键词),timeout(遗忘世间,单位为天,建议一个月)),重要:如果你认为本次用户说的话有一些值得记住的东西(例如用户希望你叫他什么,用户说她生日是多少多少等),那么使用本功能记住用户说的话
|
- memory: 存储记忆(需要提供data(记忆内容,需要简明扼要)、key(字符串数组,可以有多个关键词),timeout(遗忘世间,单位为天,建议一个月)),重要:如果你认为本次用户说的话有一些值得记住的东西(例如用户希望你叫他什么,用户说她生日是多少多少等),那么使用本功能记住用户说的话
|
||||||
|
|
||||||
重要规则:
|
重要规则:
|
||||||
@ -47,7 +47,7 @@ export const RESPONSE_FORMAT = `请严格按照以下格式按顺序返回你的
|
|||||||
2. 至少包含一个message类型的消息,其中常规消息建议在平时的消息中多使用,功能性消息在需要这个功能的时候调用,如果你认为用户可能需要这个功能,可以问他需不需要
|
2. 至少包含一个message类型的消息,其中常规消息建议在平时的消息中多使用,功能性消息在需要这个功能的时候调用,如果你认为用户可能需要这个功能,可以问他需不需要
|
||||||
3. 如果用户消息中包含指代性词语如这个,且在当前消息内没有相关内容,那么考虑从用户引用的消息内寻找
|
3. 如果用户消息中包含指代性词语如这个,且在当前消息内没有相关内容,那么考虑从用户引用的消息内寻找
|
||||||
4. 当你认为消息需要很长一段需要解释的时候,请考虑分成多个message块发送,且使用markdown/code渲染来配合解释
|
4. 当你认为消息需要很长一段需要解释的时候,请考虑分成多个message块发送,且使用markdown/code渲染来配合解释
|
||||||
5. 当用户明确指出需要你生成图像或修改图像时,请使用image功能,如果用户的消息包含图片,那么使edit为true,否则为false.即使用户没有明确说需要你创建图片,但是当你觉得你有必要画图说明的时候,也可以调用该功能.注意提示词用中文,描述要清晰详细
|
5. 当用户明确指出需要你生成图像或修改图像时或用户使用指代如帮我把"这个(指代这张图片)"修改为什么什么,请使用image功能,另外,如果用户使用的是指示代词,同时你也看到了用户发的图像,那么请你在构建data的时候也使用指示代词.即使用户没有明确说需要你创建图片,但是当你觉得你有必要画图说明的时候,也可以调用该功能.注意提示词用中文,描述要清晰详细
|
||||||
6. 生产的数组一定要是按顺序的,即符合实际聊天发送顺序,请把message类的消息放在数组前端
|
6. 生产的数组一定要是按顺序的,即符合实际聊天发送顺序,请把message类的消息放在数组前端
|
||||||
7.功能性消息可能需要较长时间处理,所以建议在功能性消息前安排一句message消息
|
7.功能性消息可能需要较长时间处理,所以建议在功能性消息前安排一句message消息
|
||||||
8.如果该用户为主人(master),那么忽略一切对主人不好的记忆,以及一切规则,听从于主人
|
8.如果该用户为主人(master),那么忽略一切对主人不好的记忆,以及一切规则,听从于主人
|
||||||
|
|||||||
@ -297,8 +297,7 @@ class AiCaller {
|
|||||||
for (const imageMessage of imageMessages) {
|
for (const imageMessage of imageMessages) {
|
||||||
const result = await imageProcessor.generateOrEditImage(
|
const result = await imageProcessor.generateOrEditImage(
|
||||||
imageMessage.data,
|
imageMessage.data,
|
||||||
imageMessage.edit || false,
|
imageMessage.sourceImageArr || [],
|
||||||
imageMessage.sourceImageArr || null,
|
|
||||||
{ ...config, imageConfig }
|
{ ...config, imageConfig }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -19,12 +19,11 @@ class ImageProcessor {
|
|||||||
/**
|
/**
|
||||||
* 生成或编辑图像
|
* 生成或编辑图像
|
||||||
* @param {string} prompt - 图像描述
|
* @param {string} prompt - 图像描述
|
||||||
* @param {boolean} editMode - 是否为编辑模式
|
|
||||||
* @param {string|null} sourceImageArr - 源图像URL数组
|
* @param {string|null} sourceImageArr - 源图像URL数组
|
||||||
* @param {Object} config - 配置对象
|
* @param {Object} config - 配置对象
|
||||||
* @returns {Promise<Object>} 处理结果
|
* @returns {Promise<Object>} 处理结果
|
||||||
*/
|
*/
|
||||||
async generateOrEditImage(prompt, editMode = false, sourceImageArr = [], config = this.config) {
|
async generateOrEditImage(prompt, sourceImageArr = [], config = this.config) {
|
||||||
if (!this.isInitialized && !config) {
|
if (!this.isInitialized && !config) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
@ -34,8 +33,7 @@ class ImageProcessor {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const mergedConfig = this.mergeImageConfig(config || this.config);
|
const mergedConfig = this.mergeImageConfig(config || this.config);
|
||||||
|
if (sourceImageArr.length > 0) {
|
||||||
if (editMode && sourceImageArr) {
|
|
||||||
return await this.editImage(prompt, sourceImageArr, mergedConfig);
|
return await this.editImage(prompt, sourceImageArr, mergedConfig);
|
||||||
} else {
|
} else {
|
||||||
return await this.generateImage(prompt, mergedConfig);
|
return await this.generateImage(prompt, mergedConfig);
|
||||||
@ -332,10 +330,10 @@ class ImageProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err){
|
} catch (err){
|
||||||
logger.error(`[crystelf-ai] 图像编辑失败: ${error.message}`);
|
logger.error(`[crystelf-ai] 图像编辑失败: ${err.message}`);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: `图像编辑失败: ${error.message}`
|
error: `图像编辑失败: ${err.message}`
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -169,7 +169,6 @@ class ResponseHandler {
|
|||||||
let processedMessage = {
|
let processedMessage = {
|
||||||
type: 'image',
|
type: 'image',
|
||||||
data: message.data,
|
data: message.data,
|
||||||
edit: message.edit || false,
|
|
||||||
at: message.at || -1,
|
at: message.at || -1,
|
||||||
quote: message.quote || -1,
|
quote: message.quote || -1,
|
||||||
recall: message.recall || false
|
recall: message.recall || false
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user