update 添加保存
This commit is contained in:
93
prompts/test/generate-perfect.ts
Normal file
93
prompts/test/generate-perfect.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import { Kevisual } from "@kevisual/ai";
|
||||
import { useConfig } from '@kevisual/use-config'
|
||||
import path from "node:path";
|
||||
import fs from "node:fs";
|
||||
import { createStorage } from "unstorage";
|
||||
import { Prompt } from "../src/index.ts";
|
||||
import fsDriver from "unstorage/drivers/fs";
|
||||
|
||||
const promptPath = path.join(process.cwd(), "./docs/prompts-01.json");
|
||||
|
||||
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
|
||||
const storage = createStorage({
|
||||
driver: fsDriver({ base: 'storage' }),
|
||||
});
|
||||
const config = useConfig();
|
||||
const kevisual = new Kevisual({
|
||||
token: config.KEVISUAL_NEW_API_KEY || "",
|
||||
model: "qwen-turbo"
|
||||
});
|
||||
|
||||
if (!fs.existsSync(promptPath)) {
|
||||
console.error("Prompt file not found:", promptPath);
|
||||
process.exit(1);
|
||||
}
|
||||
const prompts = JSON.parse(fs.readFileSync(promptPath, "utf-8")) as { key: string, value: string, id: string }[];
|
||||
|
||||
const currentUsage = (await storage.getItem("usage.json") as any) || { prompt_tokens: 0, total_tokens: 0, completion_tokens: 0 };
|
||||
|
||||
console.log("Current usage:", currentUsage);
|
||||
async function generatePerfectPrompts() {
|
||||
for (const promptData of prompts) {
|
||||
const id = promptData.id + '.json';
|
||||
const has = await storage.get(id);
|
||||
if (has) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
const perfectPrompt = `请你将以下提示词进行完善,使其更加详细和具体,适合用于生成高质量的像素艺术图像。要求如下:
|
||||
1. 只返回完善后的提示词,不要包含任何多余的内容或解释。
|
||||
2. 确保提示词专注于像素艺术风格,包括但不限于像素化角色、场景和物体的描述。
|
||||
3. 使用具体的细节来增强提示词的表现力,例如颜色、构图、光影效果等。
|
||||
4. 避免使用与像素艺术无关的术语或描述。
|
||||
5. 保持提示词的简洁性,避免过于冗长,但要确保信息量充足。
|
||||
6. 如果需要颜色,需要整个图像的颜色更少的描述,而不是复杂的颜色细节, 背景默认纯蓝色。
|
||||
7. 使用中文进行描述。
|
||||
`;
|
||||
const prompt = new Prompt({ perfectPrompt });
|
||||
const result = await kevisual.chat([
|
||||
{
|
||||
role: "user",
|
||||
content: prompt.perfect(promptData.value),
|
||||
}
|
||||
])
|
||||
const text = prompt.clearPerfectTags(kevisual.responseText);
|
||||
await storage.setItem(id, {
|
||||
value: promptData.value,
|
||||
id: promptData.id,
|
||||
perfect: text,
|
||||
});
|
||||
|
||||
await sleep(2000); // Avoid rate limits
|
||||
const _usage = kevisual.getChatUsage()
|
||||
console.log("Generated perfect prompt for:", promptData.id, _usage?.total_tokens);
|
||||
currentUsage.total_tokens += _usage?.total_tokens || 0;
|
||||
currentUsage.prompt_tokens += _usage?.prompt_tokens || 0;
|
||||
currentUsage.completion_tokens += _usage?.completion_tokens || 0;
|
||||
// Update usage
|
||||
await storage.setItem("usage.json", {
|
||||
prompt_tokens: currentUsage.prompt_tokens,
|
||||
total_tokens: currentUsage.total_tokens,
|
||||
completion_tokens: currentUsage.completion_tokens,
|
||||
});
|
||||
console.log('优化的提示词', text);
|
||||
} catch (error) {
|
||||
console.error("Error generating perfect prompt for:", promptData, error);
|
||||
// 如果是超时错误,等待一段时间后继续
|
||||
if ((error as any)?.message?.includes("timeout")) {
|
||||
console.log("Timeout occurred, waiting for 30 seconds before retrying...");
|
||||
await sleep(10000);
|
||||
continue;
|
||||
} else {
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
generatePerfectPrompts();
|
||||
|
||||
// bun test/generate-perfect.ts
|
||||
// pm2 start --name "generate-perfect" --interpreter=bun -- test/generate-perfect.ts
|
||||
28
prompts/test/random-pony.ts
Normal file
28
prompts/test/random-pony.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { PromptGenerator, saveToFile } from "../src/index.ts";
|
||||
import { source } from "./source.ts";
|
||||
import path from 'node:path';
|
||||
|
||||
const coreValue = [
|
||||
"像素艺术",
|
||||
"矢量插画",
|
||||
"线条艺术",
|
||||
"可爱",
|
||||
"日式可爱",
|
||||
"Q版",
|
||||
"萌",
|
||||
"简约",
|
||||
"极简主义",
|
||||
"干净线条",
|
||||
"扁平色彩",
|
||||
]
|
||||
const promptGenerator = new PromptGenerator({
|
||||
count: 1000,
|
||||
source: source,
|
||||
additionalValues: coreValue,
|
||||
endString: '纯色背景'
|
||||
});
|
||||
|
||||
const promptMap = promptGenerator.generateMap();
|
||||
|
||||
const outputPath = path.join(process.cwd(), "./docs/prompts.json");
|
||||
await saveToFile(promptMap, outputPath);
|
||||
155
prompts/test/source.ts
Normal file
155
prompts/test/source.ts
Normal file
@@ -0,0 +1,155 @@
|
||||
export const source = {
|
||||
"subject": [
|
||||
"圆滚滚的马",
|
||||
"穿衣服的马",
|
||||
"胖乎乎的小马",
|
||||
"戴帽子的马",
|
||||
"毛茸茸的斑马",
|
||||
"拿气球的独角兽",
|
||||
"瘦长的马",
|
||||
"Q版马",
|
||||
"戴墨镜的马",
|
||||
"拿着星星的马",
|
||||
"古代战马披铠甲",
|
||||
"水墨风格的骏马",
|
||||
"发光的梦幻马",
|
||||
"机械赛博格马",
|
||||
"戴着皇冠的皇家马",
|
||||
"背着书包上学的小马",
|
||||
"会魔法的飞马",
|
||||
"穿着宇航服的太空马",
|
||||
"抱着吉他的摇滚马",
|
||||
"正在画画的艺术家马",
|
||||
"穿唐装的新年马",
|
||||
"骑着扫帚的巫师马",
|
||||
"戴着围巾的冬日小马",
|
||||
"撑伞的雨中马",
|
||||
"戴着耳机听音乐的潮马",
|
||||
"背着礼物袋的圣诞马",
|
||||
"在镜子前自拍的爱美马",
|
||||
"变成龙形的神驹",
|
||||
"半植物半马的自然精灵",
|
||||
"透明水晶质感的玻璃马",
|
||||
"由星尘组成的宇宙马",
|
||||
"纸艺折纸风格小马",
|
||||
"黏土手办风格马",
|
||||
"影子轮廓马",
|
||||
"像素复古游戏马",
|
||||
"剪纸艺术风格马",
|
||||
"霓虹灯线条马",
|
||||
"蒸汽朋克齿轮马",
|
||||
"浮世绘风格日本马",
|
||||
"黄金雕像马"
|
||||
],
|
||||
"action": [
|
||||
"坐着发呆",
|
||||
"奔跑",
|
||||
"跳跃",
|
||||
"飞翔在空中",
|
||||
"游泳",
|
||||
"跳舞",
|
||||
"大笑",
|
||||
"惊讶地看着前方",
|
||||
"抱着胡萝卜",
|
||||
"放风筝",
|
||||
"睡觉",
|
||||
"吃草",
|
||||
"哭泣",
|
||||
"挥手打招呼",
|
||||
"翻滚",
|
||||
"冥想漂浮",
|
||||
"变魔术",
|
||||
"写毛笔字",
|
||||
"演奏小提琴",
|
||||
"骑滑板",
|
||||
"拍照留念",
|
||||
"讲笑话",
|
||||
"种花",
|
||||
"搭建积木城堡",
|
||||
"阅读童话书",
|
||||
"打太极拳",
|
||||
"喷火",
|
||||
"召唤闪电",
|
||||
"隐身消失",
|
||||
"时间暂停",
|
||||
"穿越虫洞",
|
||||
"绘制星空",
|
||||
"拥抱朋友",
|
||||
"滑冰",
|
||||
"攀岩",
|
||||
"倒立行走",
|
||||
"吐彩虹",
|
||||
"用尾巴画画",
|
||||
"变身成光球",
|
||||
"与蝴蝶共舞",
|
||||
"点亮灯笼",
|
||||
"解开谜题"
|
||||
],
|
||||
"scene": [
|
||||
"纯白色背景",
|
||||
"纯黑色背景",
|
||||
"纯红色背景",
|
||||
"纯蓝色背景",
|
||||
"纯绿色背景",
|
||||
"纯黄色背景",
|
||||
"纯橙色背景",
|
||||
"纯紫色背景",
|
||||
"纯粉色背景",
|
||||
"纯灰色背景",
|
||||
"纯米色背景",
|
||||
"纯青色背景",
|
||||
"纯金色背景",
|
||||
"纯银色背景",
|
||||
"纯棕色背景",
|
||||
"纯天蓝色背景",
|
||||
"纯珊瑚色背景",
|
||||
"纯薄荷绿背景",
|
||||
"纯薰衣草紫背景",
|
||||
"纯象牙白背景"
|
||||
],
|
||||
"style": [
|
||||
"卡通渲染风格",
|
||||
"水彩手绘质感",
|
||||
"油画厚涂技法",
|
||||
"中国风水墨画",
|
||||
"赛博朋克霓虹光影",
|
||||
"皮克斯3D动画风格",
|
||||
"低多边形(Low Poly)",
|
||||
"极简扁平设计",
|
||||
"超现实主义梦境感",
|
||||
"蒸汽朋克机械细节",
|
||||
"浮世绘木刻纹理",
|
||||
"儿童绘本插图",
|
||||
"复古8-bit像素风",
|
||||
"哥特式暗黑美学",
|
||||
"波普艺术鲜艳撞色",
|
||||
"剪纸拼贴艺术",
|
||||
"玻璃彩绘效果",
|
||||
"金属蚀刻工艺",
|
||||
"沙画流动质感",
|
||||
"全息投影光泽",
|
||||
"黏土定格动画",
|
||||
"铅笔素描线稿",
|
||||
"荧光夜光风格",
|
||||
"大理石雕塑质感",
|
||||
"丝绸刺绣图案",
|
||||
"动态模糊运动感",
|
||||
"故障艺术(Glitch Art)",
|
||||
"糖霜甜点装饰风",
|
||||
"雪花结晶微观视角",
|
||||
"星空粒子特效",
|
||||
"幻彩渐变晕染",
|
||||
"蜡笔涂鸦童趣风",
|
||||
"青铜器铭文融合",
|
||||
"敦煌壁画色彩",
|
||||
"激光雕刻线条",
|
||||
"毛毡布艺手工感",
|
||||
"琉璃透光材质",
|
||||
"水墨晕染+数字合成",
|
||||
"霓虹灯牌背景",
|
||||
"复古胶片颗粒感",
|
||||
"动态流体模拟",
|
||||
"万圣节南瓜灯氛围"
|
||||
],
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user