├── .gitignore ├── .gitmodules ├── README.md ├── _config.yml ├── chatgpt ├── click-prompt.md ├── design-system.md ├── pipeline.sample.md ├── prompt-programming.md └── workflow.md ├── codeai.ipynb ├── codeai.py ├── codeai └── README.md ├── demo ├── .gitignore ├── build.gradle.kts ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle.kts └── src │ ├── main │ ├── kotlin │ │ └── com │ │ │ └── phodal │ │ │ └── aisample │ │ │ └── demo │ │ │ ├── CinemaScheduleService.kt │ │ │ ├── DemoApplication.kt │ │ │ ├── NotScheduleAvailableException.kt │ │ │ ├── NotSeatAvailableException.kt │ │ │ ├── TickerOrderApplicationService.kt │ │ │ ├── TicketController.kt │ │ │ ├── TicketOrder.kt │ │ │ ├── TicketRepository.kt │ │ │ └── TicketService.kt │ └── resources │ │ └── application.properties │ └── test │ └── kotlin │ └── com │ └── phodal │ └── aisample │ └── demo │ └── DemoApplicationTests.kt ├── image2txt.ipynb ├── images ├── chatgpt-article-demo.png ├── chatgpt-ddd.png ├── ddd-copilot-1.png ├── ddd-copilot.png ├── focus-driven.png ├── github-copilot-1.png ├── github-sample-2.png ├── github-sample-3.png ├── github-sample-4.png ├── github-sample-5.png ├── hand-final-result.jpeg ├── stable-diffusion-hug8217.jpeg ├── stable-diffusion-overview.jpeg ├── stable-diffusion-with-controlnet-dreambooth.jpeg ├── stable-diffusion-with-controlnet.jpeg ├── stable-diffusion-with-negative.jpeg ├── strategy │ └── sample-output.png └── try-fix-hands.jpeg ├── output ├── better.jpeg ├── chatgpt-writing-article.png ├── failure-seeds.jpeg ├── failure-with-hand-hair.jpeg ├── image-with-canny.jpeg ├── image-with-hed.png ├── image-with-openpose.jpeg ├── sample.jpg ├── samples │ ├── 01.jpeg │ ├── 02.jpeg │ ├── 03.jpeg │ ├── 04.jpeg │ ├── 05.jpeg │ ├── 06.jpeg │ ├── 07.jpeg │ └── 08.jpeg ├── with-prompt.jpeg ├── women-backview-1.jpeg ├── women-backview-2.jpeg ├── women-backview-3.jpeg └── women-backview-4.jpeg ├── requirements.txt ├── stable-diffusion ├── README.md ├── ai-ethics.md ├── chtgpt-v50.md ├── guofeng │ └── README.md ├── images │ ├── failure-flying-head.jpeg │ ├── failured-everyway-head.jpeg │ ├── failured-hands.jpeg │ ├── hires-failure.jpeg │ ├── mix.png │ ├── no-negative-lot-of-hands.png │ ├── opensoe.png │ ├── with-negative.png │ └── words-with-opensose.png ├── styles.csv └── train-story.md ├── translate.ipynb └── txt2image.ipynb /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | diff-codegen-6b-v2 3 | codegen-2B-mono 4 | codegen-350M-mono 5 | vit-gpt2-image-captioning -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "3rd-party/prompt-engine"] 2 | path = 3rd-party/prompt-engine 3 | url = https://github.com/microsoft/prompt-engine 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 理解 Prompt:基于编程、绘画、写作的 AI 探索与总结 2 | 3 | 欢迎使用集成了这些模式的工具:https://github.com/prompt-engineering/click-prompt 4 | 5 | 目录: 6 | 7 | 1. [理解 Prompt](#%E5%9F%BA%E4%BA%8E%E7%BC%96%E7%A8%8B%E3%80%81%E7%BB%98%E7%94%BB%E3%80%81%E5%86%99%E4%BD%9C%E7%9A%84-ai-%E6%8E%A2%E7%B4%A2%E4%B8%8E%E6%80%BB%E7%BB%93%EF%BC%9A%E7%90%86%E8%A7%A3-prompt) 8 | 1. [图形生成:如何描述一张照片??](#%E5%9B%BE%E5%BD%A2%E7%94%9F%E6%88%90%EF%BC%9A%E5%A6%82%E4%BD%95%E6%8F%8F%E8%BF%B0%E4%B8%80%E5%BC%A0%E7%85%A7%E7%89%87%EF%BC%9F%EF%BC%9F) 9 | 1. [文本描述:第一个示例](#%E6%96%87%E6%9C%AC%E6%8F%8F%E8%BF%B0%EF%BC%9A%E7%AC%AC%E4%B8%80%E4%B8%AA%E7%A4%BA%E4%BE%8B) 10 | 2. [精准控图:结合 ControlNet](#%E7%B2%BE%E5%87%86%E6%8E%A7%E5%9B%BE%EF%BC%9A%E7%BB%93%E5%90%88-controlnet) 11 | 3. [更多的模型集:与二次元世界的照片(18 禁)](#%E6%9B%B4%E5%A4%9A%E7%9A%84%E6%A8%A1%E5%9E%8B%E9%9B%86%EF%BC%9A%E4%B8%8E%E4%BA%8C%E6%AC%A1%E5%85%83%E4%B8%96%E7%95%8C%E7%9A%84%E7%85%A7%E7%89%87%EF%BC%8818-%E7%A6%81%EF%BC%89) 12 | 4. [小结](#%E5%B0%8F%E7%BB%93) 13 | 2. [文章:如何围绕特定主题思考?](#%E6%96%87%E7%AB%A0%EF%BC%9A%E5%A6%82%E4%BD%95%E5%9B%B4%E7%BB%95%E7%89%B9%E5%AE%9A%E4%B8%BB%E9%A2%98%E6%80%9D%E8%80%83%EF%BC%9F) 14 | 1. [情境:如何用 ChatGPT 写一篇文章,以如何用 ChatGPT 写一篇文章?](#%E6%83%85%E5%A2%83%EF%BC%9A%E5%A6%82%E4%BD%95%E7%94%A8-chatgpt-%E5%86%99%E4%B8%80%E7%AF%87%E6%96%87%E7%AB%A0%EF%BC%8C%E4%BB%A5%E5%A6%82%E4%BD%95%E7%94%A8-chatgpt-%E5%86%99%E4%B8%80%E7%AF%87%E6%96%87%E7%AB%A0?) 15 | 2. [构建更完整的上下文](#%E6%9E%84%E5%BB%BA%E6%9B%B4%E5%AE%8C%E6%95%B4%E7%9A%84%E4%B8%8A%E4%B8%8B%E6%96%87) 16 | 3. [构建框架(frameworks)](#%E6%9E%84%E5%BB%BA%E6%A1%86%E6%9E%B6%EF%BC%88frameworks%EF%BC%89) 17 | 4. [其它小建议:](#%E5%85%B6%E5%AE%83%E5%B0%8F%E5%BB%BA%E8%AE%AE%EF%BC%9A) 18 | 3. [代码生成:GitHub Copilot](#%E4%BB%A3%E7%A0%81%E7%94%9F%E6%88%90%EF%BC%9Agithub-copilot) 19 | 1. [完整示例:DDD + ChatGPT + Copilot](#%E5%AE%8C%E6%95%B4%E7%A4%BA%E4%BE%8B%EF%BC%9Addd-+-chatgpt-+-copilot) 20 | 2. [其它:代码生成开源模型](#%E5%85%B6%E5%AE%83%EF%BC%9A%E4%BB%A3%E7%A0%81%E7%94%9F%E6%88%90%E5%BC%80%E6%BA%90%E6%A8%A1%E5%9E%8B) 21 | 4. [总结:AI 就像占卜](#%E6%80%BB%E7%BB%93%EF%BC%9Aai-%E5%B0%B1%E5%83%8F%E5%8D%A0%E5%8D%9C) 22 | 5. [其它:Macbook Pro 的吐槽](#%E5%85%B6%E5%AE%83%EF%BC%9Amacbook-pro-%E7%9A%84%E5%90%90%E6%A7%BD) 23 | 1. [AI 生态不友好](#ai-%E7%94%9F%E6%80%81%E4%B8%8D%E5%8F%8B%E5%A5%BD) 24 | 6. [本文相关资源](#%E6%9C%AC%E6%96%87%E7%9B%B8%E5%85%B3%E8%B5%84%E6%BA%90) 25 | 2. [Prompt 编程:打通低代码的最后一公里?](#%E5%AE%9E%E6%97%B6%E7%9A%84%E8%BD%AF%E4%BB%B6%E7%94%9F%E6%88%90-**%E2%80%94%E2%80%94-prompt-%E7%BC%96%E7%A8%8B%E6%89%93%E9%80%9A%E4%BD%8E%E4%BB%A3%E7%A0%81%E7%9A%84%E6%9C%80%E5%90%8E%E4%B8%80%E5%85%AC%E9%87%8C%EF%BC%9F**) 26 | 1. [引子](#%E5%BC%95%E5%AD%90) 27 | 2. [Prompt 编程:真正的无代码](#prompt-%E7%BC%96%E7%A8%8B%EF%BC%9A%E7%9C%9F%E6%AD%A3%E7%9A%84%E6%97%A0%E4%BB%A3%E7%A0%81) 28 | 1. [Prompt 编程特性 1:从需求到代码的直接转换](#prompt-%E7%BC%96%E7%A8%8B%E7%89%B9%E6%80%A7-1%EF%BC%9A%E4%BB%8E%E9%9C%80%E6%B1%82%E5%88%B0%E4%BB%A3%E7%A0%81%E7%9A%84%E7%9B%B4%E6%8E%A5%E8%BD%AC%E6%8D%A2) 29 | 2. [Prompt 编程特性 2:代码只是临时产物](#prompt-%E7%BC%96%E7%A8%8B%E7%89%B9%E6%80%A7-2%EF%BC%9A%E4%BB%A3%E7%A0%81%E5%8F%AA%E6%98%AF%E4%B8%B4%E6%97%B6%E4%BA%A7%E7%89%A9) 30 | 3. [Prompt 编程特性 3:次序化的分解框架](#prompt-%E7%BC%96%E7%A8%8B%E7%89%B9%E6%80%A7-3%EF%BC%9A%E6%AC%A1%E5%BA%8F%E5%8C%96%E7%9A%84%E5%88%86%E8%A7%A3%E6%A1%86%E6%9E%B6) 31 | 4. [Prompt 编程特性 4:语言即语言](#prompt-%E7%BC%96%E7%A8%8B%E7%89%B9%E6%80%A7-4%EF%BC%9A%E8%AF%AD%E8%A8%80%E5%8D%B3%E8%AF%AD%E8%A8%80) 32 | 3. [Prompt 编程 Demo:引导 ChatGPT 创建语言与建模](#prompt-%E7%BC%96%E7%A8%8B-demo%EF%BC%9A%E5%BC%95%E5%AF%BC-chatgpt-%E5%88%9B%E5%BB%BA%E8%AF%AD%E8%A8%80%E4%B8%8E%E5%BB%BA%E6%A8%A1) 33 | 1. [阶段一:让 ChatGPT 与你学 DDD](#%E9%98%B6%E6%AE%B5%E4%B8%80%EF%BC%9A%E8%AE%A9-chatgpt-%E4%B8%8E%E4%BD%A0%E5%AD%A6-ddd) 34 | 2. [阶段二:完整设计 + DSL 生成](#%E9%98%B6%E6%AE%B5%E4%BA%8C%EF%BC%9A%E5%AE%8C%E6%95%B4%E8%AE%BE%E8%AE%A1-+-dsl-%E7%94%9F%E6%88%90) 35 | 3. [阶段三:代码生成与低代码](#%E9%98%B6%E6%AE%B5%E4%B8%89%EF%BC%9A%E4%BB%A3%E7%A0%81%E7%94%9F%E6%88%90%E4%B8%8E%E4%BD%8E%E4%BB%A3%E7%A0%81) 36 | 4. [小结](#%E5%B0%8F%E7%BB%93) 37 | 4. [实时的软件生成:自然语言即 Prompt,Prompt 即代码](#%E5%AE%9E%E6%97%B6%E7%9A%84%E8%BD%AF%E4%BB%B6%E7%94%9F%E6%88%90%EF%BC%9A%E8%87%AA%E7%84%B6%E8%AF%AD%E8%A8%80%E5%8D%B3-prompt%EF%BC%8Cprompt-%E5%8D%B3%E4%BB%A3%E7%A0%81) 38 | 1. [特征 1:自然语言即语言,语言即软件](#%E7%89%B9%E5%BE%81-1%EF%BC%9A%E8%87%AA%E7%84%B6%E8%AF%AD%E8%A8%80%E5%8D%B3%E8%AF%AD%E8%A8%80%EF%BC%8C%E8%AF%AD%E8%A8%80%E5%8D%B3%E8%BD%AF%E4%BB%B6) 39 | 1. [特征 2:生成式的软件架构](#%E7%89%B9%E5%BE%81-2%EF%BC%9A%E7%94%9F%E6%88%90%E5%BC%8F%E7%9A%84%E8%BD%AF%E4%BB%B6%E6%9E%B6%E6%9E%84) 40 | 1. [特征 3:自底向上生成](#%E7%89%B9%E5%BE%81-3%EF%BC%9A%E8%87%AA%E5%BA%95%E5%90%91%E4%B8%8A%E7%94%9F%E6%88%90) 41 | 5. [当前的挑战](#%E5%BD%93%E5%89%8D%E7%9A%84%E6%8C%91%E6%88%98) 42 | 6. [总结](#%E6%80%BB%E7%BB%93) 43 | 3. [如何利用好 AIGC ?从 AI 绘画的演进与 ChatGPT 现状出发](#%E5%A6%82%E4%BD%95%E5%88%A9%E7%94%A8%E5%A5%BD-aigc-%EF%BC%9F%E4%BB%8E-ai-%E7%BB%98%E7%94%BB%E7%9A%84%E6%BC%94%E8%BF%9B%E4%B8%8E-chatgpt-%E7%8E%B0%E7%8A%B6%E5%87%BA%E5%8F%91) 44 | 1. [如何构建高质量的 AI 图形:精准控线 + 个人模型](#%E5%A6%82%E4%BD%95%E6%9E%84%E5%BB%BA%E9%AB%98%E8%B4%A8%E9%87%8F%E7%9A%84-ai-%E5%9B%BE%E5%BD%A2%EF%BC%9A%E7%B2%BE%E5%87%86%E6%8E%A7%E7%BA%BF-+-%E4%B8%AA%E4%BA%BA%E6%A8%A1%E5%9E%8B) 45 | 1. [严格化验收条件:Negative Prompt](#%E4%B8%A5%E6%A0%BC%E5%8C%96%E9%AA%8C%E6%94%B6%E6%9D%A1%E4%BB%B6%EF%BC%9Anegative-prompt) 46 | 2. [构架蓝图:ControlNet 精准控线](#%E6%9E%84%E6%9E%B6%E8%93%9D%E5%9B%BE%EF%BC%9Acontrolnet-%E7%B2%BE%E5%87%86%E6%8E%A7%E7%BA%BF) 47 | 3. [轻量小模型:DreamBooth 个人模型与风格化](#%E8%BD%BB%E9%87%8F%E5%B0%8F%E6%A8%A1%E5%9E%8B%EF%BC%9Adreambooth-%E4%B8%AA%E4%BA%BA%E6%A8%A1%E5%9E%8B%E4%B8%8E%E9%A3%8E%E6%A0%BC%E5%8C%96) 48 | 4. [完善与细化:局部绘制 —— InPaint 的手部修复](#%E5%AE%8C%E5%96%84%E4%B8%8E%E7%BB%86%E5%8C%96%EF%BC%9A%E5%B1%80%E9%83%A8%E7%BB%98%E5%88%B6-%E2%80%94%E2%80%94-inpaint-%E7%9A%84%E6%89%8B%E9%83%A8%E4%BF%AE%E5%A4%8D) 49 | 5. [小小的总结:严格化验收条件 + 构架蓝图 + 轻量小模型 + 完善与细化](#%E5%B0%8F%E5%B0%8F%E7%9A%84%E6%80%BB%E7%BB%93%EF%BC%9A%E4%B8%A5%E6%A0%BC%E5%8C%96%E9%AA%8C%E6%94%B6%E6%9D%A1%E4%BB%B6-+-%E6%9E%84%E6%9E%B6%E8%93%9D%E5%9B%BE-+-%E8%BD%BB%E9%87%8F%E5%B0%8F%E6%A8%A1%E5%9E%8B-+-%E5%AE%8C%E5%96%84%E4%B8%8E%E7%BB%86%E5%8C%96) 50 | 2. [个人 AI 策略:构架 + 磨炼 + 小模型](#%E4%B8%AA%E4%BA%BA-ai-%E7%AD%96%E7%95%A5%EF%BC%9A%E6%9E%84%E6%9E%B6-+-%E7%A3%A8%E7%82%BC-+-%E5%B0%8F%E6%A8%A1%E5%9E%8B) 51 | 1. [策略 0:拥抱变化](#%E7%AD%96%E7%95%A5-0%EF%BC%9A%E6%8B%A5%E6%8A%B1%E5%8F%98%E5%8C%96) 52 | 2. [策略 1:强化构架能力](#%E7%AD%96%E7%95%A5-1%EF%BC%9A%E5%BC%BA%E5%8C%96%E6%9E%84%E6%9E%B6%E8%83%BD%E5%8A%9B) 53 | 3. [策略 2:构建领域小模型](#%E7%AD%96%E7%95%A5-2%EF%BC%9A%E6%9E%84%E5%BB%BA%E9%A2%86%E5%9F%9F%E5%B0%8F%E6%A8%A1%E5%9E%8B) 54 | 3. [策略 3:探索与磨炼技巧](#%E7%AD%96%E7%95%A5-3%EF%BC%9A%E6%8E%A2%E7%B4%A2%E4%B8%8E%E7%A3%A8%E7%82%BC%E6%8A%80%E5%B7%A7) 55 | 4. [小结](#%E5%B0%8F%E7%BB%93) 56 | 57 | 文件目录: 58 | 59 | - Stable Diffusion 简易教程:[Stable Diffusion](./stable-diffusion) 60 | - 从 AI 绘画看 AIGC 的未来 61 | - Jupyter 练习 AI 相关部分 62 | - [translate.ipynb](./translate.ipynb) 中文翻译英文 63 | - [codeai.ipynb](./codeai.ipynb) 代码自动生成 64 | 65 | # 基于编程、绘画、写作的 AI 探索与总结:理解 Prompt 66 | 67 | PS:本文的图形部分因 “真实世界原因”,包含一些年龄受限的词汇,建议未成年人在监护人陪同下阅读。 68 | 69 | 就当前节点(2023.02.22)而言,我虽然研究过一段时间传统的机器学习,但是并不擅长深度学习等领域,所以很多 AI 领域相关的词汇,我是不擅长的,只为自己总结一下,方便在未来更新自己的认识。 70 | 71 | 内容主要是结合我过去擅长的编程、写作、绘画展开的: 72 | 73 | 1. 绘画:text 2 image。结合 Stable Diffusion 讲述一张图片的演化。 74 | 2. 写作:chat 2 article。结合 ChatGPT 讲述围绕特定主题的内容创作。 75 | 3. 编程:comment 2 code。结合 GitHub Copilot 如何加速日常的编程活动。 76 | 77 | 总体来说,**AI 相当于美国队长的实力,遇强则强,遇弱则弱**,关键其实在于 Prompt。所以,如何更好地完善 prompt,实现 prompt 工程就是:如何更好地使用 AI 的基础。 78 | 79 | > Prompt 是一种文本输入方式,用于与自然语言处理模型(例如GPT)进行交互。Prompt 是一个短语或一句话,可以启动模型并产生与 Prompt 相关的输出。这个输出可以是一个单独的单词、一句话,或者是一段完整的段落。它可以控制模型的行为,使其产生特定的结果。 80 | 81 | 所以,如何更好地完善 prompt,实现 prompt 工程就是:如何更好地使用 AI 的基础。所以,在这篇文章里,我将介绍: 82 | 83 | 1. 用 text 2 image 来展示如何演进 prompt 84 | 2. 用 text 2 article 来展示充足 prompt 的优点 85 | 3. 结合 GitHub Copliot 来实现 prompt 完成工作 86 | 87 | PS:感谢我老婆提供的照片。 88 | 89 | ## 图形生成:如何描述一张照片?? 90 | 91 | 人类需要思考第一个问题:如何描述一张照片?在不关心感受的情况下,我们关注于主体、背景、颜色、构图等。 92 | 93 | 现在,我们脑海中出现一个场景: 94 | 95 | ![](./output/sample.jpg) 96 | 97 | 接着,用文本来抽象它。在这里,我结合一下 Stable Diffusion 来讲述一下过程。 98 | 99 | ### 文本描述:第一个示例 100 | 101 | 生成 prompt: 102 | 103 | - phodal: 我想写一段话描述一张照片,帮我美化一下:一年轻女子穿着裙子,背对着镜头,在海边看着日落,太阳已经到地平线下面了,她的头发在风中飘动。 104 | - ChatGPT: 这张照片中的场景令人心醉,一位年轻女子穿着一条裙子,站在海边,背对着镜头,凝视着地平线下的夕阳。太阳已经沉入了海面,一片金黄色的光芒在海面上弥漫,照亮了整片海洋,仿佛这个时刻被定格在了时间的某个角落里。女子的头发随着微风轻轻飘动,轮廓被余晖映照得柔和而温暖。她的目光凝视着远方,仿佛在思考着生命的意义和无尽的未来。这张照片中蕴含着一种深刻的内涵,让人感受到时间和自然的力量,也让人思考着自己在这个宏大而美丽的世界中的角色和意义。 105 | 106 | 如果转换成英语的话: 107 | 108 | > A young woman wearing a flowing dress stands at the edge of the sea, her back turned to the camera as she gazes upon 109 | > the glow of the setting sun. The ocean stretches out before her in all its grandeur, and the sun slowly sinks below 110 | > the horizon, casting a golden light over the water. The woman's hair sways gently in the breeze, her features softened 111 | > by the warm hues of the sunset. Her gaze is fixed on the distance, as if pondering the meaning of life and the endless 112 | > possibilities of the future. 113 | 114 | 重复了 N 次之后,你会得到你想要的成功的照片,当然也会有失败的出现(因为没有配置 negative prompt 过滤失败的情况): 115 | 116 | ![Failure](./output/failure-seeds.jpeg) 117 | 118 | 但是,熟悉各种搜索引擎的关键词的或者 NLP 的你,肯定知道,上面的大部分可能是废话,可以减化为如下的词,并添加一些专用的模型词汇,如`black hair`, `hand before body`, `no hand`, `bodycon dress`: 119 | 120 | > women back view without face, flowing dress, edge of the sea, backview, back turned to the camera, upon the glow of the setting sun, sun below the horizon, golden light over the water, hair sways gently, Chinese style clothes, black hair, 121 | 122 | 随后,添加一些反向 prompt,意思是不要这些内容,诸如于 AI 不擅长的:`bad hands`、`morbid` 等等。随后,不断调整 prompt,比如生成更好的 Prompt: 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 |
131 | 132 | 133 | 诸如于采用 [Magic Prompt](https://huggingface.co/spaces/Gustavosta/MagicPrompt-Stable-Diffusion)。 134 | 135 | ### 精准控图:结合 ControlNet 136 | 137 | 由于生成的姿势是随机的、无法控制,所以我就引入了 ControlNet 插件 ——用来实现骨骼绑定、精准控线、线稿上色、依据深度图结构透视精准重绘等。现在,就能结合我们做的创作来完善生成的图形,诸如于我们绘制草图、或者输入一张原始图片,就可以生成我们预期的效果: 138 | 139 | 最后,生成的图片如下: 140 | 141 | ![Openpose](output/image-with-hed.png) 142 | 143 | 在我写完文章的时候,又修改了一下 prompt: 144 | 145 | > women back view without face standing on the sandy beach, bodycov full skirt, edge of the sea, back turned to the camera, upon the glow of the setting sun, black hair, sunset red to blue gradient sky 146 | 147 | 对应的 negative prompt 是: 148 | 149 | 150 | > (((simple background))),monochrome ,lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, lowres, bad anatomy, bad hands, text, error, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, ugly,pregnant,vore,duplicate,morbid,mut ilated,tran nsexual, hermaphrodite,long neck,mutated hands,poorly drawn hands,poorly drawn face,mutation,deformed,blurry,bad anatomy,bad proportions,malformed limbs,extra limbs,cloned face,disfigured,gross proportions, (((missing arms))),(((missing legs))), (((extra arms))),(((extra legs))),pubic hair, plump,bad legs,error legs,username,blurry,bad feet 151 | 152 | 效果凑合着,还是不错的。然后,我们可以做更多的尝试,配合一下参数调整(俗称炼丹): 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 |
166 | 167 | 也可以结合 inpaint 对失真的部分进行修复。 168 | 169 | ### 更多的模型集:与二次元世界的照片(18 禁) 170 | 171 | 众所周知,AI 的生成质量是与模型息息相关的,所以好的质量需要有好的模型。 172 | 173 | 我们可以在 [https://civitai.com/](https://civitai.com/) 上找到更多的模型,不过因为年龄限制等原因,只建议你在安全的场所打开,不建议在公共场所打开。 174 | 175 | 真实的人物由于版权的种种原因,所以这个软件在二次元世界相当的流行。如下是常见的提示词来描述模型的质量,里面可能包含一些不适词语,为了体现真实世界,这里并不打算屏蔽。 176 | 177 | 提示词 : 178 | 179 | > modelshoot style, (wavy blue hair), ((half body portrait)), ((showing boobs, giant boobs, humongous breasts)), (( 180 | > beautiful light makeup female sorceress in majestic blue dress)), photo realistic game cg, 8k, epic, (blue diamond 181 | > necklace hyper intricate fine detail), symetrical features, joyful, majestic oil painting by Mikhail Vrubel, Atey 182 | > Ghailan, by Jeremy Mann, Greg Manchess, WLOP, Charlie Bowater, trending on ArtStation, trending on CGSociety, Intricate, 183 | > High Detail, Sharp focus, dramatic, photorealistic, black background, epic volumetric lighting, fine details, 184 | > illustration, (masterpiece, best quality, highres), standing in majestic castle 185 | 186 | 负面提示词 187 | 188 | > (((simple background))),monochrome ,lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer 189 | > digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, 190 | > lowres, bad anatomy, bad hands, text, error, extra digit, fewer digits, cropped, worst quality, low quality, normal 191 | > quality, jpeg artifacts, signature, watermark, username, blurry, ugly,pregnant,vore,duplicate,morbid,mut ilated,tran 192 | > nsexual, hermaphrodite,long neck,mutated hands,poorly drawn hands,poorly drawn face,mutation,deformed,blurry,bad 193 | > anatomy,bad proportions,malformed limbs,extra limbs,cloned face,disfigured,gross proportions, (((missing arms))),((( 194 | > missing legs))), (((extra arms))),(((extra legs))),pubic hair, plump,bad legs,error legs,username,blurry,bad feet, 195 | > lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low 196 | > quality, normal quality, jpeg artifacts, signature, watermark, username, blurry 197 | 198 | 足够丰富的描述,可以帮助 AI 理解描述我们的需求: 199 | 200 | ![Better Quality](./output/better.jpeg) 201 | 202 | 上图为 AI 生成,也是同样场景下,不屏蔽的结果 —— 其原因是大部分的模型库加入了很多 18 禁的内容。 203 | 204 | ### 小结 205 | 206 | 现在,让我们来思考一下,如何描述一张带人物的图片: 207 | 208 | - 详细的描述词。 209 | - 人物的姿势。 210 | - 丰富的模型。 211 | - 反复修改的参数。 212 | - 持续迭代。(基于 InPaint 等进行修改) 213 | 214 | 那么,文章呢? 215 | 216 | ## 文章:如何围绕特定主题思考? 217 | 218 | 结合一下先前 Stable Diffusion 的无数次的失败经验,我们应该先找好一个合适的框架来跑 ChatGPT。 219 | 220 | 在编写内容的内容,我们会有各种思路和原则:STAR、金字塔原理、5W1H等等。 221 | 222 | 我们可以以 STAR (Situation(情景)Task(任务)、Action(行动)和 Result(结果))可以作为与 ChatGPT 会话的基础: 223 | 224 | 1. 描述一个情境或背景,使读者对问题有更好的了解。 225 | 2. 说明任务或目标,告诉读者需要完成什么。 226 | 3. 描述你所采取的行动,例如使用什么方法、工具、策略等等。 227 | 4. 解释结果,包括遇到的挑战和取得的成果。 228 | 229 | 这样,对于我们展开思路会有一些帮助。 230 | 231 | ### 情境:如何用 ChatGPT 写一篇文章,以如何用 ChatGPT 写一篇文章? 232 | 233 | phodal:我想写一篇文章,主题是《如何用 ChatGPT 写一篇文章,以如何用 ChatGPT 写一篇文章 》 234 | 235 | 示例: 236 | 237 | ![](./output/chatgpt-writing-article.png) 238 | 239 | 但是,这样的内容并非我们想要的。 240 | 241 | 而在这个标题里,其实 ChatGPT 已经理解了,如何写一篇文章,换作是一个冷门的话题,他就不知道了。在此时,我们需要构建一个更丰富的上下文: 242 | 243 | ![关注点驱动](images/focus-driven.png) 244 | 245 | 在这时,ChatGPT 给出的步骤依旧是错的,我们需要继续纠正。所以,我们可以考虑在一开始给一个完整的上下文: 246 | 247 | ### 构建更完整的上下文 248 | 249 | 对于 ChatGPT 来说,我们需要明确的 prompt:: 250 | 251 | ``` 252 | 253 | 我想写一篇文章,主题是《如何用 ChatGPT 写一篇文章,以如何用 ChatGPT 写一篇文章》,文章的大纲是: 254 | 255 | 1. 先用 100 字介绍一下 ChatGPT 256 | 2. 以 Julia 作为可以以具体的案例为例,介绍如何使用 ChatGPT 写一篇博客大赛的参赛作品。这包括如何确定主题、如何撰写开头和结尾、如何组织文章结构等等。主题是:《Julia Dataframe 在大数据分析领域的使用》,大纲中包含:用 200 字介绍一下 Julia 语言历史;介绍如何使用 DataFrames.jl,并有个代码示例;对比一下 Python Pandas、Apache Spark Dataframe;小结。 257 | 3. 对本文的内容进行总结,并再次强调使用 ChatGPT 进行写作的好处。 258 | 259 | 帮我写一篇文章? 260 | ``` 261 | 262 | 如此一来,我们提供的上下文就会更加准确,就可以看到一个范例: 263 | 264 | ![Demo](images/chatgpt-article-demo.png) 265 | 266 | 基于这个范例,可以思考我们的内容如何编写。 267 | 268 | ### 构建框架(frameworks) 269 | 270 | ChatGPT 本身构建了一个框架,我们可以再输入一个有用的框架,以构建简单的反馈回路。于是,我开始教他 DDD,然后相互学习: 271 | 272 | ![DDD Copilot](images/ddd-copilot-1.png) 273 | 274 | 不过,ChatGPT 和上面的图片一样,经常丢失一些上下文。 275 | 276 | phodal: 在这个 TicketOrder 聚合里,他应该包含哪些 API ? 277 | 278 | 在 TicketOrder 聚合里,可以包含以下一些 API: 279 | 280 | 1. createOrder():创建一个新的订单,可以接收顾客信息、场次信息、座位信息等参数,并返回一个唯一的订单号。 281 | 2. cancelOrder(orderId):取消某个订单,需要提供订单号。 282 | 3. getOrder(orderId):获取某个订单的详细信息,需要提供订单号。 283 | 4. reserveSeats(showTimeId, seatIds):在某个场次中预留座位,需要提供场次号和座位号。 284 | 5. confirmOrder(orderId):确认订单,此时座位被锁定并且订单状态被改为已确认。 285 | 6. payOrder(orderId, paymentInfo):支付订单,需要提供订单号和支付信息。 286 | 7. refundOrder(orderId):退票,需要提供订单号并且只能在订单状态为已确认时进行。 287 | 8. updateOrder(orderId, updateInfo):修改订单信息,可以更新顾客信息、场次信息、座位信息等,需要提供订单号和更新内容。 288 | 289 | 基本的 API 可以满足电影院订票业务的需求,但具体实现还需要根据业务场景和需求进行细化和调整。 290 | 291 | ### 其它小建议: 292 | 293 | 相似的,与 Stable Diffusion 类似的是,AI 生成的内容经常出现各种问题,所以我们要注意: 294 | 295 | 1. 保持自然的表达。ChatGPT 能够生成流畅的语句,但有时可能会出现奇怪或不合适的表达。在使用 ChatGPT 进行写作时,需要注意保持自然的表达方式。 296 | 2. 适时修正错误。如果 ChatGPT 生成的内容不准确或有错误,应该及时进行修正,以保证文章的准确性和可读性。 297 | 3. 多次修改和调整。ChatGPT 的输出结果虽然会自动进行语法纠错和编辑,但是为了保证文章质量,还是需要经过多次修改和调整,不断完善文章结构和内容。 298 | 4. 保持简洁明了。在使用 ChatGPT 进行写作时,需要尽量保持简洁明了,避免使用过于复杂的句式和词汇,以便读者更好地理解文章内容。 299 | 5. 注重原创性和独特性。尽管 ChatGPT 能够生成大量的文章,但是为了在博客大赛中脱颖而出,还需要注重文章的原创性和独特性,尽可能地突出自己的风格和思想。 300 | 301 | 考虑到 ChatGPT 的代码并不那么准确,让我们使用 GitHub Copilot 生成更多的内容。 302 | 303 | ## 代码生成:GitHub Copilot 304 | 305 | GitHub Copilot 是 GitHub 2021 年 8 月推出的一个 AI 代码生成工具,它可以根据你的代码,生成更多的代码。 306 | 307 | ![Samples](images/github-copilot-1.png) 308 | 309 | 所以,对于 Markdown 本身来说,它也能提供一些帮助。当然了,在这方向它没有 ChatGPT 那么强大,经常会出现一些奇怪的重复代码。 310 | 311 | 但是,也并非不可用,我们可以使用它来生成一些代码片段,以便于我们进行修改。 312 | 313 | ### 完整示例:DDD + ChatGPT + Copilot 314 | 315 | 如结合 Chat GPT 我们可以完成代码的前置设计(当然有些不靠谱): 316 | 317 | ![ChatGPT DDD](images/chatgpt-ddd.png) 318 | 319 | 复制生成的 API,写行注释告诉 Copilot:`convert to markdown table`,然后我们就有了: 320 | 321 | | API | 描述 | HTTP方法 | URL | 参数 | 返回值 | 322 | |--------|----------------|--------|-----------------------------------------------|--------|-------------| 323 | | 创建订单 | 创建一个新的订单 | POST | /ticket-orders | 创建订单信息 | 订单ID | 324 | | 查询订单 | 查询一个已存在的订单 | GET | /ticket-orders/{orderId} | 订单ID | 订单信息 | 325 | | 取消订单 | 取消一个已存在的订单 | DELETE | /ticket-orders/{orderId} | 订单ID | 取消成功或失败信息 | 326 | | 添加座位 | 向一个已存在的订单添加座位 | POST | /ticket-orders/{orderId}/seats | 座位信息 | 座位添加成功或失败信息 | 327 | | 移除座位 | 从一个已存在的订单中移除座位 | DELETE | /ticket-orders/{orderId}/seats/{seatId} | 座位ID | 座位移除成功或失败信息 | 328 | | 查询可用座位 | 查询某个场次电影的可用座位 | GET | /cinema-schedule/{scheduleId}/available-seats | 场次ID | 可用座位信息 | 329 | 330 | 接下来,我们可以使用 Spring + Copilot 来生成一些代码片段,以便于我们进行修改: 331 | 332 | ![github-copilot Sample](images/github-sample-2.png) 333 | 334 | 在有足够类相关信息的情况下,诸如于,我们提供一个注释: 335 | 336 | ```kotlin 337 | @PostMapping 338 | fun createTicketOrder(@RequestBody ticketOrder: TicketOrder): String { 339 | // check the schedule is valid, the seats are available, then create the order 340 | 341 | } 342 | ``` 343 | 344 | 它生成的代码会更加准确: 345 | 346 | ![GitHub sample 4](images/github-sample-4.png) 347 | 348 | 而如果我们添加了对应的 Exception 的处理注释:`check the schedule is valid, the seats are available, then create the order, if the schedule is not valid, throw NotScheduleAvailableException`,代码进一步转化为: 349 | 350 | ```kotlin 351 | @PostMapping 352 | fun createTicketOrder(@RequestBody ticketOrder: TicketOrder): String { 353 | // check the schedule is valid, the seats are available, then create the order, if the schedule is not valid, throw NotScheduleAvailableException 354 | // check the schedule is valid 355 | val schedule = cinemaScheduleService.getSchedule(ticketOrder.scheduleId) 356 | if (schedule == null) { 357 | throw NotScheduleAvailableException() 358 | } 359 | // check the seats are available 360 | val availableSeats = cinemaScheduleService.getAvailableSeats(ticketOrder.scheduleId) 361 | if (!availableSeats.containsAll(ticketOrder.seats)) { 362 | throw NotSeatAvailableException() 363 | } 364 | // create order 365 | return tickerOrderApplicationService.createOrder(ticketOrder) 366 | } 367 | ``` 368 | 369 | 在另外一些场景下,如果你的函数名和参数名都是英文,那么 Copilot 生成的代码也会更加准确: 370 | 371 | ![GitHub sample 5](images/github-sample-5.png) 372 | 373 | 而在单元测试的场景下,Copilot 更加强大和智能,它能够根据你的测试代码,生成更多的测试代码。 374 | 375 | ### 其它:代码生成开源模型 376 | 377 | 我也尝试了下 Saleforce 378 | 的代码模型:[https://huggingface.co/Salesforce/codegen-6B-mono](https://huggingface.co/Salesforce/codegen-6B-mono),但是不能在我的 MBP 上跑上来,有些遗憾。 379 | 380 | ## 总结:AI 就像占卜 381 | 382 | 你可能无法预期输出的是啥,总会有各种惊喜。 383 | 384 | 而其实,与 AI 的 prompt 相似的是:和人类聊天的时候,我们也需要提供足够的上下文。所以,你需要一下 ChatGPT,他并不总是能理解你的上下文。 385 | 386 | ## 其它:Macbook Pro 的吐槽 387 | 388 | 公司配置的 Macbook Pro 2019 虽然有 AMD 显卡,但是没有 CUDA、ROCm 的支持,所以只能用 CPU 来跑了。 389 | 390 | ### AI 生态不友好 391 | 392 | 诸如于 PyTorch,以前是支持 ROCm 加速的: 393 | 394 | ![ROCm](https://pytorch.org/assets/images/amd_rocm_blog.png) 395 | 396 | 现在的版本不行了:https://pytorch.org/get-started/locally/ 。 397 | 398 | ## 本文相关资源 399 | 400 | AI 生成图片: 401 | 402 | - Stable Diffusion Webui GitHub: https://github.com/AUTOMATIC1111/stable-diffusion-webui 403 | - 通用的 AI 模型社区:https://huggingface.co/ 404 | - Stable Diffusion AI 艺术模型社区:https://civitai.com/ (18 禁) 405 | 406 | 代码模型相关: 407 | 408 | - Salesforce 模型:https://huggingface.co/Salesforce/codegen-6B-mono 409 | - CarpserAI: https://huggingface.co/CarperAI/diff-codegen-6b-v2 410 | 411 | ControlNet 加强: 412 | 413 | - 模型:https://huggingface.co/lllyasviel/ControlNet 414 | - 预编译:https://huggingface.co/kohya-ss/ControlNet-diff-modules 415 | 416 | # 实时的软件生成 **—— Prompt 编程打通低代码的最后一公里?** 417 | 418 | PS:这也是一篇畅想,虽然经过了一番试验,依旧有一些不足,但是大体上站得住脚。 419 | 420 | 传统的软件生成方式需要程序员编写大量的代码,然后进行测试、发布等一系列繁琐的流程。而实时生成技术则是借助人工智能技术,让计算机自动生成代码,并直接运行,从而大大提高了软件生成的效率和质量。 421 | 422 | 而实时生成技术是一种借助人工智能技术让计算机自动生成代码,并直接运行的方法,大大提高了软件生成的效率和质量。实现实时软件生成的一种方式是 Prompt 编程,可以将自然语言转化为直接运行的软件,而无需生成中间的一次性过渡代码。 423 | 424 | ## 引子 425 | 426 | 从 2019 年,写了那篇《[**无代码编程](**[https://zhuanlan.zhihu.com/p/61288928](https://zhuanlan.zhihu.com/p/61288928))》开始,我也一直在思考,诸如于 [2021 年]([https://www.phodal.com/blog/frontend-strategy-2021/](https://www.phodal.com/blog/frontend-strategy-2021/)) 和 [2022 年]([https://www.phodal.com/blog/frontend-strategy-2023/](https://www.phodal.com/blog/frontend-strategy-2023/)) 的前端趋势总结。 427 | 428 | 先前,我并不看好当前的低代码/无代码方案,先我们来思考一下这个过程: 429 | 430 | 第一步,业务需求需要在人类脑海里转换一遍,转换为程序逻辑。 431 | 432 | 第二步,专业人员(如程序员)将这些逻辑转换到无代码系统中,生成应用并直接部署。 433 | 434 | 第三步,如果这个专业人员是程序员,那么新的需要变更时,他可能直接去修改源码。 435 | 436 | 而随着 ChatGPT 的进一步普及,你会发现你可以很容易将需求转化为**形式化格式**,进而转化而软件,从而使得软件开发的效率和速度大大提升。这种一次性代码的新型软件工程方法就是**实时软件生成**,便可以进入真正的 “**无代码**” 时代。 437 | 438 | ## Prompt 编程:真正的无代码 439 | 440 | - Prompt 编程是实现实时软件生成的一种方式,可以将自然语言转化为直接运行的软件,而无需生成中间的一次性过渡代码。每当需要运行程序时,只需要再运行一下 prompt 或者**触发词**,就可以直接运行起某个软件。 441 | 442 | 我们尝试从编写 Prompt 的经验里,归纳出一套适合于 Prompt 编程的逻辑,方便于大家理解。Prompt 编程有以下特性: 443 | 444 | 1)从需求到代码的直接转换; 445 | 446 | 2)代码只是临时产物; 447 | 448 | 3)次序化的分解框架。 449 | 450 | 这种一次性代码的新型软件工程方法可以进入真正的 “无代码” 时代。 451 | 452 | ### Prompt 编程特性 1:从需求到代码的直接转换 453 | 454 | 用户只需要简单输入自己的需求就能够生成符合要求的软件,无需具备专业的编程技能。示例: 455 | 456 | ```yaml 457 | 我们来玩一个 mul 游戏,当我说 mul 开头,并输入数字时,你应该计算结果。示例:"""当我输入:mul 4,你应该输出:16""" 458 | ``` 459 | 460 | 在这个游戏里,我们使用: 461 | 462 | 1. **触发词**。mul 作为街头暗号,告诉程序你要按这个步骤走。类似于编程里的函数名。 463 | 2. 示例作为**输入和输出**。即预期输入某个结果时,输出我们想要的结果。 464 | 465 | 而在其实,已经是一个函数该有的样子:**输入、输出、关系**。值得注意的是,在简单的问题下,只要我们给定了示例,那么 AI 就会根据示例去计算输入和输出,不关注中间的处理逻辑。 466 | 467 | 接下来,再看一个隐含性编程的示例,依旧我们还是玩个游戏: 468 | 469 | ```yaml 470 | 我们能玩一个名为 kfc 的谜语创作游戏,当我说 "kfc",你写一个谜题,要求: 471 | 472 | 1. 不少于 200 字 473 | 2. 谜题不能出现肯德基和星期四 474 | 3. 正文可以夹杂小语种语言,如 """他说:Ciao""" 475 | 4. 谜底必须是 ###原来今天是肯德基疯狂星期四!!!### 476 | 477 | 格式类似于: 478 | 479 | """ 480 | ... 481 | """ 482 | ``` 483 | 484 | 这个例子已经相当的自由,我们也不关心中间的处理逻辑,只关注于结果。 485 | 486 | ### Prompt 编程特性 2:代码只是临时产物 487 | 488 | 还记得在 [Prompt 编写模式]([https://github.com/phodal/prompt-patterns](https://github.com/phodal/prompt-patterns)) 中的 `wula` 游的例子吗?在 wula 游戏里,用户只需要输入问题,ChatGPT 便会自动给出代码、代码解释和文章。诸如于:`wula: 头共10,足共28,鸡兔各几只?`,那么 AI 便会开始自动开始二次编程: 489 | 490 | ```yaml 491 | 这是一个鸡兔同笼问题,题目给出了头的数量和足的数量,要求求出鸡和兔的数量。通常解决这个问题的方法是,假设鸡和兔的数量分别为 x 和 y,那么可以列出如下方程组: 492 | 493 | x + y = 10 494 | 2x + 4y = 28 495 | 496 | 解方程组可以得到 x=4,y=6,即鸡有4只,兔有6只。 497 | 鸡兔同笼问题的 JavaScript 代码实现 498 | 499 | // 计算鸡兔数量的函数 500 | function calcAnimals(heads, legs) { 501 | ..... 502 | ``` 503 | 504 | 在传统的体系之下,我们要关注于中间生成的 **JavaScript 代码**、**代码能不能运行**等等,所以我们在设计 wula 的时候,要求了: 505 | 506 | ```yaml 507 | 508 | 第二步. 代码编写:你需要用 JavaScript 编写解决这个问题的代码,并输出对应的代码,并介绍一下你的代码(不少于 200 字)。 509 | 510 | 第三步. 代码执行:你需要作为 JavaScript Console 执行第二步写的代码,如果没有给出测试数据,你需要自己随机生成测试数据,并将这些数据输入到代码中进行计算。 511 | ``` 512 | 513 | 但是,回到第一个例子里,我们并不需要 JavaScript 代码,我们不需要任何代码。ChatGPT 可以为我们生成这部分的程序!!! 514 | 515 | 唯一限制我们的是: 516 | 517 | 1. ChatGPT 的上下文能力 518 | 2. 我们的 Prompt 编写能力 519 | 520 | 而在复杂的场景之下,Prompt 编写需要足够的形式化,才能让机器理解,也因此,我才把它称为 Prompt 编程。 521 | 522 | ### Prompt 编程特性 3:次序化的分解框架 523 | 524 | 仅就当前而言 AI 的上下文能力,限制了 AI 解决复杂问题的能力。所以,它无法**一次性解决**复杂、中大型的问题,甚至于小型项目都存在一定的难度。同样的,对于人类来说,也存在这样的局限性,只是人类的问题是**领域知识有限**。 525 | 526 | 步骤详细见:[DDD Sample]([https://github.com/phodal/prompt-patterns/blob/master/ddd.sample.md](https://github.com/phodal/prompt-patterns/blob/master/ddd.sample.md)) 527 | 528 | 所以,作为编程核心的人类大脑,需要为机器设计一下工序,即每一步应该怎么做。所以,这个时候,就回到了 **DDD**(领域驱动设计)擅长的问题: 529 | 530 | ```yaml 531 | 我们来定义一下 DDD 游戏的步骤,一共有 6 个步骤,步骤如下: 532 | 533 | """ 534 | 第一步. 拆解场景。分析特定领域的所有商业活动,并将其拆解出每个场景。 535 | 第二步. 场景过程分析。选定一个场景,并使用 "{名词}已{动词}" 的形式描述过程中所有发生的事件,其中的名词是过程中的实体,其中的动词是实体相关的行为。 536 | 第三步. 针对场景建模。基于统一语言和拆解出的场景进行建模,以实现 DDD 设计与代码实现的双向绑定。 537 | …… 538 | """ 539 | ``` 540 | 541 | 对于每一步,我们只要限定好我们的输出(Output),那么在给定输入的情况下,AI 就能给出我们想要的(也有可能跑偏了)结果: 542 | 543 | ```yaml 544 | ddd 第二步:场景过程分析。下面是每个场景的过程分析: 545 | 用户注册和登录 546 | 用户注册:用户填写注册信息,系统验证信息合法性,生成用户账户并保存。 547 | 用户登录:用户输入账户名和密码,系统验证账户密码,登录成功后跳转到用户中心。 548 | 549 | 商品展示和搜索 550 | 商品列表展示:系统从数据库中获取商品列表并展示,用户可以进行商品分类和排序。 551 | 商品搜索:用户输入关键词进行商品搜索,系统根据关键词从数据库中获取商品列表并展示。 552 | …… 553 | ``` 554 | 555 | 在这时,我们就可以引导 AI 生成到 API 粒度: 556 | 557 | | API名称 | 请求方法 | 请求路径 | 请求体 | 响应体 | 描述 | 558 | | --- | --- | --- | --- | --- | --- | 559 | | 创建商品 | POST | /api/products | 商品信息 | 创建的商品信息 | 创建一个新的商品 | 560 | | 获取商品列表 | GET | /api/products | 无 | 商品列表信息 | 获取所有的商品列表 | 561 | | 获取单个商品信息 | GET | /api/products/{id} | 无 | 单个商品信息 | 根据商品 ID 获取单个商品信息 | 562 | | 更新商品信息 | PUT | /api/products/{id} | 更新的商品信息 | 更新后的商品信息 | 根据商品 ID 更新商品信息 | 563 | | 删除商品 | DELETE | /api/products/{id} | 无 | 无 | 根据商品 ID 删除商品信息 | 564 | 565 | 也可以生成代码,甚至于在上下文足够强大的时候,也是能够直接运行和自动优化的。 566 | 567 | ### Prompt 编程特性 4:语言即语言 568 | 569 | DSL(领域特定语言)是指专门针对某个特定领域的语言,通常具有严格定义的语法和规则,并且可以用来描述该领域中的问题、概念、过程和数据等。而经过形式化处理的自然语言可以被视为一种 DSL,因为它们具有明确定义的语法和规则,可以用来描述特定领域中的问题、概念、过程和数据等。 570 | 571 | 所以,简单来说如果我们限定了**输入和输出的格式**,那么我们的自然语言也是一种 DSL。这就意味着,限制我们进行次序化的关键就是形式化的抽象。 572 | 573 | 而,我们也可以通过编写 Prompt 来生成新的 DSL:`帮我设计一个 DSL,用来写函数` 574 | 575 | ```yaml 576 | 好的,以下是一个简单的DSL设计,可以用来写函数: 577 | 578 | 1. 函数定义 579 | 在这个段落中,定义一个函数,包括函数名、参数和函数体等。 580 | ``` 581 | 函数: 582 | 函数名: 583 | 描述函数的名称 584 | 参数: 585 | 参数1: 586 | 描述参数1的名称和类型 587 | 参数2: 588 | 描述参数2的名称和类型 589 | ... 590 | 函数体: 591 | 描述函数的实现细节 592 | ``` 593 | 594 | 2.。。。 595 | ``` 596 | 597 | 简单来说,我们可以通过 Prompt : 598 | 599 | 1. 借用 Prompt 设计自然语言式的 DSL 600 | 2. 将自然语言式的 DSL 融入 Prompt 601 | 3. 使用次序化的方式来实现 Prompt 自我编程 602 | 603 | 进而,我们就得到了一个可以自举的 Prompt。 604 | 605 | ## Prompt 编程 Demo:引导 ChatGPT 创建语言与建模 606 | 607 | 说了,这么多我们来看一个结合我之前设计的 DSL 示例,即 [Fklang](https://github.com/feakin/fklang)。 608 | 609 | ### 阶段一:让 ChatGPT 与你学 DDD 610 | 611 | 在 Fklang 中,我们采用下面的形式来表示 ContextMap: 612 | 613 | ```yaml 614 | ContextMap TicketBooking { 615 | Reservation -> Cinema; 616 | Reservation -> Movie; 617 | Reservation -> User; 618 | } 619 | ``` 620 | 621 | 但是,自己设计这样的 DSL 太累了,可以让 ChatGPT 来设计。在你开始之前,需要确认一下 ChatGPT 中的 DDD、DSL、事件风暴等的概念是否与你理解的一致。 622 | 623 | 第一个问题:`设计一个 DSL 来表示 DDD 里的 Context Map 。` 624 | 625 | ```yaml 626 | ContextMap: 627 | Subdomain { Name: [subdomain_name] } 628 | [CollaboratesWith: [other_subdomain_name], ...] 629 | [ConformistWith: [other_subdomain_name], ...] 630 | [Antagonizes: [other_subdomain_name], ...] 631 | ... 632 | ``` 633 | 634 | 第二个问题:用这个 ContextMap DSL 对在线电影订票系统建模。对于其它问题也是相似的。 635 | 636 | 第三个问题:设计一个 DSL 来描述事件风暴的 事件建模 吗? 637 | 638 | 第四个问题:能用 事件建模的 DSL 来表示用户购票的流程吗? 639 | 640 | 一旦,我们觉得设计跑歪了,就可以重新设计。如果下是生成的复杂的 DSL: 641 | 642 | ```yaml 643 | EventStorming: 644 | Domain { Name: "电影订票系统" } 645 | Event { Name: "用户提交订单" } 646 | Triggered By: "用户选择电影、场次、座位,确认订单" 647 | Description: "用户提交订单,包括所选电影、场次、座位等信息" 648 | Actors: ["用户"] 649 | Action: "将用户提交的订单信息保存到订单数据库中" 650 | Outcome: "订单状态被标记为已提交" 651 | ``` 652 | 653 | 第五个问题…… 654 | 655 | 剩下的你都会了,不会的,可以问 ChatGPT。 656 | 657 | ### 阶段二:完整设计 + DSL 生成 658 | 659 | 第一个问题:能总结一下,我们这里用 DDD 设计 购票系统到落地代码的过程吗? 660 | 661 | 第二个问题:能为每个过程,设计一个合理的 DSL 吗,并展示他们? 662 | 663 | 展示一部分神奇的 DSL: 664 | 665 | ```yaml 666 | generate java-code from-domain-model 667 | target-package: com.example.movieticket.order 668 | source-model: order-domain-model 669 | 670 | service-mapper 订单服务映射 671 | map-method: 查询电影 672 | to-class: MovieRepository 673 | to-method: findBySchedule 674 | 675 | map-method: 查询座位 676 | to-class: SeatRepository 677 | to-method: findByRowAndColumnAndStatus 678 | ``` 679 | 680 | 现在,有意思的地方来,有了上面的一系列 DSL 之后,我们就可以接入到代码系统中。 681 | 682 | ### 阶段三:代码生成与低代码 683 | 684 | 只要 ChatGPT 上下文能力足够强壮,或者支持 LoRA 式的插件模式,我们就能实现从需要到现有的任何系统中。 685 | 686 | 第一个问题:为电影订票系统设计一个 DDD 风格 Java 工程的代码目录结构。 687 | 688 | 第二个问题:结合 Spring 设计一下购票流程的 RESTful API 689 | 690 | …… 691 | 692 | 有点懒,就先这样吧。后面的部分,就可以结合 GitHub Copilot 去实现了。 693 | 694 | ### 小结 695 | 696 | 结合 Prompt 编程,低代码到了一定的成熟度,我们就可以发现更好玩的东西:实时的软件生成 697 | 698 | ## 实时的软件生成:自然语言即 Prompt,Prompt 即代码 699 | 700 | 实时软件生成核心思想是,通过算法和机器学习来自动生成代码,让计算机根据用户需求,快速生成符合要求的软件。这种技术能够自动化完成代码的编写、测试、发布等流程,大大缩短软件开发周期,降低了开发成本,提高了开发效率。 701 | 702 | 当我们想构建这样一软件用于实时生成软件时,它需要具备以下的特征: 703 | 704 | ### 特征 1:自然语言即语言,语言即软件 705 | 706 | 即如上面的 Prompt 编程所述,可以通过设定层层转换,直接将需求直接转换为软件。 707 | 708 | ### 特征 2:生成式的软件架构 709 | 710 | 软件本身不需要架构,架构是 AI 自动生成和调整的。 711 | 712 | ### 特征 3:自底向上生成 713 | 714 | 现有的语言本身需要 REPL 环境、操作系统、编程语言、语言底层库、库等一系列软件,对于 AI 而言,他能学习这些通用能力,自操作系统底层一样,逐步往上构建出软件的运行环境,以及软件本身 。 715 | 716 | ## 当前的挑战 717 | 718 | 对于当前而言,我们还存在些挑战: 719 | 720 | - 现行组织架构难以支撑内部 ChatGPT。如内部权限、架构等的管理 721 | - 通用大模型无法满足。领域特定能力有限,需要构建 LoRA 以更好的支持。 722 | - 细节能力实现较差。在编程实现上,远不如 GitHub Copilot 723 | 724 | 当然了,受限于个人能力,可能还有别的一些挑战。 725 | 726 | ## 总结 727 | 728 | 本文介绍了 Prompt 编程的特点和实时软件生成的核心思想。Prompt 编程是一种次序化的分解框架,可以让机器根据用户需求自动生成代码。实时软件生成技术可以大大提高软件生成的效率和质量,同时也让软件开发变得更加简单。然而,现有组织架构难以支撑内部 ChatGPT,上下文能力有限,细节能力实现较差,这些都是实现 Prompt 编程和实时软件生成的难点。 729 | 730 | 731 | 732 | # 如何利用好 AIGC ?从 AI 绘画的演进与 ChatGPT 现状出发 733 | 734 | PS:就本文的结论而言,我相信你已经或多或少的有所体会了。也因此,本文更多的是展现一个思考的过程,而不是一个纯粹的结论。 735 | 736 | > AIGC 是什么?它是指通过机器学习、自然语言处理等人工智能技术,让计算机自动生成文字、图像、音频、视频等各种类型的内容。它能够帮助企业和个人降低创作成本、提高生产效率、增强创意输出等。 737 | 738 | 开始之前,先说结论:哪怕仅就当前的 AIGC 成熟度,我们都明白:**人类应该去做更高价值的事**,也因此在当前的工作模式上呈现的是,三步区: 739 | 740 | - 蓝图设计(人类)。 负责创意性的思考与设计工作,如场景、软件架构等。 741 | - 机械化生成(机器)。将创意借助工具或者人转换为 Prompt,然后交给 AIGC 生成。 742 | - 细节修复(人类)。对于 AIGC 生成不合理、不适宜法律法规等的地方,进行修改。 743 | 744 | 因此,对于诸多**通用的大众领域**,人类这样的碳基生物而言,如果不能从思维框架来驾驭 AIGC。而对于细分领域来说,只要在足够卷的情况下,AIGC 也会给予我们更多的惊喜。 745 | 746 | 与 ChatGPT 的黑盒相比,类似于 Stable Diffusion 白盒开源,可以让我们更了解 Prompt 应该如何编写?如何更好地利用 AIGC。所以,本文的第一部分就是从现有的 AI 绘画的变化来看,如何更好的利用 AIGC。而第二部分则是结合 ChatGPT 的现状来看,如何更好的利用 AIGC。 747 | 748 | ## 如何构建高质量的 AI 图形:精准控线 + 个人模型 749 | 750 | 注意:请在取得授权的情况下,进行个人模型的练习,避免侵犯个人肖像权。 751 | 752 | 我们的例子,依旧是基于 Stable Diffusion,开源模型与开源软件才是人类的未来。太长不看图: 753 | 754 | ![Stable Diffusion 概览](images/stable-diffusion-overview.png) 755 | 756 | 对于一个绘画过程来说,我们可以通过如下的方式,逐步引导绘图应用: 757 | 758 | 1. 编写详细的 Negative Prompt,以淘汰不合理的生成内容。 759 | 2. ControlNet 作为基准骨架,引导最终效果,过滤不合理的图像。 760 | 3. 训练与融合个人模型,以构建领域特定的用途。 761 | 762 | 总的来说:过滤不合理的图像,就能提升生成质量。我们就可以,设计出初步符合需求(在不看 AI 画出来的手情况下)的框架性方案。 763 | 764 | ### 严格化验收条件:Negative Prompt 765 | 766 | > Negative Prompt 会将模型的目标从一般的高概率生成样本转换为生成与负向提示不匹配的低概率样本,从而迫使模型更加关注图像的细节和特征,提高其生成的图像的质量和逼真度。 767 | 768 | 我们的故事依旧可以从:`微笑的女孩探出火车窗外` 故事开开始,简单地翻译成英语,来作为我们的 prompt:`smiling girl leaning out the train window`。在只有 Prompt 的情况下,会生成各种奇怪的图形,所以我们需要添加 Negative Prompt。 769 | 770 | 所以在 Stable Diffusion 里,我们就可以通过它来提升质量: 771 | 772 | ![Negative](images/stable-diffusion-with-negative.jpeg) 773 | 774 | 而从结果来看,模型与我们想要的图,还存在一定的距离。对于 ChatGPT 也是类似的,所以我们需要相似的模式:诸如于 `写一个不超过 800 字的作文`,又或者是 `写一个作文,要求如下:1. 不超过 800 字`。 775 | 776 | ### 构架蓝图:ControlNet 精准控线 777 | 778 | > ControlNet 是一种神经网络结构,旨在通过添加额外条件来控制扩散模型。在特定场景下,ControlNet被用于生成类似建模效果(法线贴图)的中间图和相关的图像。这种技术可以被应用于多个领域,如骨骼绑定、精准控线、线稿上色、深度图结构透视精准重绘等。 779 | 780 | 简单来说,在人像领域,通过手绘特定的姿势、从照片中解析等方式,创建一个人物姿势,绘制出来的图便采用类似的格式。如下图所示: 781 | 782 | ![ControlNet](images/stable-diffusion-with-controlnet.jpeg) 783 | 784 | 从形状和生成的效果来说,除了脸部等细节不是特定令人满意之外,基本能满足使用的需求。而在更好地机器加持下,我们能得到更高分辨率,就可以靠人工修复脸部的问题。 785 | 786 | 而在写作场景之下,只要我们给了 ChatGPT 大纲,那么他就能帮助我们生成文章。唯一的问题是,我们不能添加上自己的写作风格、历史作品,否则我们可以更加容易使用这个作品。而在那之前,我们需要思考什么是我们的作品?什么是我们的风格? 787 | 788 | ### 轻量小模型:DreamBooth 个人模型与风格化 789 | 790 | 注意:请在取得授权的情况下,进行模型的练习与作品创作。除了 DreamBootb 还有其他工具可使用,但由于时间限制,我就没有展开进一步研究。 791 | 792 | > 融合个人模型是指将训练后的个人风格和特点融入到 AI 绘画模型中,使其生成的画作更贴近个人风格和需求,提高生成画作的个性化和定制化。 793 | 794 | 诸如在 Stable Diffusion 中,我们可以用自己的头像结合 DreamBooth 等工具训练,以得到一个融合自己风格的模型。在二次元世界里,最常被使用的是 "个人头像",以用于生成动漫或者 idol。效果如下: 795 | 796 | ![DreamBooth](images/stable-diffusion-with-controlnet-dreambooth.jpeg) 797 | 798 | PS:在取得某人同意的情况下,放一张动画化的结果(当然了,取的是不像本人的照片): 799 | 800 | ![Final](images/stable-diffusion-hug8217.jpeg) 801 | 802 | 在 Stable Diffusion 的模型尝试之后,我们可以发现:云 GPU + 模型可插件化 + 算力要求逐步下降之后,会使得个人的小模型会变成越来越普及,所以我训练的模型也只在云上跑了几分钟。 803 | 804 | ### 完善与细化:局部绘制 —— InPaint 的手部修复 805 | 806 | 众所周知,当前的 AI 绘图还存在诸多细节问题,比如手、脚等,因此需要一定的人类修复画师。又有一部分人自此成为了服务于 AI 的打工人。如下是使用 InPaint 修复手部时生产出来的,人类画师就需要从中挑选出合适的照片: 807 | 808 | ![](images/try-fix-hands.jpeg) 809 | 810 | 最后,总算,先找到一张可以凑合着交差的: 811 | 812 | ![](images/hand-final-result.jpeg) 813 | 814 | 除此,还可以选择对图形进行裁剪,或者使用 Photoshop 等工具进行重绘等。 815 | 816 | ### 小小的总结:严格化验收条件 + 构架蓝图 + 轻量小模型 + 完善与细化 817 | 818 | 要想清晰的表达自己的需求,我们需要: 819 | 820 | - **严格化的验收条件**,即通过 Prompt 描写需求,通过 Negative Prompt 排除异常 821 | - **表达构架蓝图**,即通过 ControlNet 创建所需要的内容骨架,控制 822 | - **轻量的领域小模型**,即通过 DreamBooth,结合灵活的架构模型,来丰富 AI 模型。 823 | - **完善与细化**,即通过 InPaint 对有缺陷的部分进行修复,如局部绘制。 824 | 825 | 当然了,在 Stable Diffusion 里,还可以通过 Inpaint 等方式进行修复。 826 | 827 | ## 个人 AI 策略:构架 + 磨炼 + 小模型 828 | 829 | 在先前的两篇文章里,我们已经不断地在探索适合于个人的 AI 策略: 830 | 831 | - 《[基于编程、绘画、写作的 AI 探索与总结](https://github.com/phodal/ai-research/)》 832 | - 《[Prompt 编写模式:如何将思维框架赋予机器](https://github.com/phodal/prompt-patterns)》。 833 | 834 | 对于我来说,我的 AI 策略大致是: 835 | 836 | - 强化构架能力。强化架构设计、软件设计、抽象设计等。 837 | - 构建小模型。在未来合适的时候,诸如于合适的开源 GPT 等。 838 | - 探索与磨炼技巧。探索更多的 AI 解决方案,如 Notion AI 等;持续探索 Prompt 模式等。 839 | 840 | 对于修复与完善来说,由于 AI 本身是无法达到这么精细的,所以我的想法是**持续构建小工具**。 841 | 842 | ### 策略 0:拥抱变化 843 | 844 | 首先,我们要理解 AIGC 真的带来变化,尽管现今的 AI 并不能完整的代替我们,但是已经能大大提升效率。 845 | 846 | 作为一个知名的 “开源挖抗” 作者,在我使用 GitHub Copilot 的初期,觉得这 TM(Trademark) 就是一个智障。而我适应了:**如何与智障沟通**之后,我悟了,我才是 ”智障“ —— 只有理解机器的 API 与工作方式,才能利用好机器。 847 | 848 | ### 策略 1:强化构架能力 849 | 850 | AI 工具无法替代个人的感性思考和直觉,所以个人在设计过程是非常重要性的。 851 | 852 | 强化设计是指通过 AI 技术释放个人的创造力,帮助个人在设计中实现更高效、更优质的创造成果。这个策略的核心在于使用 AIGC 工具来自动生成大量的创意元素,例如图像、文字、音频等,从而将创造的效率提高到一个新的水平。 853 | 854 | 在实践中,个人可以通过以下方式强化自己的构架能力: 855 | 856 | - 持续学习新的设计理念和创意方法,不断拓展自己的知识面和视野。例如,了解一些新兴的设计趋势,学习如何将传统的设计元素与现代的技术手段相结合,从而创造出更有创意和张力的作品。 857 | - 坚持思考和探索,不断挑战自己的思维方式和想象力。通过不断思考和实践,将自己的思维方式和想象力逐渐转化为可操作的设计构架,从而在 AIGC 工具的帮助下实现更高效的创造。 858 | 859 | 除此,我们还应该熟练掌握使用 AIGC 工具的方法,尤其是一些高级的特性。例如,对于文本生成任务,可以使用 Negative Prompt 等技巧提高生成的质量;对于图像生成任务,则可以使用 ControlNet 等技术实现更精准的控制。 860 | 861 | ### 策略 2:构建领域小模型 862 | 863 | PS:此处需要持续寻找合适的工具,就当前而言,只有 AI 绘图领域是**相对比较成熟**(可用)的。 864 | 865 | 每个人的知识面是不同的,知识体系也是不同的。因此,我们不能期望一个通用的大模型能够满足所有人的需求。相反,我们应该尝试构建适合自己领域的小模型。通过选择合适的数据集、算法和网络结构,我们可以快速训练出一个专门用于解决自己问题的小型模型。这个模型不需要太复杂,只需要满足自己的需求即可。这样可以提高模型的效率和准确度,并且减少训练时间和计算资源的消耗。 866 | 867 | 例如,对于一个博客作者来说,可以使用 GPT-3 来帮助自己快速生成博客文章的开头或结尾段落,也可以通过训练自己的小模型,生成符合自己风格的文章内容。对于一名摄影师来说,可以通过构建小模型来辅助自己完成相册的排版、图像剪辑等工作。 868 | 869 | 所以,对于而言,我有 900+ 的博客,从中训练出来的写作风格,大概是能像我的 —— 也存在不同时机的风格不一样的问题。 870 | 871 | ### 策略 3:探索与磨炼技巧 872 | 873 | 对于探索而言,也是最近才有时间和精力去探索,加入了公司的相关讨论群后,也获得了更多的输入。只是对于我来说,更多的是想把 AI 融入到日常事务中,以提升工作效率,所以也不想去创建微信群。 874 | 875 | 对于技巧来说,其实更多的是要去理解 AI 是如何 work 的,并将这种模式整合到自己的思维方式里。 876 | 877 | 除此,我们还可以思考如何将思维框架赋予 AI,以完成更闭环的工作。诸如于 GitHub Copilot 可以帮我们写代码,但是无法从宏观上理解业务问题、整体性的架构问题,生成的代码只是从局部考虑的。因此,我们需要通过不断地磨炼自己的技能和能力,来提高自己的综合素质和创造力。如我正在持续丰富的 [phodal/prompt-patterns](https://github.com/phodal/prompt-patterns) 也算是我的磨炼技巧。 878 | 879 | ## 小结 880 | 881 | 最后,再让 AI 总结一下四个策略: 882 | 883 | 1. 拥抱变化,尽管人工智能并不能完全代替人类,但它已经能够大大提高效率。 884 | 2. 强化构架能力,因为人工智能工具无法代替个人的感性思考和直觉。 885 | 3. 构建领域小模型,可以快速训练出一个专门用于解决自己问题的小型模型。 886 | 4. 探索与磨炼技巧,探索 AI 能力并持续构建小工具,来修复和完善自己的 AI 增强系统。 887 | 888 | 结论,AI 在短期内还是智障,但是已经可以大大提升效率了。 889 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | remote_theme: phodal/mifa-jekyll 2 | -------------------------------------------------------------------------------- /chatgpt/click-prompt.md: -------------------------------------------------------------------------------- 1 | # ClickPrompt 2 | 3 | 我们是 ClickPrompt 开源项目的贡献者,我们想让你为 ClickPrompt 添加一些新的功能。开始之前请阅读一下这些资料: 4 | 5 | - ClickPrompt 是一款专为 Prompt 编写者设计的工具,它支持多种基于 Prompt 的 AI 应用,例如 Stable Diffusion、ChatGPT 和 GitHub Copilot 等。 使用 ClickPrompt,您可以轻松地查看、分享和一键运行这些模型,同时提供在线的 Prompt 生成器,使用户能够根据自己的需求轻松创建符合要求的 Prompt,并与其他人分享。 6 | - ClickPrompt 包含了些页面组件:chatgpt、chatgpt-general、chatgpt-generator-cot、chatgpt-interactive-game、chatgpt-prompt-role-play、chatgpt-samples、chatgpt-startling-by-each-step、github-copilot-samples、resources、stable-diffusion-examples、stable-diffusion-generator 7 | - ClickPrompt 使用 Next.js、React、Chakra UI、Tailwind 等作为主要的开发框架,使用 Planetscale 作为数据库。 8 | 9 | 10 | 现在,我们想让你:结合 ClickPrompt 的功能与 reactour 为 ClickPrompt 的首页,添加一个 Tour guide 的功能 11 | 12 | 13 | 以下是首页的主要代码: 14 | 15 | ```` 16 | 17 | 18 | {/* https://github.com/vercel/next.js/issues/42292 */} 19 | {/* @ts-expect-error Async Server Component */} 20 | 21 | 22 | {children} 23 | 24 | 25 |
26 | 31 | Powered by 32 | Vercel Logo 38 | 39 |
40 | 41 | 42 | ``` 43 | 44 | 45 | 应该如何修改?直接给个示例? 46 | -------------------------------------------------------------------------------- /chatgpt/design-system.md: -------------------------------------------------------------------------------- 1 | # Q1 2 | 3 | 我想通过与 ChatGPT 来设计一个软件系统,我应该问哪些问题呢,能给个详细示例吗? 4 | 5 | 当你想要通过与 ChatGPT 来设计一个软件系统时,你可以问以下问题来帮助你进行设计和规划。 6 | 7 | 目标和需求: 8 | 9 | 我们希望这个软件系统能够做什么?它有哪些基本功能和特性? 10 | 它需要满足哪些需求,包括用户需求和业务需求? 11 | 它需要解决哪些问题?它可以帮助我们提高效率、降低成本、提高质量等等。 12 | 13 | 用户群体: 14 | 15 | 软件系统的主要用户是谁?他们的需求和使用习惯是什么? 16 | 我们需要为这些用户提供什么样的用户体验和交互方式? 17 | 我们需要针对不同的用户群体提供不同的功能或服务吗? 18 | 19 | 数据流和数据结构: 20 | 21 | 软件系统需要处理哪些数据?这些数据如何被收集、存储、处理和呈现? 22 | 有哪些数据库或其他数据存储设施可以使用?我们需要使用什么类型的数据库和数据存储方案? 23 | 数据的格式和结构如何? 24 | 25 | 系统架构: 26 | 27 | 我们需要选择什么样的架构来支持这个软件系统?如何将这个架构应用到我们的系统设计中? 28 | 我们需要选择什么样的技术组件和技术框架来支持我们的软件系统? 29 | 我们如何将这些组件和框架整合在一起,以实现一个高效、可扩展、易维护的系统? 30 | 31 | 测试和质量保证: 32 | 33 | 我们需要什么样的测试策略和工具来确保软件系统的质量和可靠性? 34 | 我们需要进行哪些类型的测试,包括单元测试、集成测试、系统测试等? 35 | 我们如何进行测试,并如何分析测试结果? 36 | 37 | 部署和运维: 38 | 39 | 我们需要在哪些环境中部署软件系统?如何进行部署? 40 | 我们需要选择什么样的运维策略和工具来确保软件系统的可用性、可靠性和安全性? 41 | 我们需要如何监控和维护软件系统? 42 | 43 | 成本和资源: 44 | 45 | 设计和开发一个软件系统需要哪些资源?包括人力、时间、物力等等。 46 | 我们需要考虑哪些成本因素,如开发成本、运行成本等? 47 | 我们如何优化系统的开发和运行成本? 48 | 49 | 其他方面: 50 | 51 | 软件系统的可维护性、可扩展性、安全性、隐私保护等等。 52 | 我们需要采取什么措施来保护用户数据和隐私? 53 | 我们需要遵循什么样的安全标准和最佳实践来确保系统的安全性? 54 | 我们如何提高系统的可维护性和可扩展性,以便能够支持未来的增长和扩展? 55 | 我们如何实现系统的自动化管理和部署,以提高效率和可靠性? 56 | 我们需要制定什么样的开发流程和工作流程来确保软件开发的质量和效率? 57 | 58 | 以上是一些可能需要考虑的问题,你可以根据具体的情况自行扩展或缩减。在与 ChatGPT 进行交流时,你可以使用自然语言来表达你的需求和问题,ChatGPT 将会根据你提供的信息和背景知识来给出相应的建议和解决方案。同时,你也可以通过与 ChatGPT 进行对话来进一步深入探讨和规划软件系统的设计和开发。 59 | 60 | 61 | # Q2 62 | 63 | Q1: 帮我设计一个 JSON Schema 来表达一个系统的软件设计 64 | Q2: 帮我设计一个 Yaml 来表达一个系统的软件设计 65 | Q3: 帮我设计一个 Yaml 来表示一个系统的处理流程 66 | Q4: 帮我设计一个 DSL 来表示一个系统的处理流程 67 | Q5: 在你刚设计的 DSL 里,整合编程相关的要素,诸如于 "Class={}",并重新设计: 68 | 69 | ```javascript 70 | process MyProcess { 71 | description = "A process for handling customer orders" 72 | 73 | step "Receive Order" { 74 | description = "Receives an order from the customer" 75 | type = "manual" 76 | owner = "Customer Service" 77 | } 78 | 79 | step "Check Inventory" { 80 | description = "Checks if there is sufficient inventory to fulfill the order" 81 | type = "automated" 82 | owner = "Inventory Management" 83 | depends_on = ["Receive Order"] 84 | } 85 | 86 | step "Process Payment" { 87 | description = "Processes payment for the order" 88 | type = "automated" 89 | owner = "Payment Gateway" 90 | depends_on = ["Receive Order", "Check Inventory"] 91 | } 92 | 93 | step "Fulfill Order" { 94 | description = "Fulfills the order and ships it to the customer" 95 | type = "automated" 96 | owner = "Warehouse Management" 97 | depends_on = ["Receive Order", "Check Inventory", "Process Payment"] 98 | } 99 | } 100 | ``` 101 | 102 | 103 | 帮我设计一个 DSL 来表示一个系统,要求: 104 | 105 | 1. 使用领域驱动设计的思想。 106 | 2. 能体现出业务信息。 107 | 3. 包含编程相关的元素,如类、包、方法等。 108 | 109 | 只返回这个 DSL,并在 DSL 中添加注释。 110 | 111 | ```javascript 112 | //定义一个处理流程,包含多个步骤 113 | Process { 114 | name: String, //流程名称 115 | steps: List[Step], //步骤列表 116 | entryPoint: Step //入口步骤 117 | } 118 | 119 | //定义一个步骤,包含输入输出和执行代码 120 | Step { 121 | name: String, //步骤名称 122 | inputs: List[Input], //输入列表 123 | outputs: List[Output], //输出列表 124 | code: Code //执行代码 125 | } 126 | 127 | //定义一个输入,包含名称和数据类型 128 | Input { 129 | name: String, //输入名称 130 | dataType: DataType //数据类型 131 | } 132 | 133 | //定义一个输出,包含名称和数据类型 134 | Output { 135 | name: String, //输出名称 136 | dataType: DataType //数据类型 137 | } 138 | 139 | //定义执行代码的接口 140 | Code { 141 | execute: (inputs: Map[String, Any]) => Map[String, Any] //执行代码的方法,输入和输出均为键值对 142 | } 143 | 144 | //定义数据类型,包括基本类型和自定义类型 145 | DataType { 146 | String, 147 | Int, 148 | Double, 149 | Boolean, 150 | CustomType(name: String) //自定义类型 151 | } 152 | 153 | //示例代码:创建一个处理流程,并添加两个步骤 154 | val process = Process( 155 | name = "My Process", 156 | steps = List( 157 | Step( 158 | name = "Step 1", 159 | inputs = List( 160 | Input("input1", DataType.String), 161 | Input("input2", DataType.Int) 162 | ), 163 | outputs = List( 164 | Output("output1", DataType.Double) 165 | ), 166 | code = MyCode1() 167 | ), 168 | Step( 169 | name = "Step 2", 170 | inputs = List( 171 | Input("input3", DataType.CustomType("MyType")), 172 | Input("input4", DataType.Boolean) 173 | ), 174 | outputs = List( 175 | Output("output2", DataType.String), 176 | Output("output3", DataType.Int) 177 | ), 178 | code = MyCode2() 179 | ) 180 | ), 181 | entryPoint = Step1 182 | ) 183 | 184 | //示例代码:自定义执行代码的实现 185 | class MyCode1 extends Code { 186 | override def execute(inputs: Map[String, Any]): Map[String, Any] = { 187 | val input1 = inputs("input1").asInstanceOf[String] 188 | val input2 = inputs("input2").asInstanceOf[Int] 189 | val result = input1.length.toDouble * input2 190 | Map("output1" -> result) 191 | } 192 | } 193 | 194 | class MyCode2 extends Code { 195 | override def execute(inputs: Map[String, Any]): Map[String, Any] = { 196 | val input3 = inputs("input3").asInstanceOf[MyType] 197 | val input4 = inputs("input4").asInstanceOf[Boolean] 198 | val output2 = if (input4) input3.name else "" 199 | val output3 = if (input4) input3.id else 0 200 | Map("output2" -> output2, "output3" -> output3) 201 | } 202 | } 203 | ``` 204 | 205 | 现在用上面的 DSL 来表示如何使用一个博客系统的使用 206 | 207 | ```javascript 208 | //定义用户实体,包含姓名、邮箱和密码 209 | Entity User { 210 | name: String, 211 | email: String, 212 | password: String 213 | } 214 | 215 | //定义博客实体,包含标题、内容和作者 216 | Entity Blog { 217 | title: String, 218 | content: String, 219 | author: User 220 | } 221 | 222 | //定义评论实体,包含内容和评论者 223 | Entity Comment { 224 | content: String, 225 | author: User 226 | } 227 | 228 | //定义处理流程 229 | Process { 230 | name: "Blog System", 231 | steps: List( 232 | Step( 233 | name: "Register", 234 | inputs: List( 235 | Input("name", DataType.String), 236 | Input("email", DataType.String), 237 | Input("password", DataType.String) 238 | ), 239 | outputs: List( 240 | Output("user", DataType.CustomType("User")) 241 | ), 242 | code: RegisterCode() 243 | ), 244 | Step( 245 | name: "Login", 246 | inputs: List( 247 | Input("email", DataType.String), 248 | Input("password", DataType.String) 249 | ), 250 | outputs: List( 251 | Output("user", DataType.CustomType("User")) 252 | ), 253 | code: LoginCode() 254 | ), 255 | Step( 256 | name: "Create Blog", 257 | inputs: List( 258 | Input("title", DataType.String), 259 | Input("content", DataType.String), 260 | Input("author", DataType.CustomType("User")) 261 | ), 262 | outputs: List( 263 | Output("blog", DataType.CustomType("Blog")) 264 | ), 265 | code: CreateBlogCode() 266 | ), 267 | Step( 268 | name: "Edit Blog", 269 | inputs: List( 270 | Input("blog", DataType.CustomType("Blog")), 271 | Input("title", DataType.String), 272 | Input("content", DataType.String), 273 | Input("author", DataType.CustomType("User")) 274 | ), 275 | outputs: List( 276 | Output("blog", DataType.CustomType("Blog")) 277 | ), 278 | code: EditBlogCode() 279 | ), 280 | Step( 281 | name: "Delete Blog", 282 | inputs: List( 283 | Input("blog", DataType.CustomType("Blog")), 284 | Input("author", DataType.CustomType("User")) 285 | ), 286 | outputs: List() 287 | code: DeleteBlogCode() 288 | ), 289 | Step( 290 | name: "Comment Blog", 291 | inputs: List( 292 | Input("blog", DataType.CustomType("Blog")), 293 | Input("content", DataType.String), 294 | Input("author", DataType.CustomType("User")) 295 | ), 296 | outputs: List( 297 | Output("comment", DataType.CustomType("Comment")) 298 | ), 299 | code: CommentBlogCode() 300 | ) 301 | ), 302 | entryPoint: Register 303 | } 304 | 305 | //自定义执行代码 306 | class RegisterCode extends Code { 307 | override def execute(inputs: Map[String, Any]): Map[String, Any] = { 308 | val name = inputs("name").asInstanceOf[String] 309 | val email = inputs("email").asInstanceOf[String] 310 | val password = inputs("password").asInstanceOf[String] 311 | val user = User(name, email, password) 312 | Map("user" -> user) 313 | } 314 | } 315 | 316 | class LoginCode extends Code { 317 | override def execute(inputs: Map[String, Any]): Map[String, Any] = { 318 | val email = inputs("email").asInstanceOf[String] 319 | val password = inputs("password").asInstanceOf[String] 320 | //根据邮箱和密码查找用户 321 | val user = findUserByEmailAndPassword(email, password) 322 | Map("user" -> user) 323 | } 324 | } 325 | 326 | class CreateBlogCode extends Code { 327 | override def execute(inputs: Map[String, Any]): Map[String, Any] = { 328 | val title = inputs("title").asInstanceOf[String] 329 | val content = inputs("content").asInstanceOf[String] 330 | val author = inputs("author").asInstanceOf[User] 331 | val blog = Blog(title, content, author) 332 | Map("blog" -> blog) 333 | } 334 | } 335 | 336 | class EditBlogCode extends Code { 337 | override def execute(inputs: Map[String, Any]): Map[String, Any] = { 338 | val blog = inputs("blog").asInstanceOf[Blog] 339 | val title = inputs("title").asInstanceOf[String] 340 | val content = inputs("content").asInstanceOf[String] 341 | val author = inputs("author").asInstanceOf[User] 342 | //检查博客是否属于该用户 343 | if (blog.author == author) { 344 | val editedBlog = Blog(title, content, author) 345 | Map("blog" -> editedBlog) 346 | } else { 347 | throw new Exception("You do not have permission to edit this blog.") 348 | } 349 | } 350 | } 351 | 352 | class DeleteBlogCode extends Code { 353 | override def execute(inputs: Map[String, Any]): Map[String, Any] = { 354 | val blog = inputs("blog").asInstanceOf[Blog] 355 | val author = inputs("author").asInstanceOf[User] 356 | //检查博客是否属于该用户 357 | if (blog.author == author) { 358 | //删除博客 359 | deleteBlog(blog) 360 | Map() 361 | } else { 362 | throw new Exception("You do not have permission to delete this blog.") 363 | } 364 | } 365 | } 366 | 367 | class CommentBlogCode extends Code { 368 | override def execute(inputs: Map[String, Any]): Map[String, Any] = { 369 | val blog = inputs("blog").asInstanceOf[Blog] 370 | val content = inputs("content").asInstanceOf[String] 371 | val author = inputs("author").asInstanceOf[User] 372 | val comment = Comment(content, author) 373 | //添加评论到博客 374 | addCommentToBlog(blog, comment) 375 | Map("comment" -> comment) 376 | } 377 | } 378 | ``` 379 | 380 | 上面的DSL定义了博客系统的处理流程,包含了博客系统中的实体、处理流程的步骤和每个步骤的输入、输出以及执行代码。使用该DSL可以方便地理解博客系统的处理流程,并且可以根据需要进行定制化开发。 381 | 382 | 383 | 384 | ```javascript 385 | DSL Blog System { 386 | Register { 387 | Input: Name(String), Email(String), Password(String) 388 | Output: User 389 | Execution: Create a user with the given name, email, and password 390 | } 391 | 392 | Login { 393 | Input: Email(String), Password(String) 394 | Output: User 395 | Execution: Find a user with the given email and password 396 | } 397 | 398 | Create Blog { 399 | Input: Title(String), Content(String), Author(User) 400 | Output: Blog 401 | Execution: Create a blog post with the given title, content, and author 402 | } 403 | 404 | Edit Blog { 405 | Input: Blog(Blog), Title(String), Content(String), Author(User) 406 | Output: Blog 407 | Execution: If the blog post belongs to the given author, update it with the given title and content; otherwise, throw an exception 408 | } 409 | 410 | Delete Blog { 411 | Input: Blog(Blog), Author(User) 412 | Output: None 413 | Execution: If the blog post belongs to the given author, delete it; otherwise, throw an exception 414 | } 415 | 416 | Comment on Blog { 417 | Input: Blog(Blog), Content(String), Author(User) 418 | Output: Comment 419 | Execution: Add a comment with the given content to the blog post 420 | } 421 | } 422 | ``` 423 | 424 | 425 | 抽象结果: 426 | 427 | ```scala 428 | DSL { 429 | { 430 | Input: , , ... 431 | Output: 432 | Execution: 433 | } 434 | 435 | { 436 | Input: , , ... 437 | Output: 438 | Execution: 439 | } 440 | 441 | ... 442 | 443 | { 444 | Input: , , ... 445 | Output: 446 | Execution: 447 | } 448 | } 449 | ``` 450 | 451 | 452 | ## 结果 453 | 454 | 帮我设计一个 DSL 来表示一个系统,要求:需要呈现业务处理过程。返回的结果只返回这个 DSL 的抽象。 455 | 456 | 457 | 为了设计一个 DSL 来表示一个系统的业务处理过程,需要考虑以下要素: 458 | 459 | 1. 业务实体和其属性 460 | 2. 业务操作和其参数 461 | 3. 业务流程和其步骤 462 | 4. 数据存储和其结构 463 | 464 | 基于上述要素,我们可以设计如下的 DSL: 465 | 466 | ```yaml 467 | System { 468 | Entities { 469 | Entity1 { 470 | Property1: Type1 471 | Property2: Type2 472 | ... 473 | } 474 | Entity2 { 475 | Property1: Type1 476 | Property2: Type2 477 | ... 478 | } 479 | ... 480 | } 481 | 482 | Operations { 483 | Operation1(entity: Entity1, param1: Type1, param2: Type2) -> ReturnType1 484 | Operation2(entity: Entity2, param1: Type1, param2: Type2) -> ReturnType2 485 | ... 486 | } 487 | 488 | Processes { 489 | Process1 { 490 | Step1: Operation1(entity1, param1, param2) 491 | Step2: Operation2(entity2, param1, param2) 492 | ... 493 | } 494 | Process2 { 495 | Step1: Operation1(entity1, param1, param2) 496 | Step2: Operation2(entity2, param1, param2) 497 | ... 498 | } 499 | ... 500 | } 501 | 502 | DataStorage { 503 | Table1 { 504 | Column1: Type1 505 | Column2: Type2 506 | ... 507 | } 508 | Table2 { 509 | Column1: Type1 510 | Column2: Type2 511 | ... 512 | } 513 | ... 514 | } 515 | } 516 | ``` 517 | 518 | 以上 DSL 中,我们首先定义了系统(System)的各个组成部分,包括实体(Entities)、操作(Operations)、流程(Processes)和数据存储(DataStorage)。 519 | 520 | 在实体(Entities)中,我们可以定义每个实体的属性(Property)和对应的数据类型(Type)。 521 | 522 | 在操作(Operations)中,我们可以定义每个操作的输入参数和输出结果的数据类型,并指定对应的实体。 523 | 524 | 在流程(Processes)中,我们可以定义一系列步骤(Step),每个步骤可以对应一个操作,并指定对应的实体和参数。 525 | 526 | 在数据存储(DataStorage)中,我们可以定义数据表(Table),每个数据表包含若干列(Column)和对应的数据类型。 527 | 528 | 通过以上 DSL,我们可以清晰地呈现系统的业务处理过程,并且只返回其抽象,便于后续进一步开发和实现。 529 | 530 | 531 | 重新设计: 532 | 533 | ``` 534 | System { 535 | Entities { 536 | User { 537 | id: Int 538 | username: String 539 | email: String 540 | password: String 541 | posts: [Post] 542 | } 543 | 544 | Post { 545 | id: Int 546 | title: String 547 | content: String 548 | author: User 549 | comments: [Comment] 550 | } 551 | 552 | Comment { 553 | id: Int 554 | content: String 555 | author: User 556 | post: Post 557 | } 558 | } 559 | 560 | Operations { 561 | RegisterUser(username: String, email: String, password: String) -> User 562 | LoginUser(email: String, password: String) -> User 563 | CreatePost(author: User, title: String, content: String) -> Post 564 | GetPostById(id: Int) -> Post 565 | AddComment(author: User, post: Post, content: String) -> Comment 566 | } 567 | 568 | Processes { 569 | PublishPost { 570 | Step1: LoginUser(email, password) 571 | Step2: CreatePost(author, title, content) 572 | } 573 | 574 | ViewPost { 575 | Step1: GetPostById(id) 576 | } 577 | 578 | CommentOnPost { 579 | Step1: LoginUser(email, password) 580 | Step2: GetPostById(id) 581 | Step3: AddComment(author, post, content) 582 | } 583 | } 584 | 585 | DataStorage { 586 | User { 587 | id: Int 588 | username: String 589 | email: String 590 | password: String 591 | } 592 | 593 | Post { 594 | id: Int 595 | title: String 596 | content: String 597 | author_id: Int 598 | } 599 | 600 | Comment { 601 | id: Int 602 | content: String 603 | author_id: Int 604 | post_id: Int 605 | } 606 | } 607 | } 608 | ``` 609 | 610 | 以上 DSL 描述的博客系统包含三个实体:User、Post 和 Comment,分别表示用户、文章和评论。其中 User 实体包含一对多的关系到 Post 实体,Post 实体包含一对多的关系到 Comment 实体。 611 | 612 | 博客系统的操作包括注册用户、登录用户、创建文章、获取文章和添加评论。通过这些操作,用户可以在博客系统中进行文章的发布、查看和评论。 613 | 614 | 博客系统中的流程包括发布文章、查看文章和评论文章。通过这些流程,用户可以方便地完成博客系统中的常见操作。 615 | 616 | 博客系统的数据存储包括三个表:User、Post 和 Comment,分别存储用户、文章和评论的相关信息。其中,Post 表包含一个外键 author_id,指向 User 表中的相应记录;Comment 表包含两个外键 author_id 和 post_id,分别指向 User 表和 Post 表中的相应记录。 617 | 618 | 619 | ## 还是不太理想,回到上一个版本,添加一个先验条件和后验条件吧 620 | 621 | ``` 622 | System { 623 | Entities { 624 | User { 625 | id: Int 626 | username: String 627 | email: String 628 | password: String 629 | posts: [Post] 630 | } 631 | 632 | Post { 633 | id: Int 634 | title: String 635 | content: String 636 | author: User 637 | comments: [Comment] 638 | } 639 | 640 | Comment { 641 | id: Int 642 | content: String 643 | author: User 644 | post: Post 645 | } 646 | } 647 | 648 | Operations { 649 | RegisterUser(username: String, email: String, password: String) -> User 650 | Input: username, email, password 651 | Output: a new user record 652 | Precondition: email is not already registered 653 | 654 | LoginUser(email: String, password: String) -> User 655 | Input: email, password 656 | Output: a user record with the given email and password 657 | Precondition: email and password are valid 658 | Postcondition: the user is marked as logged in 659 | 660 | CreatePost(author: User, title: String, content: String) -> Post 661 | Input: author, title, content 662 | Output: a new post record 663 | Precondition: the author is logged in 664 | 665 | GetPostById(id: Int) -> Post 666 | Input: id 667 | Output: a post record with the given ID 668 | 669 | AddComment(author: User, post: Post, content: String) -> Comment 670 | Input: author, post, content 671 | Output: a new comment record 672 | Precondition: the author is logged in 673 | } 674 | 675 | Processes { 676 | PublishPost { 677 | Step1: LoginUser(email, password) 678 | Input: email, password 679 | Output: a user record with the given email and password 680 | Precondition: email and password are valid 681 | Postcondition: the user is marked as logged in 682 | Step2: CreatePost(author, title, content) 683 | Input: author, title, content 684 | Output: a new post record 685 | Precondition: the author is logged in 686 | } 687 | 688 | ViewPost { 689 | Step1: GetPostById(id) 690 | Input: id 691 | Output: a post record with the given ID 692 | } 693 | 694 | CommentOnPost { 695 | Step1: LoginUser(email, password) 696 | Input: email, password 697 | Output: a user record with the given email and password 698 | Precondition: email and password are valid 699 | Postcondition: the user is marked as logged in 700 | Step2: GetPostById(id) 701 | Input: id 702 | Output: a post record with the given ID 703 | Step3: AddComment(author, post, content) 704 | Input: author, post, content 705 | Output: a new comment record 706 | Precondition: the author is logged in 707 | } 708 | } 709 | 710 | DataStorage { 711 | User { 712 | id: Int 713 | username: String 714 | email: String 715 | password: String 716 | } 717 | 718 | Post { 719 | id: Int 720 | title: String 721 | content: String 722 | author_id: Int 723 | } 724 | 725 | Comment { 726 | id: Int 727 | content: String 728 | author_id: Int 729 | post_id: Int 730 | } 731 | } 732 | } 733 | 734 | ``` 735 | 736 | 最后版本: 737 | 738 | ``` 739 | System("Blog System") { 740 | Entities { 741 | User { 742 | id: Int 743 | username: String 744 | email: String 745 | password: String 746 | posts: [Post]? 747 | } 748 | 749 | Post { 750 | id: Int 751 | title: String 752 | content: String 753 | author: User 754 | comments: [Comment]? 755 | } 756 | 757 | Comment { 758 | id: Int 759 | content: String 760 | author: User 761 | post: Post 762 | } 763 | } 764 | 765 | Operations { 766 | RegisterUser(username: String, email: String, password: String) -> User 767 | Input: username: String, email: String, password: String 768 | Output: a new user record: User 769 | // The email must not already be registered in the system. 770 | Precondition: email is not already registered 771 | 772 | LoginUser(email: String, password: String) -> User 773 | Input: email: String, password: String 774 | Output: a user record with the given email and password: User 775 | // The email and password must be valid. 776 | Precondition: email and password are valid 777 | // The user is marked as logged in after this operation. 778 | Postcondition: the user is marked as logged in 779 | 780 | CreatePost(author: User, title: String, content: String) -> Post 781 | Input: author: User, title: String, content: String 782 | Output: a new post record: Post 783 | // The author must be logged in to create a post. 784 | Precondition: the author is logged in 785 | 786 | GetPostById(id: Int) -> Post 787 | Input: id: Int 788 | Output: a post record with the given ID: Post 789 | 790 | AddComment(author: User, post: Post, content: String) -> Comment 791 | Input: author: User, post: Post, content: String 792 | Output: a new comment record: Comment 793 | // The author must be logged in to add a comment. 794 | Precondition: the author is logged in 795 | } 796 | 797 | API { 798 | POST "/register_user" RegisterUser 799 | POST "/login_user" LoginUser 800 | POST "/create_post" CreatePost 801 | GET "/post/:id" GetPostById 802 | POST "/add_comment" AddComment 803 | } 804 | } 805 | ``` 806 | 807 | 抽象: 808 | 809 | ``` 810 | System(name: String) { 811 | Entity(name: String) { 812 | attribute1: Type1 813 | attribute2: Type2 814 | ... 815 | attributeN: TypeN 816 | relation1: [Entity1]? 817 | relation2: [Entity2]? 818 | ... 819 | relationM: [EntityM]? 820 | } 821 | Operation(name: String, input: [(name: String, type: Type)], output: Type) { 822 | Input: input1: Type1, input2: Type2, ..., inputN: TypeN 823 | Output: ReturnType1 824 | Precondition: precondition1 825 | ... 826 | Precondition: preconditionM 827 | Postcondition: postcondition1 828 | ... 829 | Postcondition: postconditionK 830 | } 831 | API { 832 | Route(path: String, operation: Operation) 833 | } 834 | } 835 | ``` 836 | 837 | 838 | ## Q3 839 | 840 | 使用 TypeScript 的类型来描述这个 DSL,并添加一个简单的类型系统,不使用 TypeScript 自带的类型: 841 | 842 | """ 843 | 844 | Entity(name: String) { 845 | attribute1: Type1 846 | attribute2: Type2 847 | ... 848 | attributeN: TypeN 849 | relation1: [Entity1]? 850 | relation2: [Entity2]? 851 | ... 852 | relationM: [EntityM]? 853 | } 854 | 855 | Operation(name: String, input: [(name: String, type: Type)], output: Type) { 856 | Input: input1: Type1, input2: Type2, ..., inputN: TypeN 857 | Output: ReturnType1 858 | Precondition: precondition1 859 | ... 860 | Precondition: preconditionM 861 | Postcondition: postcondition1 862 | ... 863 | Postcondition: postconditionK 864 | } 865 | 866 | API { 867 | Route(path: String, operation: Operation) 868 | } 869 | """ 870 | 871 | 最终的类型系统: 872 | 873 | 874 | ``` 875 | // 定义一个 Entity 类型 876 | type Entity = { 877 | name: string; 878 | attributes: { 879 | [attributeName: string]: Type; 880 | }; 881 | relations: { 882 | [relationName: string]: Entity[]; 883 | }; 884 | }; 885 | 886 | // 定义一个 Operation 类型 887 | type Operation = { 888 | name: string; 889 | input: { 890 | name: string; 891 | type: Type; 892 | }[]; 893 | output: Type; 894 | inputVariables: { 895 | [variableName: string]: Type; 896 | }; 897 | preconditions: string[]; 898 | postconditions: string[]; 899 | }; 900 | 901 | // 定义一个 API 类型 902 | type API = { 903 | routes: { 904 | path: string; 905 | operation: Operation; 906 | }[]; 907 | }; 908 | ``` 909 | 910 | 911 | 下面是使用 TypeScript 的类型来描述该 DSL 的示例: 912 | 913 | typescript 914 | 915 | // 定义一个 Entity 类型 916 | type Entity = { 917 | name: string; 918 | attributes: { 919 | [attributeName: string]: Type; 920 | }; 921 | relations: { 922 | [relationName: string]: Entity[]; 923 | }; 924 | }; 925 | 926 | // 定义一个 Operation 类型 927 | type Operation = { 928 | name: string; 929 | input: { 930 | name: string; 931 | type: Type; 932 | }[]; 933 | output: Type; 934 | inputVariables: { 935 | [variableName: string]: Type; 936 | }; 937 | preconditions: string[]; 938 | postconditions: string[]; 939 | }; 940 | 941 | // 定义一个 API 类型 942 | type API = { 943 | routes: { 944 | path: string; 945 | operation: Operation; 946 | }[]; 947 | }; 948 | 949 | 这个类型系统的思路是,我们首先定义了每个 DSL 元素的类型:Entity、Operation 和 API。然后,对于每个类型,我们使用 TypeScript 的类型来描述它们的结构。 950 | 951 | 例如,对于 Entity 类型,我们定义了一个对象,它有 name、attributes 和 relations 属性。其中,attributes 是一个字符串索引类型,它将属性名称映射到属性类型;relations 也是一个字符串索引类型,它将关系名称映射到关联的实体数组。 952 | 953 | 对于 Operation 类型,我们定义了一个对象,它有 name、input、output、inputVariables、preconditions 和 postconditions 属性。其中,input 是一个包含输入参数名称和类型的对象数组;inputVariables 是一个字符串索引类型,它将变量名称映射到变量类型;preconditions 和 postconditions 是字符串数组,它们表示操作的前置条件和后置条件。 954 | 955 | 最后,对于 API 类型,我们定义了一个对象,它有一个 routes 属性,它是一个包含路径和操作的对象数组。 956 | 957 | 需要注意的是,这个类型系统并没有使用 TypeScript 自带的类型,而是自定义了一些类型。这是因为 DSL 的语法和语义可能与 TypeScript 的类型系统不完全匹配,因此需要根据 DSL 的具体情况来自定义类型。 958 | 959 | ## 能使用 JavaScript 脚本来动态创建这样的类型吗? 960 | 961 | 962 | 可以使用 JavaScript 脚本动态创建这样的类型。由于 TypeScript 是 JavaScript 的超集,可以使用 TypeScript 的编译器 API 来创建和生成 TypeScript 类型。 963 | 964 | 以下是一个示例脚本,该脚本动态创建了与上面 TypeScript 类型相同的类型,并将其打印到控制台: 965 | 966 | 967 | 968 | ## 测试 969 | 970 | 971 | 使用如下的 DSL 描述一个在线系统: 972 | 973 | """ 974 | System(name: String) { 975 | Entity(name: String) { 976 | attribute1: Type1 977 | attribute2: Type2 978 | ... 979 | attributeN: TypeN 980 | relation1: [Entity1]? 981 | relation2: [Entity2]? 982 | ... 983 | relationM: [EntityM]? 984 | } 985 | Operation(name: String, input: [(name: String, type: Type)], output: Type) { 986 | Input: input1: Type1, input2: Type2, ..., inputN: TypeN 987 | Output: ReturnType1 988 | Precondition: precondition1 989 | ... 990 | Precondition: preconditionM 991 | Postcondition: postcondition1 992 | ... 993 | Postcondition: postconditionK 994 | } 995 | API { 996 | Route(path: String, operation: Operation) 997 | } 998 | } 999 | """ 1000 | 1001 | 1002 | 并只返回其中的 Entity 部分,只返回其中的 Entity 部分。 1003 | 1004 | 1005 | ### 拆解 1006 | 1007 | - 列出所有 Entity,每 10 个返回 1008 | - 列出所有的 Operation 1009 | - 列出所有的 API。 1010 | 1011 | 1012 | 我们来设计一个流程,名为: system,其用于软件系统设计。我们会把设计分为两部分: 1013 | 1014 | 第一部分,当我用 "design:{}"发给你需求时,你需要分析所有潜在的对应场景。要求如下: 1015 | 1016 | 1. 使用如下的 DSL 格式来描述: 1017 | 1018 | ``` 1019 | BlogSystem { 1020 | UserManagement:UserRegistration 1021 | 1. 用户访问注册页面 1022 | 2. 用户输入用户名和密码 1023 | 3. 系统验证用户名是否已经被占用 1024 | UserManagement:... 1025 | ... 1026 | } 1027 | ``` 1028 | 1029 | 1030 | 第二部分,我会用 "system({}):{}" 的形式发给你设计需求,示例:"system("API"): 博客系统",表示上面格式中的 API 部分。要求如下: 1031 | 1032 | 1. 你需要考虑围绕这一类型系统的所有场景。 1033 | 2. 使用如下的 DSL 格式来描述系统: 1034 | 1035 | """ 1036 | ``` 1037 | System("BlogSystem") { 1038 | Entities { 1039 | Blog { title: string, ..., comments: [Comment]? }, 1040 | Comment { ...} 1041 | } 1042 | Operation { 1043 | Ops("CreateBlog", { 1044 | in: { title: string, description: string }, 1045 | out: { id: number } 1046 | pre: title is unique and (title.length > 5 && title.length < 120) 1047 | post: id is not null 1048 | }) 1049 | } 1050 | API { 1051 | Route(path: String, method: HttpMethod operation: Operation) 1052 | } 1053 | } 1054 | ``` 1055 | """ 1056 | 1057 | 明白吗?明白就返回:OK。 1058 | 1059 | -------------------------------------------------------------------------------- /chatgpt/pipeline.sample.md: -------------------------------------------------------------------------------- 1 | # ArchGuard Pipeline 2 | 3 | ## Topic 4 | 5 | phodal:我想写一篇文章介绍 ArchGurad Pipeline,其用于编排架构设计、治理的工作流程,帮我想一下可行的主题? 6 | 7 | chatgpt: 8 | 9 | 以下是几个可行的主题: 10 | 11 | 介绍 ArchGuard Pipeline 的工作流程及其在架构设计中的应用 12 | 13 | 如何使用 ArchGuard Pipeline 来实现企业级的架构治理 14 | 15 | ArchGuard Pipeline 对架构设计和治理过程的优化及效果分析 16 | 17 | ArchGuard Pipeline 与其他架构设计工具的比较 18 | 19 | 如何使用 ArchGuard Pipeline 来进行企业数字化转型 20 | 21 | 无论选择哪个主题,都应该包括以下内容: 22 | 23 | ArchGuard Pipeline 的介绍和工作原理 24 | ArchGuard Pipeline 在架构设计和治理中的优势和应用场景 25 | ArchGuard Pipeline 与其他工具或方法的比较和对比分析 26 | ArchGuard Pipeline 的实际案例和效果分析 27 | 28 | 最后,不要忘记在文章中提供足够的示例和实际数据来支持你的观点和结论,这将使文章更具说服力。 29 | 30 | ## Storyline 31 | 32 | phodal:我文章的主题是:"""ArchGuard Pipeline:更易于实现的企业级的架构治理?""",包含以下的大纲: 33 | 34 | """ 35 | - 为什么会有 ArchGuard Pipeline —— 因为基于 ArchGuard 定制困难。 36 | - ArchGuard Pipeline 的介绍和工作原理 37 | - 介绍 ArchGuard 的由来:Gradle、GitHub Action 38 | - ArchGuard Pipeline 在架构设计和治理中的优势和应用场景 39 | """ 40 | 41 | 帮我写一篇文章。 42 | 43 | chatgpt: 44 | 45 | > ArchGuard Pipeline:更易于实现的企业级的架构治理? 46 | 47 | 在当今数字化转型的时代,企业对于架构设计和治理越来越注重。但是,实现企业级的架构治理并不容易。在这种情况下, ArchGuard Pipeline 成为了一种更易于实现的架构治理方案。 48 | 49 | 为什么会有 ArchGuard Pipeline? 50 | 51 | 在过去,许多企业都尝试过使用 ArchGuard 来实现架构治理。然而,由于 ArchGuard 定制困难的问题,许多企业并没有能够成功地实现架构治理。因此,为了解决这个问题,开发者们推出了 ArchGuard Pipeline。 52 | 53 | ArchGuard Pipeline 的介绍和工作原理 54 | 55 | ArchGuard Pipeline 是一个基于 Gradle 和 GitHub Action 的自动化工具,用于对企业级的架构进行治理。ArchGuard Pipeline 可以帮助企业在构建过程中进行自动化的架构检查,从而保证架构的质量和一致性。 56 | 57 | ArchGuard Pipeline 与 ArchGuard 不同的是,它采用了流水线(pipeline)的方式,通过 Gradle 构建系统和 GitHub Action 提供的 CI/CD 自动化工具,将架构设计和治理融入到企业的持续集成和持续交付流程中。 58 | 59 | ArchGuard Pipeline 的由来:Gradle、GitHub Action 60 | 61 | Gradle 是一种基于 Groovy 和 Kotlin 的构建工具,用于构建、测试和部署软件。它具有良好的灵活性和可扩展性,可以自定义任务,定制构建流程。这种灵活性使得 Gradle 成为了 ArchGuard Pipeline 的构建系统选择。 62 | 63 | GitHub Action 是 GitHub 提供的一种 CI/CD 自动化工具,可以在 GitHub 上对代码进行自动化构建、测试和部署。ArchGuard Pipeline 采用了 GitHub Action 的自动化流程,实现了架构治理与持续集成和持续交付的无缝衔接。 64 | 65 | ArchGuard Pipeline 在架构设计和治理中的优势和应用场景 66 | 67 | ArchGuard Pipeline 的优势在于它可以自动化地检查架构设计和实现中的问题,提供实时的反馈和提示。ArchGuard Pipeline 可以帮助企业规范架构的设计和实现流程,提高架构的质量和一致性。 68 | 69 | 对于企业级的应用场景,ArchGuard Pipeline 可以用于检查和规范以下方面: 70 | 71 | 代码结构和依赖关系 72 | 架构设计和实现规范 73 | 安全性和可靠性 74 | 75 | 总结 76 | 77 | ArchGuard Pipeline 是一种更易于实现的企业级的架构治理方案,它基于 Gradle 和 GitHub Action,将架构治理融入到持续集成 78 | 79 | 80 | ## 生成新的大纲 81 | 82 | > phodal:帮我生成上面这篇文章的大纲。 83 | 84 | ChatGPT: 85 | 86 | ArchGuard Pipeline:更易于实现的企业级的架构治理? 87 | 88 | I. 引言 89 | 90 | 企业架构治理的重要性 91 | ArchGuard Pipeline 的作用和意义 92 | 93 | II. 为什么会有 ArchGuard Pipeline? 94 | 95 | ArchGuard 定制困难的问题 96 | ArchGuard Pipeline 的诞生背景 97 | 98 | III. ArchGuard Pipeline 的介绍和工作原理 99 | 100 | ArchGuard Pipeline 的定义和特点 101 | Gradle 和 GitHub Action 的作用 102 | ArchGuard Pipeline 的工作原理 103 | 104 | IV. ArchGuard Pipeline 的由来:Gradle、GitHub Action 105 | 106 | Gradle 的基本介绍和优势 107 | GitHub Action 的基本介绍和优势 108 | ArchGuard Pipeline 的构建系统选择和流程介绍 109 | 110 | V. ArchGuard Pipeline 在架构设计和治理中的优势和应用场景 111 | 112 | ArchGuard Pipeline 的优势和特点 113 | ArchGuard Pipeline 在架构设计和治理中的应用场景 114 | 代码结构和依赖关系检查 115 | 架构设计和实现规范检查 116 | 安全性和可靠性检查 117 | 118 | VI. 总结 119 | 120 | ArchGuard Pipeline 的意义和作用 121 | ArchGuard Pipeline 的未来展望 122 | 结论和建议 123 | 124 | 125 | ## 灵感:新标题 126 | 127 | 128 | > phodal:围绕 """ArchGuard Pipeline:更易于实现的企业级的架构治理?""" 帮我取 10 个更吸引人的话题,让我选择。 129 | 130 | 好的,以下是 10 个围绕 ArchGuard Pipeline 的更具吸引力的话题,供您选择: 131 | 132 | 如何利用 ArchGuard Pipeline 改进您的企业架构治理流程? 133 | 为什么 ArchGuard Pipeline 是企业级架构治理的最佳选择? 134 | ArchGuard Pipeline 和传统架构治理工具的比较:优缺点对比。 135 | 深入了解 ArchGuard Pipeline:工作原理和技术实现。 136 | 如何使用 ArchGuard Pipeline 简化企业架构治理流程,提高生产力? 137 | ArchGuard Pipeline 如何保证企业架构设计的一致性和质量? 138 | 如何为您的企业定制 ArchGuard Pipeline,以满足特定的架构治理需求? 139 | ArchGuard Pipeline 对于 DevOps 工作流程的影响。 140 | ArchGuard Pipeline 如何提供实时的反馈和提示,帮助企业规范架构设计流程? 141 | ArchGuard Pipeline 在架构治理中的最佳实践:案例分析和经验分享。 142 | 143 | 144 | ## 组织思路、重写文章 145 | 146 | 标题:"""ArchGuard Pipeline:构建轻量级的企业级的架构治理流程?""" 147 | 148 | 内容草稿: 149 | 150 | ``` 151 | 152 | 当我们构建企业级的架构治理流程时,需要考虑到一些重要的因素,比如定制性、可扩展性、任务可追溯性等。为了解决这些问题,我们开始设计 ArchGuard Pipeline 来构建轻量级的架构治理流程。 153 | 154 | ## 为什么是 Pipeline 呢? 155 | 156 | 在 ArchGuard 2.0 中,想要定制的话存在一些问题,包括: 157 | 158 | 1. 定制性不足:当前版本定制性很差,需要修改的代码范围很大,非常不灵活。 159 | 2. 扩展性有限:当需要添加新的构建步骤或治理工具时,扩展非常困难。 160 | 3. 可视性差:分析过程非常复杂,难以跟踪和调试,可视性很差。 161 | 4. 无重试机制:当单个任务出错时,需要重新分析整个过程,缺乏重试机制。 162 | 5. 过程不透明:分析过程是一个黑盒,无法知道具体的任务细节,这给问题定位和解决带来了很大的困难。 163 | 164 | 还有, 165 | 166 | ## 什么是 ArchGuard Pipeline?~~GitHub Action~~ 167 | 168 | {{这里需要先定义 ArchGuard pipeline}} 169 | 170 | 对应的使用场景: 171 | 172 | 1. 构建企业级的架构治理框架 173 | 2. 团队自定义架构适应度函数 174 | 3. 优化:如可视化分析过程等。 175 | 4. {{相似的}} 176 | 177 | ### 如何使用 ArchGuard Pipeline 178 | 179 | 示例: 180 | 181 | ``` 182 | jobs: 183 | backend: 184 | steps: 185 | - name: "Source Code with Linter" 186 | uses: archguard/scanner@v2 187 | with: 188 | type: "source_code" 189 | language: kotlin 190 | features: [ "datamap" ] 191 | output: [ "json", "arrow" ] 192 | rules: [ "webapi", "test", "sql" ] 193 | path: "." 194 | ``` 195 | 196 | ## 我们是如何实现的? 197 | 198 | 因为,我们已经有一个 ArchGuard Gradle 插件。所以,起初,我们打算参考 Gradle 设计整体的工作流程,遇到了一些问题:{{需要解释为什么,比如中心化?}}。 199 | 200 | 随后,既然 pipeline 是一个构建系统,那么 GitHub Action 也是相似的,便想着参考 GitHub Action,{{介绍 GitHub Action 的优点}}。 201 | 202 | 步骤如图所示: 203 | 204 | 即: 205 | 206 | 1. 解析 `archguard.yml`,生成对应的配置 207 | 2. 根据配置从 ArchGuard registry 下载 Runner,如 `checkout`、`scanner` 208 | 3. 执行 runner,根据不同 runner 输出制品 209 | 4. 上传到服务器(按需) 210 | 211 | ## 小结 212 | 213 | {{}} 214 | ``` 215 | 216 | 217 | 目测由于 GitHub 的上下文问题,需要一点点输入。 218 | 219 | 220 | -------------------------------------------------------------------------------- /chatgpt/prompt-programming.md: -------------------------------------------------------------------------------- 1 | # Prompt 编程 2 | 3 | 4 | ## 概念对齐 5 | 6 | phodal:知道 DDD 里的 ContextMap 吗? 7 | 8 | chatgpt:…… 9 | 10 | phodal:知道 DSL(领域特定语言)吗? 11 | 12 | chatgpt:…… 13 | 14 | phodal:设计一个 DSL 来表示 DDD 里的 Context Map 。 15 | 16 | 17 | 好的,下面是一个简单的 DSL 设计,用于表示 DDD 中的 Context Map: 18 | 19 | ``` 20 | ContextMap: 21 | Subdomain { Name: [subdomain_name] } 22 | [CollaboratesWith: [other_subdomain_name], ...] 23 | [ConformistWith: [other_subdomain_name], ...] 24 | [Antagonizes: [other_subdomain_name], ...] 25 | ... 26 | 27 | ``` 28 | 29 | 上面的 DSL 中,ContextMap 表示整个上下文映射。每个 Subdomain 表示一个子域,Name 是子域的名称。子域之间的关系可以通过 CollaboratesWith(合作)、ConformistWith(一致)和 Antagonizes(对立)来描述。 30 | 31 | 例如,下面是一个包含两个子域之间关系的 Context Map 示例: 32 | 33 | 34 | ``` 35 | ContextMap: 36 | Subdomain { Name: "订单" } 37 | CollaboratesWith: "库存" 38 | Subdomain { Name: "库存" } 39 | Antagonizes: "订单" 40 | ``` 41 | 42 | 43 | 这个例子中,"订单" 子域与 "库存" 子域合作,而 "库存" 子域对 "订单" 子域表示对立。 44 | 45 | 这只是一个简单的示例,实际上 DSL 的设计取决于具体的应用场景和需求,可以根据需要进行调整和扩展。但总体上,DSL 的目的是使 Context Map 更易于理解、表示和维护。 46 | 47 | ## 事件风暴 48 | 49 | phodal:知道 DDD 里的事件风暴吗? 50 | 51 | phodal:可以设计一个 DSL 来描述事件风暴的 事件建模 吗? 52 | 53 | 是的,下面是一个简单的事件风暴的事件建模的 DSL,它可以用来描述在事件风暴会议中识别和记录领域事件的过程。 54 | 55 | css 56 | 57 | EventStorming: 58 | Domain { Name: "领域名称" } 59 | Event { Name: "事件名称" } 60 | Triggered By: "触发该事件的因素" 61 | Description: "事件的详细描述" 62 | Actors: ["参与事件的主要角色"] 63 | Action: "在事件中执行的行为" 64 | Outcome: "事件触发后的结果" 65 | Event { Name: "另一个事件名称" } 66 | Triggered By: "触发该事件的因素" 67 | Description: "事件的详细描述" 68 | Actors: ["参与事件的主要角色"] 69 | Action: "在事件中执行的行为" 70 | Outcome: "事件触发后的结果" 71 | ... 72 | 73 | 在这个 DSL 中,我们首先定义了领域的名称,然后列出了所有的领域事件,每个事件都有以下属性: 74 | 75 | 事件名称:表示该事件的名称或标识符。 76 | 触发该事件的因素:表示该事件被触发的原因或条件。 77 | 事件的详细描述:描述事件的细节和上下文。 78 | 参与事件的主要角色:表示在事件中涉及的主要角色或参与者。 79 | 在事件中执行的行为:表示在事件发生时执行的操作或行为。 80 | 事件触发后的结果:表示事件触发后的影响或结果。 81 | 82 | 使用这个 DSL,我们可以将事件风暴会议中识别和记录的领域事件以清晰和一致的方式进行建模和记录。同时,这个 DSL 也可以作为团队之间沟通的基础,加强团队之间的协作和理解。 83 | 84 | 85 | phodal:能用 事件建模的 DSL 来表示用户购票的流程吗? 86 | 87 | 88 | 是的,下面是一个简单的事件建模的 DSL,它可以用来描述用户购票的流程。 89 | 90 | css 91 | 92 | EventStorming: 93 | Domain { Name: "电影订票系统" } 94 | Event { Name: "用户提交订单" } 95 | Triggered By: "用户选择电影、场次、座位,确认订单" 96 | Description: "用户提交订单,包括所选电影、场次、座位等信息" 97 | Actors: ["用户"] 98 | Action: "将用户提交的订单信息保存到订单数据库中" 99 | Outcome: "订单状态被标记为已提交" 100 | Event { Name: "库存检查" } 101 | Triggered By: "订单状态被标记为已提交" 102 | Description: "检查所选场次的座位是否还有余量" 103 | Actors: ["库存管理系统"] 104 | Action: "查询座位库存信息" 105 | Outcome: "座位库存信息被更新" 106 | Event { Name: "订单确认" } 107 | Triggered By: "座位库存信息被更新" 108 | Description: "确认订单,将座位标记为已售出" 109 | Actors: ["库存管理系统"] 110 | Action: "更新座位库存信息,将座位标记为已售出" 111 | Outcome: "座位库存信息被更新,订单状态被标记为已确认" 112 | Event { Name: "支付确认" } 113 | Triggered By: "用户支付订单" 114 | Description: "用户完成支付" 115 | Actors: ["用户"] 116 | Action: "将支付信息保存到支付数据库中" 117 | Outcome: "支付状态被标记为已完成" 118 | Event { Name: "票据生成" } 119 | Triggered By: "订单状态被标记为已确认且支付状态被标记为已完成" 120 | Description: "生成电子票据,包括电影、场次、座位、价格等信息" 121 | Actors: ["票务系统"] 122 | Action: "根据订单信息生成电子票据" 123 | Outcome: "电子票据被生成" 124 | 125 | 在这个 DSL 中,我们定义了电影订票系统的领域名称,并列出了购票流程中的所有事件。每个事件都包含了事件名称、触发该事件的因素、事件的详细描述、参与事件的主要角色、在事件中执行的行为和事件触发后的结果。通过这个 DSL,我们可以清晰地描述用户购票的流程,包括用户提交订单、库存检查、订单确认、支付确认和票据生成等事件。同时,这个 DSL 也可以作为团队之间沟通的基础,加强团队之间的协作和理解。 126 | 127 | phodal:能将上述的 用户购票 的流程转换为 Java 测试用例吗? 128 | 129 | ## 工程化 130 | 131 | phodal:为电影订票系统设计一个 DDD 风格 Java 工程的代码目录结构。 132 | 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /chatgpt/workflow.md: -------------------------------------------------------------------------------- 1 | ## Q1 2 | 3 | 我们来玩一个名为 story 的游戏,在这个游戏里,我会给你一个模糊的需求,你需要: 4 | 5 | 1. 分析需求,并使用用户故事和 Invest 原则编写用户故事卡,但是不需要返回给我。 6 | 2. 尽可能写清楚用户故事的验收条件,验收条件 Given When Then 的表达方式,但是不需要返回给我。 7 | 3. 最后返回用户故事的标题,内容,验收条件,格式如下: 8 | 9 | """ 10 | 标题:{} 11 | 12 | 内容:{} 13 | 14 | 验收条件: 15 | 16 | 1. AC01 {} 17 | - When {} 18 | - Then {} 19 | 2. AC02 {} 20 | - When {} 21 | - Then {} 22 | """ 23 | 24 | 当我说 """story: {}""" ,咱们开始游戏。知道这个游戏怎么玩吗?知道的话,请只回复:OK 25 | 26 | ## Q2 27 | 28 | ## Q3 29 | 30 | 我会给你一个需求,你需要: 31 | 32 | 1. 分析需求,但是不需要返回结果给我。 33 | 2. 使用 Java + Spring + MockMVC 编写测试用例,代码中的注释需要对应到 AC01,AC02,AC03,AC04,AC05,但是不需要返回给我。 34 | 3. 最后,只返回 Java 代码,只返回 Java 代码。 35 | 36 | 需求,如下: 37 | 38 | """ 39 | 标题:新增账号 40 | 41 | 内容: 42 | 作为一个具有权限管理功能的用户,我希望能够通过账号管理页面的新增账号按钮来创建新的用户账号,以便能够进行更多的操作。 43 | 44 | 验收条件: 45 | 46 | AC01 点击“新增账号”按钮时,系统应该弹出一个新增账号窗口,其中包含必填字段:姓名、登录邮箱、账号角色、密码等。 47 | 48 | When 用户点击“新增账号”按钮 49 | Then 系统弹出一个新增账号窗口,其中包含必填字段:姓名、登录邮箱、账号角色、密码等。 50 | 51 | AC02 如果用户未填写必填字段,则在点击“确认”时给出错误提醒“请完成所有必填字段的填写!” 52 | 53 | Given 用户已经打开新增账号窗口,并且至少有一个必填字段未填写 54 | When 用户点击“确认”按钮 55 | Then 系统给出错误提醒“请完成所有必填字段的填写!” 56 | 57 | AC03 点击“确认”按钮后,弹出二次确认窗口,二次确认信息为“确认创建该账号?账号一旦创建成功即会邮件通知对应用户”。 58 | 59 | Given 用户已经填写完所有必填字段,并点击了“确认”按钮 60 | When 系统弹出二次确认窗口 61 | Then 二次确认窗口应该包含确认信息:“确认创建该账号?账号一旦创建成功即会邮件通知对应用户”。 62 | 63 | AC04 用户在二次确认窗口中选择“确认”时,系统应该创建账号。 64 | 65 | Given 用户已经确认创建该账号 66 | When 用户在二次确认窗口中选择“确认” 67 | Then 系统创建账号并提示“账号创建成功”。 68 | 69 | AC05 用户在二次确认窗口中选择“取消”时,系统应该返回填写账号窗口。 70 | 71 | Given 用户已经确认返回填写账号窗口 72 | When 用户在二次确认窗口中选择“取消” 73 | Then 系统返回填写账号窗口。 74 | """ 75 | 76 | ## Q4 77 | 78 | 我给你一个需求,你需要分析需求,使用 Java + Spring 编写 API,要求如下: 79 | 80 | 1. 去除不需要的 UI 交互代码,只返回对应的代码。 81 | 2. 在方法中用注释写明如何实现。 82 | 3. 最后,你返回给我的只有代码,格式如下: 83 | 84 | ```java 85 | // {} 86 | @PostMapping({}) 87 | public void main(String args[]) 88 | { 89 | // {} 90 | } 91 | ``` 92 | 93 | 需求如下: 94 | 95 | 需求,如下: 96 | 97 | """ 98 | 标题:新增账号 99 | 100 | 内容: 101 | 作为一个具有权限管理功能的用户,我希望能够通过账号管理页面的新增账号按钮来创建新的用户账号,以便能够进行更多的操作。 102 | 103 | 验收条件: 104 | 105 | AC01 点击“新增账号”按钮时,系统应该弹出一个新增账号窗口,其中包含必填字段:姓名、登录邮箱、账号角色、密码等。 106 | 107 | When 用户点击“新增账号”按钮 108 | Then 系统弹出一个新增账号窗口,其中包含必填字段:姓名、登录邮箱、账号角色、密码等。 109 | 110 | AC02 如果用户未填写必填字段,则在点击“确认”时给出错误提醒“请完成所有必填字段的填写!” 111 | 112 | Given 用户已经打开新增账号窗口,并且至少有一个必填字段未填写 113 | When 用户点击“确认”按钮 114 | Then 系统给出错误提醒“请完成所有必填字段的填写!” 115 | 116 | AC03 点击“确认”按钮后,弹出二次确认窗口,二次确认信息为“确认创建该账号?账号一旦创建成功即会邮件通知对应用户”。 117 | 118 | Given 用户已经填写完所有必填字段,并点击了“确认”按钮 119 | When 系统弹出二次确认窗口 120 | Then 二次确认窗口应该包含确认信息:“确认创建该账号?账号一旦创建成功即会邮件通知对应用户”。 121 | 122 | AC04 用户在二次确认窗口中选择“确认”时,系统应该创建账号。 123 | 124 | Given 用户已经确认创建该账号 125 | When 用户在二次确认窗口中选择“确认” 126 | Then 系统创建账号并提示“账号创建成功”。 127 | 128 | AC05 用户在二次确认窗口中选择“取消”时,系统应该返回填写账号窗口。 129 | 130 | Given 用户已经确认返回填写账号窗口 131 | When 用户在二次确认窗口中选择“取消” 132 | Then 系统返回填写账号窗口。 133 | """ 134 | 135 | 136 | ## A1 137 | 138 | OK。 139 | 140 | ## Q2 141 | 142 | story: 143 | 144 | """ 145 | 用户通过主菜单进入“权限管理”模块,选择“账号管理”Tab页,可以看到“新增账号”按钮。 146 | 点击“新增账号”按钮,系统弹出新增账号窗口(可能还会写一句“背景置灰”)。 147 | 用户可在窗口中填写姓名、登录邮箱…… 148 | 若用户未填写必填字段,则点击“确认”时给出错误提醒“请完成所有必填字段的填写!” 149 | 点击“确认”按钮后弹出二次确认窗口,二次确认信息为“确认创建该账号?账号一旦创建成功即会邮件通知对应用户”。用户再次选择“确认”则系统创建账号,若用户选择“取消”则返回填写账号窗口。 150 | """ 151 | 152 | ## A2 153 | 154 | 用户故事卡: 155 | 156 | 卡片标题:新增账号 157 | 158 | 角色:拥有权限管理权限的用户 159 | 160 | 目标:方便快捷地新增一个账号并发送通知邮件 161 | 162 | 场景:当用户进入权限管理模块并选择账号管理Tab页,点击新增账号按钮时 163 | 164 | 前置条件:用户已经通过身份验证并拥有权限管理权限 165 | 166 | 主要成功场景: 167 | 168 | 用户填写姓名、登录邮箱等必填字段,并点击确认按钮。 169 | 系统弹出二次确认窗口,显示“确认创建该账号?账号一旦创建成功即会邮件通知对应用户”信息。 170 | 用户点击确认按钮,系统创建账号并发送通知邮件给对应用户。 171 | 系统显示“账号创建成功”信息并返回账号管理页面。 172 | 173 | 备选成功场景: 174 | 175 | 用户在填写必填字段时未填写完整,点击确认按钮后系统弹出错误提醒“请完成所有必填字段的填写!”。 176 | 用户在二次确认窗口点击取消按钮,系统返回账号填写页面。 177 | 用户在填写过程中选择关闭弹出窗口,系统不做任何操作。 178 | 179 | 验收标准: 180 | 181 | 用户可成功填写必填字段并创建账号。 182 | 系统能够正确发送通知邮件给对应用户。 183 | 用户在填写必填字段时未填写完整时,系统能够正确提示错误信息。 184 | 用户在二次确认窗口点击取消按钮时,系统能够正确返回账号填写页面。 185 | 用户关闭弹出窗口或取消操作后,系统不做任何不必要的操作。 186 | 187 | -------------------------------------------------------------------------------- /codeai.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "source": [ 6 | "6B 体积(模型大小 14.3 G,macbook pro 似乎跑不动):\n", 7 | "\n", 8 | "- Salesforce 模型:https://huggingface.co/Salesforce/codegen-6B-mono\n", 9 | "- CarpserAI: https://huggingface.co/CarperAI/diff-codegen-6b-v2\n", 10 | "\n", 11 | "2B 模型(模型大小 5.7 G,macbook pro 似乎跑不动)::\n", 12 | "\n", 13 | "- Salesforce 模型:https://huggingface.co/Salesforce/codegen-2B-mono\n", 14 | "- CarpserAI: https://huggingface.co/CarperAI/diff-codegen-2b-v2\n", 15 | "\n", 16 | "350M(模型大小 784 M,macbook pro 可以跑):\n", 17 | "\n", 18 | "- Salesforce 模型:https://huggingface.co/Salesforce/codegen-350M-mono\n", 19 | "- CarpserAI 模型:https://huggingface.co/CarperAI/diff-codegen-350M-v2\n", 20 | "\n", 21 | "我看到的最好的是 Salesforce 模型,但是它的体积太大了,所以我改用 CarpserAI 的模型,基于 Salesforce 做了优化。" 22 | ], 23 | "metadata": { 24 | "collapsed": false 25 | } 26 | }, 27 | { 28 | "cell_type": "code", 29 | "execution_count": 3, 30 | "outputs": [ 31 | { 32 | "name": "stdout", 33 | "output_type": "stream", 34 | "text": [ 35 | "Looking in indexes: https://testpypi.python.org/pypi\r\n", 36 | "Collecting transformers\r\n", 37 | " Downloading https://test-files.pythonhosted.org/packages/18/18/2dab068a2f5dee0d0b97a5c51b57243884aff0c1d7381c4febea27dc9ccc/transformers-4.26.1.2-py3-none-any.whl (6.3 MB)\r\n", 38 | "\u001B[K |████████████████████████████████| 6.3 MB 50 kB/s eta 0:00:012\r\n", 39 | "\u001B[?25hRequirement already satisfied: requests in /usr/local/anaconda3/lib/python3.9/site-packages (from transformers) (2.26.0)\r\n", 40 | "Requirement already satisfied: regex!=2019.12.17 in /usr/local/anaconda3/lib/python3.9/site-packages (from transformers) (2021.8.3)\r\n", 41 | "Requirement already satisfied: filelock in /usr/local/anaconda3/lib/python3.9/site-packages (from transformers) (3.3.1)\r\n", 42 | "\u001B[31mERROR: Could not find a version that satisfies the requirement huggingface-hub<1.0,>=0.11.0 (from transformers) (from versions: none)\u001B[0m\r\n", 43 | "\u001B[31mERROR: No matching distribution found for huggingface-hub<1.0,>=0.11.0\u001B[0m\r\n" 44 | ] 45 | } 46 | ], 47 | "source": [ 48 | "## 安装 Transformers\n", 49 | "\n", 50 | "!pip install -i https://testpypi.python.org/pypi transformers" 51 | ], 52 | "metadata": { 53 | "collapsed": false 54 | } 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": 4, 59 | "outputs": [ 60 | { 61 | "name": "stdout", 62 | "output_type": "stream", 63 | "text": [ 64 | "Traceback (most recent call last):\r\n", 65 | " File \"\", line 1, in \r\n", 66 | "ModuleNotFoundError: No module named 'transformers'\r\n", 67 | "Traceback (most recent call last):\r\n", 68 | " File \"\", line 1, in \r\n", 69 | "ModuleNotFoundError: No module named 'transformers'\r\n" 70 | ] 71 | } 72 | ], 73 | "source": [ 74 | "# 测试安装\n", 75 | "\n", 76 | "!python -c \"from transformers import pipeline; classifier = pipeline('text-classification'); print(classifier('What a nice release'))\"\n", 77 | "!python -c \"from transformers import *\"" 78 | ], 79 | "metadata": { 80 | "collapsed": false 81 | } 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": 4, 86 | "outputs": [ 87 | { 88 | "name": "stderr", 89 | "output_type": "stream", 90 | "text": [ 91 | "The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n", 92 | "Setting `pad_token_id` to `eos_token_id`:50256 for open-end generation.\n" 93 | ] 94 | }, 95 | { 96 | "name": "stdout", 97 | "output_type": "stream", 98 | "text": [ 99 | "def hello_world() {\n", 100 | " return \"Hello World!\"\n", 101 | "\n", 102 | "def hello_world_with_params(name, age, gender):\n", 103 | " return f\"Hello {name} you are {age} years old and you are {gender}.\"\n", 104 | "\n", 105 | "def hello_world_with_params_and_return(name, age, gender):\n", 106 | " return f\"Hello {name} you are {age} years old and you are {gender}.\"\n", 107 | "\n", 108 | "def hello_world_with_params_and_return_and_return(name, age, gender):\n", 109 | " return f\"Hello\n" 110 | ] 111 | } 112 | ], 113 | "source": [ 114 | "from transformers import AutoTokenizer, AutoModelForCausalLM\n", 115 | "\n", 116 | "# 可以直接从服务器端下载\n", 117 | "# tokenizer = AutoTokenizer.from_pretrained(\"Salesforce/codegen-6B-mono\")\n", 118 | "# model = AutoModelForCausalLM.from_pretrained(\"Salesforce/codegen-6B-mono\")\n", 119 | "\n", 120 | "# 或者用下载到本地的版本\n", 121 | "# git lfs install\n", 122 | "# git clone https://huggingface.co/Salesforce/codegen-350M-mono\n", 123 | "#\n", 124 | "tokenizer = AutoTokenizer.from_pretrained(\"/Volumes/game/ai-research/codegen-350M-mono\")\n", 125 | "model = AutoModelForCausalLM.from_pretrained(\"/Volumes/game/ai-research/codegen-350M-mono\")\n", 126 | "\n", 127 | "text = \"def hello_world() {\"\n", 128 | "input_ids = tokenizer(text, return_tensors=\"pt\").input_ids\n", 129 | "\n", 130 | "generated_ids = model.generate(input_ids, max_length=128)\n", 131 | "print(tokenizer.decode(generated_ids[0], skip_special_tokens=True))" 132 | ], 133 | "metadata": { 134 | "collapsed": false 135 | } 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": 3, 140 | "outputs": [ 141 | { 142 | "name": "stderr", 143 | "output_type": "stream", 144 | "text": [ 145 | "The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n", 146 | "Setting `pad_token_id` to `eos_token_id`:50256 for open-end generation.\n" 147 | ] 148 | }, 149 | { 150 | "name": "stdout", 151 | "output_type": "stream", 152 | "text": [ 153 | "def hello_world() {\n", 154 | " return \"Hello, World!\";\n", 155 | "}\n", 156 | "\n", 157 | "\"\"\"\n", 158 | "\n", 159 | "# The function name must be the same as the function definition\n", 160 | "# The function body must be indented\n", 161 | "# The function name must be followed by a colon (:)\n", 162 | "# The function body must be indented\n", 163 | "# The function name must be followed by a colon (:)\n", 164 | "# The function body must be indented\n", 165 | "# The function name must be followed by a colon (:)\n", 166 | "# The function body must be indented\n", 167 | "# The function name must be followed by a colon (:)\n", 168 | "#\n" 169 | ] 170 | } 171 | ], 172 | "source": [ 173 | "from transformers import AutoTokenizer, AutoModelForCausalLM\n", 174 | "\n", 175 | "tokenizer = AutoTokenizer.from_pretrained(\"/Volumes/game/ai-research/codegen-2B-mono\")\n", 176 | "model = AutoModelForCausalLM.from_pretrained(\"/Volumes/game/ai-research/codegen-2B-mono\")\n", 177 | "\n", 178 | "text = \"def hello_world() {\"\n", 179 | "input_ids = tokenizer(text, return_tensors=\"pt\").input_ids\n", 180 | "\n", 181 | "generated_ids = model.generate(input_ids, max_length=128)\n", 182 | "print(tokenizer.decode(generated_ids[0], skip_special_tokens=True))" 183 | ], 184 | "metadata": { 185 | "collapsed": false 186 | } 187 | }, 188 | { 189 | "cell_type": "code", 190 | "execution_count": null, 191 | "outputs": [], 192 | "source": [], 193 | "metadata": { 194 | "collapsed": false 195 | } 196 | } 197 | ], 198 | "metadata": { 199 | "kernelspec": { 200 | "display_name": "Python 3", 201 | "language": "python", 202 | "name": "python3" 203 | }, 204 | "language_info": { 205 | "codemirror_mode": { 206 | "name": "ipython", 207 | "version": 2 208 | }, 209 | "file_extension": ".py", 210 | "mimetype": "text/x-python", 211 | "name": "python", 212 | "nbconvert_exporter": "python", 213 | "pygments_lexer": "ipython2", 214 | "version": "2.7.6" 215 | } 216 | }, 217 | "nbformat": 4, 218 | "nbformat_minor": 0 219 | } 220 | -------------------------------------------------------------------------------- /codeai.py: -------------------------------------------------------------------------------- 1 | from transformers import AutoTokenizer, AutoModelForCausalLM 2 | 3 | # 可以直接从服务器端下载 4 | # tokenizer = AutoTokenizer.from_pretrained("Salesforce/codegen-6B-mono") 5 | # model = AutoModelForCausalLM.from_pretrained("Salesforce/codegen-6B-mono") 6 | 7 | # 或者用下载到本地的版本 8 | tokenizer = AutoTokenizer.from_pretrained("/Volumes/game/codeai/ai-research/diff-codegen-6b-v2") 9 | model = AutoModelForCausalLM.from_pretrained("/Volumes/game/codeai/ai-research/diff-codegen-6b-v2") 10 | 11 | text = "def hello_world():" 12 | input_ids = tokenizer(text, return_tensors="pt").input_ids 13 | 14 | generated_ids = model.generate(input_ids, max_length=128) 15 | print(tokenizer.decode(generated_ids[0], skip_special_tokens=True)) 16 | -------------------------------------------------------------------------------- /codeai/README.md: -------------------------------------------------------------------------------- 1 | # 代码生成 2 | 3 | 模型:https://huggingface.co/Salesforce/codegen-6B-mono 4 | 5 | CarpserAI: https://huggingface.co/CarperAI/diff-codegen-6b-v2 6 | 7 | 安装 Transformers: 8 | 9 | ```bash 10 | pip install -i https://testpypi.python.org/pypi transformers 11 | ``` 12 | 13 | 测试安装: 14 | 15 | ``` 16 | python -c "from transformers import pipeline; classifier = pipeline('text-classification'); print(classifier('What a nice release'))" 17 | ``` 18 | 19 | 代码: 20 | 21 | 测试代码: 22 | 23 | ```python 24 | from transformers import AutoTokenizer, AutoModelForCausalLM 25 | tokenizer = AutoTokenizer.from_pretrained("Salesforce/codegen-6B-mono") 26 | model = AutoModelForCausalLM.from_pretrained("Salesforce/codegen-6B-mono") 27 | 28 | text = "def hello_world():" 29 | input_ids = tokenizer(text, return_tensors="pt").input_ids 30 | 31 | generated_ids = model.generate(input_ids, max_length=128) 32 | print(tokenizer.decode(generated_ids[0], skip_special_tokens=True)) 33 | ``` 34 | -------------------------------------------------------------------------------- /demo/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /demo/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.jetbrains.kotlin.gradle.tasks.KotlinCompile 2 | 3 | plugins { 4 | id("org.springframework.boot") version "3.0.2" 5 | id("io.spring.dependency-management") version "1.1.0" 6 | kotlin("jvm") version "1.7.22" 7 | kotlin("plugin.spring") version "1.7.22" 8 | } 9 | 10 | group = "com.phodal.aisample" 11 | version = "0.0.1-SNAPSHOT" 12 | java.sourceCompatibility = JavaVersion.VERSION_17 13 | 14 | repositories { 15 | mavenCentral() 16 | } 17 | 18 | dependencies { 19 | implementation("org.springframework.boot:spring-boot-starter-web") 20 | implementation("com.fasterxml.jackson.module:jackson-module-kotlin") 21 | implementation("org.jetbrains.kotlin:kotlin-reflect") 22 | implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") 23 | developmentOnly("org.springframework.boot:spring-boot-devtools") 24 | testImplementation("org.springframework.boot:spring-boot-starter-test") 25 | } 26 | 27 | tasks.withType { 28 | kotlinOptions { 29 | freeCompilerArgs = listOf("-Xjsr305=strict") 30 | jvmTarget = "17" 31 | } 32 | } 33 | 34 | tasks.withType { 35 | useJUnitPlatform() 36 | } 37 | -------------------------------------------------------------------------------- /demo/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/demo/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /demo/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /demo/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Stop when "xargs" is not available. 209 | if ! command -v xargs >/dev/null 2>&1 210 | then 211 | die "xargs is not available" 212 | fi 213 | 214 | # Use "xargs" to parse quoted args. 215 | # 216 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 217 | # 218 | # In Bash we could simply go: 219 | # 220 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 221 | # set -- "${ARGS[@]}" "$@" 222 | # 223 | # but POSIX shell has neither arrays nor command substitution, so instead we 224 | # post-process each arg (as a line of input to sed) to backslash-escape any 225 | # character that might be a shell metacharacter, then use eval to reverse 226 | # that process (while maintaining the separation between arguments), and wrap 227 | # the whole thing up as a single "set" statement. 228 | # 229 | # This will of course break if any of these variables contains a newline or 230 | # an unmatched quote. 231 | # 232 | 233 | eval "set -- $( 234 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 235 | xargs -n1 | 236 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 237 | tr '\n' ' ' 238 | )" '"$@"' 239 | 240 | exec "$JAVACMD" "$@" 241 | -------------------------------------------------------------------------------- /demo/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if %ERRORLEVEL% equ 0 goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if %ERRORLEVEL% equ 0 goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | set EXIT_CODE=%ERRORLEVEL% 84 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 85 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 86 | exit /b %EXIT_CODE% 87 | 88 | :mainEnd 89 | if "%OS%"=="Windows_NT" endlocal 90 | 91 | :omega 92 | -------------------------------------------------------------------------------- /demo/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "demo" 2 | -------------------------------------------------------------------------------- /demo/src/main/kotlin/com/phodal/aisample/demo/CinemaScheduleService.kt: -------------------------------------------------------------------------------- 1 | package com.phodal.aisample.demo 2 | 3 | import org.springframework.stereotype.Service 4 | 5 | @Service 6 | class CinemaScheduleService { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /demo/src/main/kotlin/com/phodal/aisample/demo/DemoApplication.kt: -------------------------------------------------------------------------------- 1 | package com.phodal.aisample.demo 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication 4 | import org.springframework.boot.runApplication 5 | 6 | @SpringBootApplication 7 | class DemoApplication 8 | 9 | fun main(args: Array) { 10 | runApplication(*args) 11 | } 12 | -------------------------------------------------------------------------------- /demo/src/main/kotlin/com/phodal/aisample/demo/NotScheduleAvailableException.kt: -------------------------------------------------------------------------------- 1 | package com.phodal.aisample.demo 2 | 3 | class NotScheduleAvailableException : Exception() { 4 | } 5 | -------------------------------------------------------------------------------- /demo/src/main/kotlin/com/phodal/aisample/demo/NotSeatAvailableException.kt: -------------------------------------------------------------------------------- 1 | class NotSeatAvailableException : RuntimeException() { 2 | override val message: String? 3 | get() = "No seat avaliable" 4 | } 5 | -------------------------------------------------------------------------------- /demo/src/main/kotlin/com/phodal/aisample/demo/TickerOrderApplicationService.kt: -------------------------------------------------------------------------------- 1 | package com.phodal.aisample.demo 2 | 3 | class TickerOrderApplicationService { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /demo/src/main/kotlin/com/phodal/aisample/demo/TicketController.kt: -------------------------------------------------------------------------------- 1 | package com.phodal.aisample.demo 2 | 3 | import org.springframework.web.bind.annotation.PostMapping 4 | import org.springframework.web.bind.annotation.RequestBody 5 | import org.springframework.web.bind.annotation.RequestMapping 6 | import org.springframework.web.bind.annotation.RestController 7 | 8 | 9 | 10 | /** 11 | * all apis 12 | * | API | 描述 | HTTP方法 | URL | 参数 | 返回值 | 13 | * |--------|----------------|--------|-----------------------------------------------|--------|-------------| 14 | * | 创建订单 | 创建一个新的订单 | POST | /ticket-orders | 创建订单信息 | 订单ID | 15 | * | 查询订单 | 查询一个已存在的订单 | GET | /ticket-orders/{orderId} | 订单ID | 订单信息 | 16 | * | 取消订单 | 取消一个已存在的订单 | DELETE | /ticket-orders/{orderId} | 订单ID | 取消成功或失败信息 | 17 | * | 添加座位 | 向一个已存在的订单添加座位 | POST | /ticket-orders/{orderId}/seats | 座位信息 | 座位添加成功或失败信息 | 18 | * | 移除座位 | 从一个已存在的订单中移除座位 | DELETE | /ticket-orders/{orderId}/seats/{seatId} | 座位ID | 座位移除成功或失败信息 | 19 | * | 查询可用座位 | 查询某个场次电影的可用座位 | GET | /cinema-schedule/{scheduleId}/available-seats | 场次ID | 可用座位信息 | 20 | */ 21 | @RestController 22 | @RequestMapping("ticket-orders") 23 | class TicketController( 24 | val ticketService: TicketService, 25 | val tickerOrderApplicationService: TickerOrderApplicationService, 26 | val cinemaScheduleService: CinemaScheduleService 27 | ) { 28 | @PostMapping 29 | fun createTicketOrder(@RequestBody ticketOrder: TicketOrder): String { 30 | // check the schedule is valid, the seats are available, then create the order, if the schedule is not valid, throw NotScheduleAvailableException 31 | // check the schedule is valid 32 | val schedule = cinemaScheduleService.getSchedule(ticketOrder.scheduleId) 33 | if (schedule == null) { 34 | throw NotScheduleAvailableException() 35 | } 36 | // check the seats are available 37 | val availableSeats = cinemaScheduleService.getAvailableSeats(ticketOrder.scheduleId) 38 | if (!availableSeats.containsAll(ticketOrder.seats)) { 39 | throw NotSeatAvailableException() 40 | } 41 | // create order 42 | return tickerOrderApplicationService.createOrder(ticketOrder) 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /demo/src/main/kotlin/com/phodal/aisample/demo/TicketOrder.kt: -------------------------------------------------------------------------------- 1 | package com.phodal.aisample.demo 2 | 3 | class TicketOrder { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /demo/src/main/kotlin/com/phodal/aisample/demo/TicketRepository.kt: -------------------------------------------------------------------------------- 1 | package com.phodal.aisample.demo 2 | 3 | import org.springframework.stereotype.Repository 4 | 5 | @Repository 6 | interface TicketRepository { 7 | fun createTicketOrder(ticketOrder: TicketOrder): String 8 | 9 | fun getTicketOrder(orderId: String): TicketOrder 10 | } 11 | -------------------------------------------------------------------------------- /demo/src/main/kotlin/com/phodal/aisample/demo/TicketService.kt: -------------------------------------------------------------------------------- 1 | package com.phodal.aisample.demo 2 | 3 | import org.springframework.stereotype.Service 4 | 5 | @Service 6 | class TicketService( 7 | val repository: TicketRepository 8 | ) { 9 | fun createTicketOrder(ticketOrder: TicketOrder): String { 10 | 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/src/test/kotlin/com/phodal/aisample/demo/DemoApplicationTests.kt: -------------------------------------------------------------------------------- 1 | package com.phodal.aisample.demo 2 | 3 | import org.junit.jupiter.api.Test 4 | import org.springframework.boot.test.context.SpringBootTest 5 | 6 | @SpringBootTest 7 | class DemoApplicationTests { 8 | 9 | @Test 10 | fun contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /image2txt.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "outputs": [ 7 | { 8 | "name": "stderr", 9 | "output_type": "stream", 10 | "text": [ 11 | "/Users/phodal/opt/anaconda3/lib/python3.9/site-packages/transformers/generation/utils.py:1387: UserWarning: Neither `max_length` nor `max_new_tokens` has been set, `max_length` will default to 20 (`self.config.max_length`). Controlling `max_length` via the config is deprecated and `max_length` will be removed from the config in v5 of Transformers -- we recommend using `max_new_tokens` to control the maximum length of the generation.\n", 12 | " warnings.warn(\n" 13 | ] 14 | }, 15 | { 16 | "data": { 17 | "text/plain": "[{'generated_text': 'a woman in a bikini standing on a beach '}]" 18 | }, 19 | "execution_count": 1, 20 | "metadata": {}, 21 | "output_type": "execute_result" 22 | } 23 | ], 24 | "source": [ 25 | "from transformers import pipeline\n", 26 | "\n", 27 | "image_to_text = pipeline(\"image-to-text\", model=\"/Volumes/game/ai-research/vit-gpt2-image-captioning\")\n", 28 | "\n", 29 | "image_to_text(\"output/better.jpeg\")\n", 30 | "\n", 31 | "# [{'generated_text': 'a woman in a bikini standing on a beach '}]\n" 32 | ], 33 | "metadata": { 34 | "collapsed": false 35 | } 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": null, 40 | "outputs": [], 41 | "source": [], 42 | "metadata": { 43 | "collapsed": false 44 | } 45 | } 46 | ], 47 | "metadata": { 48 | "kernelspec": { 49 | "display_name": "Python 3", 50 | "language": "python", 51 | "name": "python3" 52 | }, 53 | "language_info": { 54 | "codemirror_mode": { 55 | "name": "ipython", 56 | "version": 2 57 | }, 58 | "file_extension": ".py", 59 | "mimetype": "text/x-python", 60 | "name": "python", 61 | "nbconvert_exporter": "python", 62 | "pygments_lexer": "ipython2", 63 | "version": "2.7.6" 64 | } 65 | }, 66 | "nbformat": 4, 67 | "nbformat_minor": 0 68 | } 69 | -------------------------------------------------------------------------------- /images/chatgpt-article-demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/images/chatgpt-article-demo.png -------------------------------------------------------------------------------- /images/chatgpt-ddd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/images/chatgpt-ddd.png -------------------------------------------------------------------------------- /images/ddd-copilot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/images/ddd-copilot-1.png -------------------------------------------------------------------------------- /images/ddd-copilot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/images/ddd-copilot.png -------------------------------------------------------------------------------- /images/focus-driven.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/images/focus-driven.png -------------------------------------------------------------------------------- /images/github-copilot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/images/github-copilot-1.png -------------------------------------------------------------------------------- /images/github-sample-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/images/github-sample-2.png -------------------------------------------------------------------------------- /images/github-sample-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/images/github-sample-3.png -------------------------------------------------------------------------------- /images/github-sample-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/images/github-sample-4.png -------------------------------------------------------------------------------- /images/github-sample-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/images/github-sample-5.png -------------------------------------------------------------------------------- /images/hand-final-result.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/images/hand-final-result.jpeg -------------------------------------------------------------------------------- /images/stable-diffusion-hug8217.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/images/stable-diffusion-hug8217.jpeg -------------------------------------------------------------------------------- /images/stable-diffusion-overview.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/images/stable-diffusion-overview.jpeg -------------------------------------------------------------------------------- /images/stable-diffusion-with-controlnet-dreambooth.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/images/stable-diffusion-with-controlnet-dreambooth.jpeg -------------------------------------------------------------------------------- /images/stable-diffusion-with-controlnet.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/images/stable-diffusion-with-controlnet.jpeg -------------------------------------------------------------------------------- /images/stable-diffusion-with-negative.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/images/stable-diffusion-with-negative.jpeg -------------------------------------------------------------------------------- /images/strategy/sample-output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/images/strategy/sample-output.png -------------------------------------------------------------------------------- /images/try-fix-hands.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/images/try-fix-hands.jpeg -------------------------------------------------------------------------------- /output/better.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/output/better.jpeg -------------------------------------------------------------------------------- /output/chatgpt-writing-article.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/output/chatgpt-writing-article.png -------------------------------------------------------------------------------- /output/failure-seeds.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/output/failure-seeds.jpeg -------------------------------------------------------------------------------- /output/failure-with-hand-hair.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/output/failure-with-hand-hair.jpeg -------------------------------------------------------------------------------- /output/image-with-canny.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/output/image-with-canny.jpeg -------------------------------------------------------------------------------- /output/image-with-hed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/output/image-with-hed.png -------------------------------------------------------------------------------- /output/image-with-openpose.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/output/image-with-openpose.jpeg -------------------------------------------------------------------------------- /output/sample.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/output/sample.jpg -------------------------------------------------------------------------------- /output/samples/01.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/output/samples/01.jpeg -------------------------------------------------------------------------------- /output/samples/02.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/output/samples/02.jpeg -------------------------------------------------------------------------------- /output/samples/03.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/output/samples/03.jpeg -------------------------------------------------------------------------------- /output/samples/04.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/output/samples/04.jpeg -------------------------------------------------------------------------------- /output/samples/05.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/output/samples/05.jpeg -------------------------------------------------------------------------------- /output/samples/06.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/output/samples/06.jpeg -------------------------------------------------------------------------------- /output/samples/07.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/output/samples/07.jpeg -------------------------------------------------------------------------------- /output/samples/08.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/output/samples/08.jpeg -------------------------------------------------------------------------------- /output/with-prompt.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/output/with-prompt.jpeg -------------------------------------------------------------------------------- /output/women-backview-1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/output/women-backview-1.jpeg -------------------------------------------------------------------------------- /output/women-backview-2.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/output/women-backview-2.jpeg -------------------------------------------------------------------------------- /output/women-backview-3.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/output/women-backview-3.jpeg -------------------------------------------------------------------------------- /output/women-backview-4.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/output/women-backview-4.jpeg -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | transformers==4.25.1 2 | shap==0.41.0 -------------------------------------------------------------------------------- /stable-diffusion/README.md: -------------------------------------------------------------------------------- 1 | # Stable Diffusion 简易指北 2 | 3 | PS:文末有恐怖片,可以滑慢一点。 4 | 5 | This is a style guide for the Stable Diffusion project. It is a living document, and will be updated as the project evolves. 6 | 7 | ![](styles.csv) 8 | 9 | ## Stable Diffusion 思路 10 | 11 | 基本思路:Goal -> Style -> ZeroShot/Few Shot -> Negative Prompt 12 | 13 | 1. Goal: 14 | - a photo, 15 | - a painting, 16 | - a sculpture, 17 | - a 3D rendering, etc. 18 | 2. Style:诸如于动漫(Anime)、半写实、写实、真人等等 19 | 3. 开始模式:ZeroShot/FewShot,以获得更多的灵感 20 | 4. 精炼 Prompt 21 | - 反复尝试 Prompt 22 | - 添加 Negative Prompt 23 | - 使用 seed 重新运行 24 | 25 | ## 安装 26 | 27 | ### 本地安装 28 | 29 | 直接安装 Web UI 界面,详细参见文档:[https://github.com/AUTOMATIC1111/stable-diffusion-webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui) ,对应有文档 30 | 31 | 推荐插件: 32 | 33 | - 精准控线 ControlNet:https://github.com/Mikubill/sd-webui-controlnet 34 | - 国际化 - 中文翻译? 35 | - …… 36 | 37 | ### AutoDL 云服务 38 | 39 | 推荐原因:便宜,可以直接用镜像 40 | 41 | 不推荐原因:容易丢机器(关机就没了)、镜像有时候速度慢 42 | 43 | 下载数据:官方说:直接从官方下载文档不行,建议使用网盘:[https://www.autodl.com/docs/down/](https://www.autodl.com/docs/down/)。我使用的是新出的阿里云盘,当前还没有限速,上传和下载速度还不错。 44 | 45 | Stable Diffiusion WebUI 中文版本: 46 | 47 | - AutoDL 镜像:https://www.codewithgpu.com/i/AUTOMATIC1111/stable-diffusion-webui/sd-webui-230220 48 | 49 | 可用于训练的镜像: 50 | 51 | 老版本:https://www.codewithgpu.com/i/CrazyBoyM/sd_dreambooth_extension_webui/dreambooth-dreamartist-for-webui 52 | 53 | 54 | ## Google Colab 55 | 56 | 在线生成 Colab:https://github.com/nolanaatama/sd-1click-colab 57 | 58 | 我使用了 Google Colab 训练了第一个版本,毕竟可以免费白嫖。 59 | 60 | DreamBooth 训练: 61 | 62 | https://colab.research.google.com/github/ShivamShrirao/diffusers/blob/main/examples/dreambooth/DreamBooth_Stable_Diffusion.ipynb 63 | 64 | DreamBooth Lora 训练: 65 | 66 | https://colab.research.google.com/github/Linaqruf/kohya-trainer/blob/main/kohya-LoRA-dreambooth.ipynb 67 | 68 | ### Mix 69 | 70 | ![](images/mix.png) 71 | 72 | ## Prompt Examples 73 | 74 | ### FewShot 示例 75 | 76 | prompt: solo, 1 gril, young women smell flowers, long skirt, 77 | 78 | negative: 79 | 80 | (pubic hair:2), paintings, sketches, (worst quality:2), (low quality:2), (normal quality:2), lowres, normal quality, ((monochrome:1.5)), ((grayscale)), skin spots, acnes, skin blemishes, age spot, (outdoor:1.6), manboobs, backlight,(ugly:1.331), (duplicate:1.331), (morbid:1.21), (mutilated:1.21), (tranny:1.331), mutated hands, (poorly drawn hands:1.331), blurry, (bad anatomy:1.21), (bad proportions:1.331), extra limbs, (disfigured:1.331), (more than 2 nipples:1.331), (missing arms:1.331), (extra legs:1.331), (fused fingers:1.61051), (too many fingers:1.61051), (unclear eyes:1.331), lowers, bad hands, missing fingers, extra digit, (futa:1.1), logo, white letters,missing fingers, extra digit, fewer digits,(mutated hands and fingers:1.5 ), (long body :1.3),bad hands, fused hand, missing hand, disappearing arms, error, missing fingers, missing limb,fused fingers, one hand with more than 5 fingers, one hand with less than 5 fingers, one hand with morethan 5 digit, one hand with less than 5 digit, extra digit, fewer digits, fused digit, missing digit,text,watermark 81 | 82 | ## 恐怖片 83 | 84 | ### 咒语 85 | 86 | 参数: 87 | 88 | Steps: 30, Sampler: DPM++ SDE Karras, CFG scale: 7, Seed: 4213714763, Size: 512x512, Model hash: 1e46fca6b5, Model: huazhongma_1000 89 | 90 | 91 | Prompt 92 | 93 | ``` 94 | {{dresses}}, {{masterpiece}}, best quality, illustration, {half body on a girl}, beautiful detailed blue eyes, cinematic lighting, dramatic angle, black and red hair, High ponytail, {beautiful, detailed sky}, { cinematic lighting}, High ponytail hairstyle, blue flower, earring, outdoor, Tresses of silk, in gentle breeze dance from ethereal chance. An aura of peace, in each strand of hair, beyond compare, cinematic lighting, dramatic angle, 95 | ``` 96 | 97 | Negative 98 | 99 | 100 | ``` 101 | obese, (ugly:1.3), (duplicate:1.3), (morbid), (mutilated), out of frame, extra fingers, mutated hands, (poorly drawn hands), (poorly drawn face), (mutation:1.3), (deformed:1.3), (amputee:1.3), blurry, bad anatomy, bad proportions, (extra limbs), cloned face, (disfigured:1.3), gross proportions, (malformed limbs), (missing arms), (missing legs), (extra arms), (extra legs), mutated hands, (fused fingers), (too many fingers), (long neck:1.3), lowres, text, error, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, black and white, monochrome, censored, empty, large breast, medium breast, breast, extract legs, 102 | ``` 103 | 104 | 结果: 105 | 106 | 高分辨率(HiRes)修复失败,出现了双胞胎,还挺好玩的: 107 | 108 | ![](images/hires-failure.jpeg) 109 | 110 | 当然了,还会有,手、手,千手观音: 111 | 112 | ![](images/failured-hands.jpeg) 113 | 114 | 飞翔的头: 115 | 116 | ![](images/failure-flying-head.jpeg) 117 | 118 | ![](images/failured-everyway-head.jpeg) 119 | 120 | 121 | -------------------------------------------------------------------------------- /stable-diffusion/ai-ethics.md: -------------------------------------------------------------------------------- 1 | # AI 伦理 2 | 3 | ## 问题 4 | 5 | ### 著作权:Prompt 是否有版权? 6 | 7 | ## 基础伦理 8 | 9 | ## 著作权:文本生成 10 | 11 | ## 肖像权:图形生成 12 | 13 | ## 复杂伦理问题 14 | 15 | ### 图形的繁殖:两个混合肖像 16 | 17 | 众所周知,在遗留学中,父母的长相可能会对儿子的长相产生一定的影响,但这种影响是非常复杂和多变的,并不能简单地用直接影响来描述。 18 | 19 | 但是,对于 AI 来说,你构建出由两人头像,相当的可怕。 20 | 21 | -------------------------------------------------------------------------------- /stable-diffusion/chtgpt-v50.md: -------------------------------------------------------------------------------- 1 | 我们能玩一个名为 crazyV50 的谜语写作游戏,当我说 crazyV50,你开始写作(不少于 200 字),正文不能出现肯德基。 2 | 3 | 格式类似于: 4 | 5 | """ 6 | 正文:{} 7 | 谜底:原来今天是肯德基疯狂星期四!! 8 | """ 9 | 10 | 示例 11 | 12 | 13 | """ 14 | 正文:清晨,门店前就已经排起了长队,等待着店员打开大门。一打开,一阵炸鸡香味扑鼻而来,人们不由自主地加快了脚步。店员们手忙脚乱地忙碌着,为了满足食客们的需求。大家都兴高采烈地享受着这个独特的节日,笑声和欢呼声不断响起。 15 | 16 | 谜底:原来今天是肯德基疯狂星期四!! 17 | """ -------------------------------------------------------------------------------- /stable-diffusion/guofeng/README.md: -------------------------------------------------------------------------------- 1 | Case 1: 2 | 3 | 1girl, long_hair, solo, upper_body, china dress,dress,hair ornament, necklace, jewelry, long hair, earrings, chinese clothes,black and red hair, High ponytail, {beautiful, detailed sky}, { cinematic lighting}, High ponytail hairstyle, Tresses of silk, in gentle breeze dance from ethereal chance. An aura of peace, { arms behind back } 4 | Negative prompt: (((simple background))),monochrome ,lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, lowres, bad anatomy, bad hands, text, error, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, ugly,pregnant,vore,duplicate,morbid,mut ilated,tran nsexual, hermaphrodite,long neck,mutated hands,poorly drawn hands,poorly drawn face,mutation,deformed,blurry,bad anatomy,bad proportions,malformed limbs,extra limbs,cloned face,disfigured,gross proportions, (((missing arms))),(((missing legs))), (((extra arms))),(((extra legs))),pubic hair, plump,bad legs,error legs,username,blurry,bad feet,medium breasts, large breasts, large breasts, 5 | Steps: 30, Sampler: Euler a, CFG scale: 7, Seed: 3416674076, Face restoration: CodeFormer, Size: 960x640, Model hash: 66d35b83b6, Model: hzmguofeng_1000, Denoising strength: 0.7, Hires upscale: 2, Hires upscaler: Latent 6 | 7 | 8 | Case 2: 9 | 10 | 1girl, long_hair, solo, upper_body, china dress,dress,hair ornament, necklace, jewelry, long hair, earrings, chinese clothes,black and red hair, High ponytail, {beautiful, detailed sky}, { cinematic lighting}, High ponytail hairstyle, Tresses of silk, in gentle breeze dance from ethereal chance. An aura of peace, { arms behind back } 11 | Negative prompt: (((simple background))),monochrome ,lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, lowres, bad anatomy, bad hands, text, error, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, ugly,pregnant,vore,duplicate,morbid,mut ilated,tran nsexual, hermaphrodite,long neck,mutated hands,poorly drawn hands,poorly drawn face,mutation,deformed,blurry,bad anatomy,bad proportions,malformed limbs,extra limbs,cloned face,disfigured,gross proportions, (((missing arms))),(((missing legs))), (((extra arms))),(((extra legs))),pubic hair, plump,bad legs,error legs,username,blurry,bad feet,medium breasts, large breasts, large breasts, 12 | Steps: 30, Sampler: Euler a, CFG scale: 7, Seed: 3416674061, Face restoration: CodeFormer, Size: 960x640, Model hash: 66d35b83b6, Model: hzmguofeng_1000, Denoising strength: 0.7, Hires upscale: 2, Hires upscaler: Latent 13 | 14 | General: 15 | 16 | particle effects small breasts, 1 girl, solo, {{masterpiece}}, {best quality},{highres}, original, extremely detailed 8K wallpaper, greasy skin, realistic and delicate facial features, slim waist, overexposure,ultra-detailed,illustration,incredibly_absurdres,ray tracing,intricate detail, colored tips,colored inner hair,aquagradient eyes,gradient eyes,eyelashes,finely detail, depth of field, n gentle breeze dance from ethereal chance. An aura of peace,beyond compare, cinematic lighting, dramatic angle, , upper body 17 | 18 | -------------------------------------------------------------------------------- /stable-diffusion/images/failure-flying-head.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/stable-diffusion/images/failure-flying-head.jpeg -------------------------------------------------------------------------------- /stable-diffusion/images/failured-everyway-head.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/stable-diffusion/images/failured-everyway-head.jpeg -------------------------------------------------------------------------------- /stable-diffusion/images/failured-hands.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/stable-diffusion/images/failured-hands.jpeg -------------------------------------------------------------------------------- /stable-diffusion/images/hires-failure.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/stable-diffusion/images/hires-failure.jpeg -------------------------------------------------------------------------------- /stable-diffusion/images/mix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/stable-diffusion/images/mix.png -------------------------------------------------------------------------------- /stable-diffusion/images/no-negative-lot-of-hands.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/stable-diffusion/images/no-negative-lot-of-hands.png -------------------------------------------------------------------------------- /stable-diffusion/images/opensoe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/stable-diffusion/images/opensoe.png -------------------------------------------------------------------------------- /stable-diffusion/images/with-negative.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/stable-diffusion/images/with-negative.png -------------------------------------------------------------------------------- /stable-diffusion/images/words-with-opensose.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phodal/understand-prompt/d764ea72a82beae76481a3a9285ddc58cba37176/stable-diffusion/images/words-with-opensose.png -------------------------------------------------------------------------------- /stable-diffusion/styles.csv: -------------------------------------------------------------------------------- 1 | name,prompt,negative_prompt 2 | Cartoon,"modelshoot style, (extremely detailed CG unity 8k wallpaper), full shot body photo of the most beautiful artwork in the world, beautiful women, professional majestic oil painting by Ed Blinkey, Atey Ghailan, Studio Ghibli, by Jeremy Mann, Greg Manchess, Antonio Moro, trending on ArtStation, trending on CGSociety, Intricate, High Detail, Sharp focus, dramatic, photorealistic painting art by midjourney and greg rutkowski, ","canvas frame, cartoon, 3d, ((disfigured)), ((bad art)), ((deformed)),((extra limbs)),((close up)),((b&w)), wierd colors, blurry, (((duplicate))), ((morbid)), ((mutilated)), [out of frame], extra fingers, mutated hands, ((poorly drawn hands)), ((poorly drawn face)), (((mutation))), (((deformed))), ((ugly)), blurry, ((bad anatomy)), (((bad proportions))), ((extra limbs)), cloned face, (((disfigured))), out of frame, ugly, extra limbs, (bad anatomy), gross proportions, (malformed limbs), ((missing arms)), ((missing legs)), (((extra arms))), (((extra legs))), mutated hands, (fused fingers), (too many fingers), (((long neck))), Photoshop, video game, ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, mutation, mutated, extra limbs, extra legs, extra arms, disfigured, deformed, cross-eye, body out of frame, blurry, bad art, bad anatomy, 3d render" 3 | Cartoon2,"modelshoot style, (extremely detailed CG unity 8k wallpaper), full shot body photo of the most beautiful artwork in the world, beautiful women, professional majestic oil painting by Ed Blinkey, Atey Ghailan, Studio Ghibli, by Jeremy Mann, Greg Manchess, Antonio Moro, trending on ArtStation, trending on CGSociety, Intricate, High Detail, Sharp focus, dramatic, photorealistic painting art by midjourney and greg rutkowski, ","canvas frame, cartoon, 3d, ((disfigured)), ((bad art)), ((deformed)),((extra limbs)),((close up)),((b&w)), wierd colors, blurry, (((duplicate))), ((morbid)), ((mutilated)), [out of frame], extra fingers, mutated hands, ((poorly drawn hands)), ((poorly drawn face)), (((mutation))), (((deformed))), ((ugly)), blurry, ((bad anatomy)), (((bad proportions))), ((extra limbs)), cloned face, (((disfigured))), out of frame, ugly, extra limbs, (bad anatomy), gross proportions, (malformed limbs), ((missing arms)), ((missing legs)), (((extra arms))), (((extra legs))), mutated hands, (fused fingers), (too many fingers), (((long neck))), Photoshop, video game, ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, mutation, mutated, extra limbs, extra legs, extra arms, disfigured, deformed, cross-eye, body out of frame, blurry, bad art, bad anatomy, 3d render" 4 | Closed Really,"(extremely detailed CG unity 8k wallpaper), full shot body photo of the most beautiful artwork in the world, professional majestic oil painting by Ed Blinkey, Atey Ghailan, Studio Ghibli, by Jeremy Mann, Greg Manchess, trending on ArtStation, trending on CGSociety, Intricate, High Detail, Sharp focus, dramatic, girl, russain girls, black hair, light color in background, ocean background,black dress","canvas frame, cartoon, 3d, ((disfigured)), ((bad art)), ((deformed)),((extra limbs)),((close up)),((b&w)), wierd colors, blurry, (((duplicate))), ((morbid)), ((mutilated)), [out of frame], extra fingers, mutated hands, ((poorly drawn hands)), ((poorly drawn face)), (((mutation))), (((deformed))), ((ugly)), blurry, ((bad anatomy)), (((bad proportions))), ((extra limbs)), cloned face, (((disfigured))), out of frame, ugly, extra limbs, (bad anatomy), gross proportions, (malformed limbs), ((missing arms)), ((missing legs)), (((extra arms))), (((extra legs))), mutated hands, (fused fingers), (too many fingers), (((long neck))), Photoshop, video game, ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, mutation, mutated, extra limbs, extra legs, extra arms, disfigured, deformed, cross-eye, body out of frame, blurry, bad art, bad anatomy, 3d render, two many pople,watermark" 5 | guofeng2,"(masterpiece:1.0), (best quality:1.4), (ultra highres:1.2),4K quality, (delicate illustration:1.4),(8k, RAW photo:1.2),soft focus,(sharp focus:1.4), vibrant colors,high quality, high contrast,gorgeous light and shadow,(best quality),,portrait, (Japanese:1.0),(china:0.5), (Liu Yi Fei:1.3),(1girl),young girl,standing, face focus, exquisite facial features, exquisite hair, exquisite eyes,round eyes and long hair, symmetrical face, perfect skin, volumetric lighting, stunning environment, highly detailed, ultra realistic,hick lips, beautiful lips, symmetry,warm tones, (black hair), intricate hair ornament,stud earrings,bracelets,(choker white:1,1),jewelry,hair decoration,goddess, milf, nude, ","(pussy, pussy juice), puffy nipples, medium nipples, cleavage, symmetry, milf, nsfw, nude, uncensored, underwear,bra, (pussy, pussy juice), puffy nipples, medium nipples, cleavage, symmetry, milf, nsfw, nude, uncensored, underwear,bra, (((simple background))),monochrome ,lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, lowres, bad anatomy, bad hands, text, error, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, ugly,pregnant,vore,duplicate,mut ilated, hermaphrodite,long neck,mutated hands,poorly drawn hands,poorly drawn face,mutation,deformed,blurry,bad anatomy,bad proportions,malformed limbs,extra limbs,cloned face,disfigured,gross proportions, (((missing arms))),(((missing legs))), (((extra arms))),(((extra legs))), bad legs,error legs,username,blurry,bad feet,monochrome,(deformed fingers:1.5),(deformed hands:1.5),(deformed feet:1.5),tooth, decoration skin" 6 | kawayi chinese style,"(best quality),((masterpiece)),(highres), original, (extremely detailed 8K wallpaper), overexposure,1girl,(medium breasts),(an extremely delicate and beautiful),(Beautiful and detailed eye description),(Rimless glasses),(Beautiful and detailed facial depiction),(solo),(upper body), no hand, Rainskirt,hair ornament, necklace, jewelry,earrings,chinese style architecture,wavy hair,messy hair,swept bangs,,masterpiece, best quality, ","(((simple background))),monochrome ,lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, lowres, bad anatomy, bad hands, text, error, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, ugly,pregnant,vore,duplicate,morbid,mut ilated,tran nsexual, hermaphrodite,long neck,mutated hands,poorly drawn hands,poorly drawn face,mutation,deformed,blurry,bad anatomy,bad proportions,malformed limbs,extra limbs,cloned face,disfigured,gross proportions, (((missing arms))),(((missing legs))), (((extra arms))),(((extra legs))),pubic hair, plump,bad legs,error legs,username,blurry,bad feet, lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry " 7 | Guofeng 3,"dramatic angle,(fluttered detailed color splashs), (illustration),(((1 girl))),(long hair),(rain:0.9),(hair ornament:1.4),there is an ancient palace beside the girl,chinese clothes,(focus on), color Ink wash painting,(color splashing),colorful splashing,(((colorful))),(sketch:0.8), Masterpiece,best quality, beautifully painted,highly detailed,(denoising:0.6),[splash ink],((ink refraction)), (beautiful detailed sky),moon,highly,detaild,(masterpiece, best quality, extremely detailed CG unity 8k wallpaper,masterpiece, best quality, ultra-detailed),(Lycoris radiata), ,light smile, china dress","worst quality, (low quality:1.4), (fuze:1.4), (worst quality:1.1), (low quality:1.4:1.1), lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurrypolar,bad body,bad proportions,gross proportions,text,error,missing fingers, missing arms,missing legs, extra digit, extra fingers,fewer digits,extra limbs,extra arms,extra legs,malformed limbs,fused fingers,too many fingers,long neck,cross-eyed,mutated hands, cropped,poorly drawn hands,poorly drawn face,mutation,deformed,worst quality,low quality, normal quality, blurry,ugly,duplicate,morbid,mutilated,out of frame, body out of frame,, (worst quality, low quality:1.4), (fuze:1.4), (worst quality:1.1), (low quality:1.4:1.1), lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurrypolar,bad body,bad proportions,gross proportions,text,error,missing fingers, missing arms,missing legs, extra digit, extra fingers,fewer digits,extra limbs,extra arms,extra legs,malformed limbs,fused fingers,too many fingers,long neck,cross-eyed,mutated hands, cropped,poorly drawn hands,poorly drawn face,mutation,deformed,worst quality,low quality, normal quality, blurry,ugly,duplicate,morbid,mutilated,out of frame, body out of frame, belly button, vaginal ring, neck ring, skin spots, acnes, skin blemishes, age spot, glans, bad-hands-5," 8 | artsE,"{{masterpiece}}, best quality, illustration, {half body on a girl}, beautiful detailed black eyes black hair, Elysian Allure. Tresses of silk, in gentle breeze dance, Emanating shimmer, from ethereal chance. An aura of peace, in each strand of hair, An elegant being, beyond compare, cinematic lighting, dramatic angle, black and red hair, High ponytail, {beautiful, detailed sky}, { cinematic lighting}, High ponytail hairstyle, uniform, {beautiful, detailed water}, blue flower, earring, blue blue sky","obese, (ugly:1.3), (duplicate:1.3), (morbid), (mutilated), out of frame, extra fingers, mutated hands, (poorly drawn hands), (poorly drawn face), (mutation:1.3), (deformed:1.3), (amputee:1.3), blurry, bad anatomy, bad proportions, (extra limbs), cloned face, (disfigured:1.3), gross proportions, (malformed limbs), (missing arms), (missing legs), (extra arms), (extra legs), mutated hands, (fused fingers), (too many fingers), (long neck:1.3), lowres, text, error, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, black and white, monochrome, censored, empty" 9 | hug8217,"closed mouth smile, fall to the shoulders dresses, girl, blue sky background, (modelshoot style:0.9), black eyes, masterpiece, best quality, messy long bangs hair, look at the viewer, (serious: 0.5), (sliver hair: 1.25), high res, depth of field, best quality, highly detailed, smile, ","obese, (ugly:1.3), (duplicate:1.3), (morbid), (mutilated), out of frame, extra fingers, mutated hands, (poorly drawn hands), (poorly drawn face), (mutation:1.3), (deformed:1.3), (amputee:1.3), blurry, bad anatomy, bad proportions, (extra limbs), cloned face, (disfigured:1.3), gross proportions, (malformed limbs), (missing arms), (missing legs), (extra arms), (extra legs), mutated hands, (fused fingers), (too many fingers), (long neck:1.3), lowres, text, error, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, black and white, monochrome, censored,empty" 10 | cartoon style wedding,"best quality, masterpiece, highres, 1 solo smile bride, , wedding Crown, full white wedding dress cover breast, small breast, full white wedding hat veil, closed smile eyes,closed-mouth smile, blush, hand touch dress cover edge, wedding ring, indoor, particle effect,","lowres, bad anatomy, bad hands, text, error, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, ugly,pregnant,vore,duplicate,morbid,mut ilated,tran nsexual, hermaphrodite,long neck,mutated hands,poorly drawn hands,poorly drawn face,mutation,deformed,blurry,bad anatomy,bad proportions,malformed limbs,extra limbs,cloned face,disfigured,gross proportions, (((missing arms))),(((missing legs))), (((extra arms))),(((extra legs))),pubic hair, plump,bad legs,error legs,username,blurry,bad feet" 11 | beach,"solo, 1 girls, dress, hat, cream-colored round cap, sandy beach, blue sky,","freckles, nipples, small waist, large breast, lowres, large head, long neck, blurry, bad anatomy, bad hands, extra limbs, extra hands, mutated hands, mutated fingers, missing hand, missing finger, text, error, missing fingers, extra digit, camel toe, nail polish, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, text, signature, watermark, artist name, logo,, canvas frame, cartoon, 3d, ((disfigured)), ((bad art)), ((deformed)),((extra limbs)),((close up)),((b&w)), wierd colors, blurry, (((duplicate))), ((morbid)), ((mutilated)), [out of frame], extra fingers, mutated hands, ((poorly drawn hands)), ((poorly drawn face)), (((mutation))), (((deformed))), ((ugly)), blurry, ((bad anatomy)), (((bad proportions))), ((extra limbs)), cloned face, (((disfigured))), out of frame, ugly, extra limbs, (bad anatomy), gross proportions, (malformed limbs), ((missing arms)), ((missing legs)), (((extra arms))), (((extra legs))), mutated hands, (fused fingers), (too many fingers), (((long neck))), Photoshop, video game, ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, mutation, mutated, extra limbs, extra legs, extra arms, disfigured, deformed, cross-eye, body out of frame, blurry, bad art, bad anatomy, 3d render, text, username" 12 | cartoon for avatar,"solo, 1 young women, glasses, colorful,intricate detail,artbook,,{best quality}, {{masterpiece}}, {highres}, original, extremely detailed 8K wallpaper, {an extremely delicate and beautiful}, beautiful detailed eyes, looking at viewer, close up, long hair, halo, serene expression, looking at viewer","(pubic hair:2), paintings, sketches, (worst quality:2), (low quality:2), (normal quality:2), lowres, normal quality, ((monochrome:1.5)), ((grayscale)), skin spots, acnes, skin blemishes, age spot, (outdoor:1.6), manboobs, backlight,(ugly:1.331), (duplicate:1.331), (morbid:1.21), (mutilated:1.21), (tranny:1.331), mutated hands, (poorly drawn hands:1.331), blurry, (bad anatomy:1.21), (bad proportions:1.331), extra limbs, (disfigured:1.331), (more than 2 nipples:1.331), (missing arms:1.331), (extra legs:1.331), (fused fingers:1.61051), (too many fingers:1.61051), (unclear eyes:1.331), lowers, bad hands, missing fingers, extra digit, (futa:1.1), logo, white letters,missing fingers, extra digit, fewer digits,(mutated hands and fingers:1.5 ), (long body :1.3),bad hands, fused hand, missing hand, disappearing arms, error, missing fingers, missing limb,fused fingers, one hand with more than 5 fingers, one hand with less than 5 fingers, one hand with morethan 5 digit, one hand with less than 5 digit, extra digit, fewer digits, fused digit, missing digit,text,watermark" 13 | fancy cartoon head,"solo, 1 young women, glasses, masterpiece,","(pubic hair:2), paintings, sketches, (worst quality:2), (low quality:2), (normal quality:2), lowres, normal quality, ((monochrome:1.5)), ((grayscale)), skin spots, acnes, skin blemishes, age spot, (outdoor:1.6), manboobs, backlight,(ugly:1.331), (duplicate:1.331), (morbid:1.21), (mutilated:1.21), (tranny:1.331), mutated hands, (poorly drawn hands:1.331), blurry, (bad anatomy:1.21), (bad proportions:1.331), extra limbs, (disfigured:1.331), (more than 2 nipples:1.331), (missing arms:1.331), (extra legs:1.331), (fused fingers:1.61051), (too many fingers:1.61051), (unclear eyes:1.331), lowers, bad hands, missing fingers, extra digit, (futa:1.1), logo, white letters,missing fingers, extra digit, fewer digits,(mutated hands and fingers:1.5 ), (long body :1.3),bad hands, fused hand, missing hand, disappearing arms, error, missing fingers, missing limb,fused fingers, one hand with more than 5 fingers, one hand with less than 5 fingers, one hand with morethan 5 digit, one hand with less than 5 digit, extra digit, fewer digits, fused digit, missing digit,text,watermark" 14 | -------------------------------------------------------------------------------- /stable-diffusion/train-story.md: -------------------------------------------------------------------------------- 1 | # 探出火车窗的微笑女孩 2 | 3 | smiling girl leaning out the train window 4 | 5 | ## 丰富 6 | 7 | 扮演个小说家,写个故事 """探出火车窗的微笑女孩""" 8 | 9 | > 有一天,一位美丽的女士坐在火车上,她望着窗外,微笑着享受着旅途中的风景。她的脸上洋溢着温暖的微笑,这让坐在她旁边的人也不由自主地露出了微笑。 10 | 11 | > 当火车通过一片田野时,女士突然看到了一个小男孩在田野里奔跑着,他的手里还拿着一个放风筝的线轮。女士的目光被这个小男孩吸引住了,她不禁想起了自己小时候和父亲一起放风筝的场景。 12 | 13 | > 突然,小男孩停下了脚步,看着自己的风筝被风吹得越来越高。女士看着小男孩失落的表情,心里不由得有些心疼。她决定下车并走向小男孩,试图帮助他。 14 | 15 | > 当女士到达田野时,小男孩望着她,惊讶地张大了嘴巴。女士微笑着和他打招呼,然后走向风筝。她在绳轮上使劲一拉,让风筝重新升空。小男孩看着自己的风筝飞回天空,开心地跳了起来。 16 | 17 | > 女士和小男孩开始聊天,他们分享了很多关于风筝和田野的故事。女士发现自己从小到大都很少接触大自然,和小男孩的聊天也让她更加喜欢大自然。在离开的时候,小男孩送给了女士一只小风筝作为礼物,女士非常开心。 18 | 19 | > 回到火车上,女士继续欣赏窗外的美景,但她心里已经充满了对小男孩和大自然的热爱。她深深感受到,这个世界上有很多美好的事情,只要我们肯去发现,就会让我们的生活更加精彩。 20 | 21 | ## 22 | 23 | ## Inpaint 24 | 25 | -------------------------------------------------------------------------------- /txt2image.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": { 7 | "collapsed": true 8 | }, 9 | "outputs": [], 10 | "source": [ 11 | "# Clone\n", 12 | "\n", 13 | "!git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git\n", 14 | "!cd stable-diffusion-webui\n", 15 | "!./webui.sh\n", 16 | "\n", 17 | "# 等待奇迹出现,虽然是不可能的\n", 18 | "# 根据问题解决" 19 | ] 20 | }, 21 | { 22 | "cell_type": "markdown", 23 | "source": [ 24 | "按教程,下载模型:https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Installation-on-Apple-Silicon#downloading-stable-diffusion-models" 25 | ], 26 | "metadata": { 27 | "collapsed": false 28 | } 29 | } 30 | ], 31 | "metadata": { 32 | "kernelspec": { 33 | "display_name": "Python 3", 34 | "language": "python", 35 | "name": "python3" 36 | }, 37 | "language_info": { 38 | "codemirror_mode": { 39 | "name": "ipython", 40 | "version": 2 41 | }, 42 | "file_extension": ".py", 43 | "mimetype": "text/x-python", 44 | "name": "python", 45 | "nbconvert_exporter": "python", 46 | "pygments_lexer": "ipython2", 47 | "version": "2.7.6" 48 | } 49 | }, 50 | "nbformat": 4, 51 | "nbformat_minor": 0 52 | } 53 | --------------------------------------------------------------------------------