ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

如何用 prompts.chat npm 包的 image() 构建器生成 Midjourney、DALL-E 图像提示词?

如何用 prompts.chat npm 包的 image() 构建器生成 Midjourney、DALL-E 图像提示词? 如何用 prompts.chat npm 包的 image() 构建器生成 Midjourney、DALL-E 图像提示词【免费下载链接】prompts.chatf.k.a. Awesome ChatGPT Prompts. Share, discover, and collect prompts from the community. Free and open source — self-host for your organization with complete privacy.项目地址: https://gitcode.com/GitHub_Trending/aw/prompts.chat在需要为图像生成模型编写提示词时手动拼接主体 环境 镜头 灯光 风格长句很容易漏项团队成员写出来的格式也不一致。prompts.chatnpm 包提供的image()构建器解决这个问题它把主体、环境、相机、灯光、构图、风格、色彩、技术参数都做成可链式调用的方法.build()后直接输出一条完整的提示词字符串和对应的结构化数据。包文档对 Image Builder 的定位是Works with Midjourney, DALL-E, Stable Diffusion, Flux, and other image AI platforms见 packages/prompts.chat/README.md。本文只覆盖一件事用image()从安装到产出可核对的提示词文本。先说清楚产出边界image()构建器输出的是提示词文本和结构化数据它本身不调用 Midjourney 或 DALL-E 的 API。你拿到生成的字符串后再把它用到自己的图像平台或 API 客户端里。安装 prompts.chat 包在项目中执行npm install prompts.chat前置条件以包元数据为准packages/prompts.chat/package.json 中engines声明node: 18即需要 Node.js 18 或更高版本。该包同时提供 ESM 和 CJS 构建exports字段中import指向./dist/index.mjs、require指向./dist/index.jsESM 项目和 CommonJS 项目都可以直接引入。image从包主入口导出见 src/index.ts 中对image的再导出工厂函数image()定义在 src/builder/media.ts返回一个ImagePromptBuilder实例。最短路径一条链式调用产出提示词以下是 README Quick Start 中的示例保存为脚本即可运行import { image } from prompts.chat; const prompt image() .subject(a lone samurai) .environment(bamboo forest at dawn) .camera({ angle: low-angle, shot: wide, lens: 35mm }) .lighting({ type: rim, time: golden-hour }) .medium(cinematic) .build(); console.log(prompt.prompt);各方法的作用按 README 的方法参考表对应.subject()设置主体、.environment()设置环境、.camera()一次性设置相机参数景别shot、角度angle、镜头lens、.lighting()一次性设置灯光参数、.medium()设置艺术风格ArtStyle。按照构建器的拼装规则见 media.ts 的 buildPromptText各部分按 主体 → 环境 → 构图 → 相机 → 灯光 → 风格 → 色彩 → 情绪 → 技术参数 的顺序用逗号连接上面这段代码得到的输出如下示例结果按源码拼装规则推演a lone samurai, bamboo forest at dawn, wide shot, low-angle, 35mm lens, rim lighting, golden-hour, cinematic如果链上没有调用.negative()和.aspectRatio()输出就只有这段正文不会带任何后缀。读懂 build() 的返回值build()返回一个BuiltImagePrompt对象包含两个字段见 README 的 Output Structure 与 media.tsinterface BuiltImagePrompt { prompt: string; // Full formatted prompt with --no and --ar flags structure: { subject?: ImageSubject; camera?: ImageCamera; lighting?: ImageLighting; composition?: ImageComposition; style?: ImageStyle; color?: ImageColor; environment?: ImageEnvironment; technical?: ImageTechnical; mood?: Mood | Mood[]; negative?: string[]; }; }prompt是直接可用的提示词字符串。structure是回显的原始结构化数据方便你在代码里做二次处理比如按字段渲染表单、或按平台改写文本。两个固定后缀规则来自拼装逻辑media.ts调用过.negative([...])时在提示词末尾追加--no 项1, 项2调用过.aspectRatio(2:3)时在提示词末尾追加--ar 2:3。另外两条拼装细节值得知道.subjectCount()设置的数量值如果不是single会在主体前拼成数量 主体.subject()传对象时expression会拼成..., 表情 expressionclothing会拼成..., wearing ...。完整参数示例一张奇幻插画提示词下面是 README Usage Examples 中的 Fantasy Illustration 示例。它同时演示了主体对象、环境对象、多值风格、艺术家、色彩、情绪以及negative和aspectRatio两个会触发后缀的方法const fantasy image() .subject({ main: elven queen, expression: regal and mysterious, pose: seated on crystal throne, clothing: flowing silver gown with starlight patterns, accessories: [crown of moonstone, ancient scepter] }) .environment({ setting: ethereal forest palace, atmosphere: magical mist and floating lights, props: [glowing flowers, ancient trees] }) .medium([fantasy, illustration]) .artist([Alan Lee, Brian Froud]) .palette(cool) .primaryColors([silver, deep blue, violet]) .lightingType(soft) .mood([ethereal, mysterious]) .aspectRatio(2:3) .quality(ultra) .negative([modern elements, technology]) .build(); console.log(fantasy.prompt);按拼装规则核对这条输出时应看到正文依次包含主体细节elven queen、seated on crystal throne、wearing flowing silver gown with starlight patterns、with crown of moonstone, ancient scepter、环境ethereal forest palace、风格fantasy, illustration, in the style of Alan Lee and Brian Froud、色彩cool color palette、primary colors: silver, deep blue, violet、灯光soft lighting、情绪ethereal, mysterious mood、技术ultra quality结尾固定以--no modern elements, technology --ar 2:3收尾前缀来自.negative()--ar值来自.aspectRatio()。README 中还给出了三个不同场景的完整示例可以直接改写Portrait Photography人像、Product Photography产品、Cinematic Landscape风光都在 packages/prompts.chat/README.md 的 Image Builder 章节里。所有链式方法的完整签名在 README 的 Methods Reference 表中Subject / Environment / Camera / Lighting / Composition / Style / Color / Technical 八组。几个常用单值方法对应关系.shot()景别extreme-close-up到headshot、.focus()景深shallow、deep、bokeh-heavy等、.aperture()光圈传入1.8会拼成f/1.8、.filmStock()胶片拼成shot on ...、.timeOfDay()时段golden-hour、night等。导出为 JSON、YAML 或 MarkdownBuiltImagePrompt上除build()外还提供导出方法media.tsconst json fantasy.toJSON(); // 结构化数据的 JSON 字符串 const yaml fantasy.toYAML(); // YAML 字符串 const md fantasy.toMarkdown(); // 含 Prompt 与分节列表的 Markdown const text fantasy.format(json); // format(fmt) 按 text | json | yaml | markdown 分发toJSON()输出的是structure对象的 JSON 序列化可被JSON.parse还原适合把提示词连同参数存进你的数据库或配置toMarkdown()会生成带# Image Prompt标题、## Prompt代码块和各字段分节的文档适合存档或评审。验证生成的提示词文档中可用的验证方式有两层运行脚本直接查看。对上面的示例最小核对项是console.log(fantasy.prompt)的输出包含你设置的关键词如elven queen、cool color palette且结尾出现--no和--ar后缀当且仅当你调用过对应方法。参照仓库自己的测试断言方式。src/tests/builder.test.ts 中 ImagePromptBuilder 的测试用expect(result.prompt).toContain(close-up)这类断言验证设置项确实进入了输出文本并验证toJSON()的结果能被JSON.parse解析。在自己的项目里做自动化检查时可以照这个思路写断言设置过的每个关键值都应出现在prompt字符串中。边界与限制包当前版本为0.1.1package.json要求 Node.js 18。image()只做提示词文本与结构化数据的生成。README 说明 Image Builder Works with Midjourney, DALL-E, Stable Diffusion, Flux, and other image AI platforms但文档没有说明--no/--ar这两个后缀在各平台上分别被如何识别也没有提供任何调用图像模型 API 的代码。跨平台使用这条输出时请在你自己的集成层处理平台差异。大部分参数值是固定的联合类型枚举不是自由文本。例如aspectRatio只接受1:1 | 4:3 | 3:2 | 16:9 | 21:9 | 9:16 | 2:3 | 4:5 | 5:4media.ts 的 AspectRatio 类型shot、angle、lens、lightingType、mood等同样如此传入列表外的值会在 TypeScript 类型检查时报错。自由描述类的参数subject、environment、artist、influence等才是任意字符串。需要完全自定义措辞时.custom(text)会把文本原样追加到正文末尾在--no后缀之前这是不经过拼装模板的直接出口。完整的方法清单、类型定义和各场景示例继续看 packages/prompts.chat/README.md 的 Image Builder 章节和 packages/prompts.chat/src/builder/media.ts。【免费下载链接】prompts.chatf.k.a. Awesome ChatGPT Prompts. Share, discover, and collect prompts from the community. Free and open source — self-host for your organization with complete privacy.项目地址: https://gitcode.com/GitHub_Trending/aw/prompts.chat创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表