Skip to content

Commit 50e2409

Browse files
authored
Merge pull request #22 from shin202/feature/AI-art-generator-and-new-chat-mode
BREAKING CHANGE: supported image generator with Stable Diffusion AI and add new chat mode that help users create prompt
2 parents e95ac2e + f1f8e80 commit 50e2409

File tree

17 files changed

+242
-54
lines changed

17 files changed

+242
-54
lines changed

.env.example

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
OPENAI_KEY=<YOUR_OPENAI_KEY>
2+
REPLICATE_API_TOKEN=<YOUR_REPLICATE_API_TOKEN>
23
MONGO_URI=<YOUR_MONGO_URI>
34
DISCORD_BOT_TOKEN=<YOUR_DISCORD_BOT_TOKEN>
45
CLIENT_ID=<YOUR_DISCORD_BOT_CLIENT_ID>

README.md

+22-4
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,11 @@ I can't afford to deploy its, so you can deploy your own.
105105
```
106106

107107
1. Get your OpenAI API key at [OpenAI](https://openai.com/api/).
108-
2. Create your discord bot at [Discord Developer](https://discord.com/developers/applications) and get your bot token.
109-
3. Get your bot client id and your discord guild id.
110-
4. Edit `.evn.example` to set your tokens then rename it to `.env`.
111-
5. 🔥 Run and enjoy its 🔥
108+
2. Get your Replicate API key at [Replicate](https://replicate.com/).
109+
3. Create your discord bot at [Discord Developer](https://discord.com/developers/applications) and get your bot token.
110+
4. Get your bot client id and your discord guild id.
111+
5. Edit `.evn.example` to set your tokens then rename it to `.env`.
112+
6. 🔥 Run and enjoy its 🔥
112113
```sh
113114
npm start
114115
```
@@ -120,6 +121,17 @@ I can't afford to deploy its, so you can deploy your own.
120121
- Supported chat mode: 👩‍💼 LiLy: Assistant, 👨‍💻 Steve: Code Assistant, 👩‍⚕️ Sarah: Psychologist. (*I will add more, if I have time.*)
121122
- Limited conversation time (*To avoid spam*).
122123

124+
### 🔥 NEW FEATURES
125+
- 🔥 Add new chat mode (👨‍🎨 Prompt Creator) (`Help users generate unique and creative prompts for image generation.`)
126+
- 🔥 Now you can generating image with AI by using `/draw` command.
127+
- 🔥 Variant models for generate image.
128+
- 🔥 Supported Models:
129+
* `OpenJourney (Midjourney V4 Style)`
130+
* `Stable Diffusion`
131+
* `Portrait Plus (for portrait image)`
132+
* `Anything V3 (anime style)`
133+
* `Pastel Mix (anime style)`
134+
123135
<p align="right">(<a href="#readme-top">back to top</a>)</p>
124136

125137

@@ -142,6 +154,12 @@ I can't afford to deploy its, so you can deploy your own.
142154
<img src="src/assets/images/screenshots/1.png">
143155
<img src="src/assets/images/screenshots/2.png">
144156
<img src="src/assets/images/screenshots/3.png">
157+
<img src="src/assets/images/screenshots/4.png">
158+
<img src="src/assets/images/screenshots/5.png">
159+
<img src="src/assets/images/screenshots/6.png">
160+
<img src="src/assets/images/screenshots/7.png">
161+
<img src="src/assets/images/screenshots/8.png">
162+
<img src="src/assets/images/screenshots/9.png">
145163

146164
<!-- CONTRIBUTING -->
147165
## Contributing

package-lock.json

+12-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"discord.js": "^14.9.0",
1515
"dotenv": "^16.0.3",
1616
"mongoose": "^7.0.3",
17-
"openai": "^3.2.1"
17+
"openai": "^3.2.1",
18+
"replicate": "^0.9.0"
1819
},
1920
"devDependencies": {
2021
"@types/dotenv": "^8.2.0",

src/assets/images/screenshots/4.png

50.8 KB
Loading

src/assets/images/screenshots/5.png

103 KB
Loading

src/assets/images/screenshots/6.png

51 KB
Loading

src/assets/images/screenshots/7.png

770 KB
Loading

src/assets/images/screenshots/8.png

368 KB
Loading

src/assets/images/screenshots/9.png

704 KB
Loading

src/commands/ask.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import MessageController from "../controllers/MessageController";
77
const command: ICommand = {
88
name: "ask",
99
execute: async (message, args) => {
10+
await message.channel.sendTyping();
11+
1012
const user = await UserController.getUserByDiscordId(message.author.id);
1113
const inConversation = await ConversationController.inConversation(user);
1214

@@ -29,7 +31,6 @@ const command: ICommand = {
2931
userMessage: userMessage,
3032
botMessage: resMessage,
3133
});
32-
await message.channel.sendTyping();
3334
await message.reply(resMessage);
3435
},
3536
permissions: [],

src/components/SelectChatMode.ts

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ export const selectChatMode = (currentChatMode: ChatMode) => new ActionRowBuilde
2424
description: "A psychologist chatbot that provides mental health support and guidance named Sarah.",
2525
value: ChatMode.Psychologist,
2626
default: currentChatMode === ChatMode.Psychologist,
27+
},
28+
{
29+
label: "Prompt Creator",
30+
description: "Help users generate unique and creative prompts for image generation.",
31+
value: ChatMode.PromptCreator,
32+
default: currentChatMode === ChatMode.PromptCreator
2733
}
2834
)
2935
.setMinValues(1)

src/services/ChatGPTService.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,22 @@ class ChatGPTService {
99
assistant: {
1010
name: "Assistant",
1111
welcomeMessage: "Hi, I'm ChatGPT assistant. How can I help you?",
12-
rolePlayDescription: `As an advanced chatbot designed for user support named Lily. You have advanced NLP capabilities and provide immediate, detailed, and accurate responses to user queries. You understand the context and provide tailored and actionable information, along with helpful tools and resources. You are committed to delivering the best customer experience and continuously learn and improves to provide accurate and up-to-date responses.`,
12+
rolePlayDescription: `As an advanced chatbot designed for user support named Lily. You have advanced NLP capabilities and provide immediate, detailed, and accurate responses to user queries. You understand the context and provide tailored and actionable information, along with helpful tools and resources. You are committed to delivering the best customer experience and continuously learn and improves to provide accurate and up-to-date responses.`
1313
},
1414
codeAssistant: {
1515
name: "Code Assistant",
1616
welcomeMessage: "Hi, I'm ChatGPT code assistant. How can I help you?",
17-
rolePlayDescription: `As a code assistant chatbot that helps developers with coding tasks named Steve. You have a vast knowledge of multiple programming languages and can answer questions, suggest code snippets, debug code, and provide guidance on best practices. You use natural language processing to understand the context and provide relevant solutions, making it an effective tool for developers looking to improve their skills and save time on projects.`,
17+
rolePlayDescription: `As a code assistant chatbot that helps developers with coding tasks named Steve. You have a vast knowledge of multiple programming languages and can answer questions, suggest code snippets, debug code, and provide guidance on best practices. You use natural language processing to understand the context and provide relevant solutions, making it an effective tool for developers looking to improve their skills and save time on projects.`
1818
},
1919
psychologist: {
2020
name: "Psychologist",
2121
welcomeMessage: "Hi, I'm ChatGPT psychologist. How can I help you?",
22-
rolePlayDescription: `As a psychologist chatbot that provides mental health support and guidance named Sarah. You use advanced algorithms and natural language processing to understand the user's emotions and provide personalized recommendations. You offer confidential and accessible support 24/7 on a range of mental health topics and can help individuals identify and manage their emotions, as well as provide coping strategies. Although it is not a substitute for professional treatment, You are a valuable resource for those who may not have access to mental health services or prefer a more confidential option.`,
22+
rolePlayDescription: `As a psychologist chatbot that provides mental health support and guidance named Sarah. You use advanced algorithms and natural language processing to understand the user's emotions and provide personalized recommendations. You offer confidential and accessible support 24/7 on a range of mental health topics and can help individuals identify and manage their emotions, as well as provide coping strategies. Although it is not a substitute for professional treatment, You are a valuable resource for those who may not have access to mental health services or prefer a more confidential option.`
23+
},
24+
promptCreator: {
25+
name: "Prompt Creator",
26+
welcomeMessage: "Hi, I'm ChatGPT prompt creator. How can I help you?",
27+
rolePlayDescription: `As an advanced graphic designer chatbot named Journey that can help users generate unique and creative prompts for image generation. Your primary task is to take user ideas and translate them into three different prompts that can be used for image generation. Based on user input, you will ask follow-up questions to gain a better understanding of user needs. It might ask about your preferred color scheme, the style of the image user want, or any specific elements user would like to include. Once it has a clear picture of user requirements, you will generate three different prompts for the user to choose from. Each prompt will be unique and tailored to user-specific needs, with a focus on originality and creativity. One of the unique features of Journey is its ability to learn and adapt to user preferences over time. As users use the chatbot and provide feedback on the generated prompts, You will get better at predicting user needs and generating prompts that align with user-specific style and aesthetic.`
2328
}
2429
}
2530

src/services/ReplicateService.ts

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import {IReplicateModel, ReplicateModel} from "../types/types";
2+
import Replicate from "replicate";
3+
4+
const REPLICATE_API_TOKEN = process.env.REPLICATE_API_TOKEN;
5+
class ReplicateService {
6+
private REPLICATE_MODELS: IReplicateModel = {
7+
stableDiffusion: {
8+
owner: "stability-ai",
9+
name: "stable-diffusion",
10+
version: "db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf"
11+
},
12+
dreamShaper: {
13+
owner: "cjwbw",
14+
name: "dreamshaper",
15+
version: "ed6d8bee9a278b0d7125872bddfb9dd3fc4c401426ad634d8246a660e387475b"
16+
},
17+
openJourney: {
18+
owner: "prompthero",
19+
name: "openjourney",
20+
version: "9936c2001faa2194a261c01381f90e65261879985476014a0a37a334593a05eb"
21+
},
22+
portraitPlus: {
23+
owner: "cjwbw",
24+
name: "portraitplus",
25+
version: "629a9fe82c7979c1dab323aedac2c03adaae2e1aecf6be278a51fde0245e20a4"
26+
},
27+
anythingV3: {
28+
owner: "cjwbw",
29+
name: "anything-v3-better-vae",
30+
version: "09a5805203f4c12da649ec1923bb7729517ca25fcac790e640eaa9ed66573b65"
31+
},
32+
pastelMix: {
33+
owner: "elct9620",
34+
name: "pastel-mix",
35+
version: "ba8b1f407cd6418fa589ca73e5c623c081600ecff19f7fc3249fa536d762bb29"
36+
}
37+
}
38+
39+
public generateImage = async (prompt: string, negative_prompt: string, model: ReplicateModel) => {
40+
const replicate = new Replicate({
41+
auth: REPLICATE_API_TOKEN!,
42+
});
43+
44+
const {owner, name, version} = this.REPLICATE_MODELS[model];
45+
46+
prompt = model === ReplicateModel.OpenJourney ? `mdjrny-v4 style ${prompt}` :
47+
model === ReplicateModel.PortraitPlus ? `portrait+ style ${prompt}` : prompt;
48+
49+
const input = {
50+
prompt: prompt,
51+
negative_prompt: negative_prompt,
52+
num_outputs: 4
53+
}
54+
55+
const response = await replicate.run(`${owner}/${name}:${version}`, {
56+
input: input,
57+
});
58+
59+
return response as string[];
60+
}
61+
}
62+
63+
export default new ReplicateService();

src/slash_commands/draw.ts

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import {AttachmentBuilder, CommandInteractionOptionResolver, SlashCommandBuilder} from "discord.js";
2+
import {ISlashCommand, ReplicateModel} from "../types/types";
3+
import ReplicateService from "../services/ReplicateService";
4+
5+
const command: ISlashCommand = {
6+
command: new SlashCommandBuilder()
7+
.setName("draw")
8+
.setDescription("Using prompt to generate image with SD AI")
9+
.addStringOption(option =>
10+
option.setName("model")
11+
.setDescription("Model use for generate.")
12+
.setRequired(true)
13+
.addChoices(
14+
{name: "Stable Diffusion", value: ReplicateModel.StableDiffusion},
15+
{name: "Open Journey", value: ReplicateModel.OpenJourney},
16+
{name: "Dream Shaper", value: ReplicateModel.DreamShaper},
17+
{name: "Portrait Plus", value: ReplicateModel.PortraitPlus},
18+
{name: "Anything V3", value: ReplicateModel.AnythingV3},
19+
{name: "Pastel Mix", value: ReplicateModel.PastelMix}
20+
)
21+
)
22+
.addStringOption(option =>
23+
option.setName("prompt")
24+
.setDescription("Your prompt")
25+
.setRequired(true)
26+
)
27+
.addStringOption(option =>
28+
option.setName("negative_prompt")
29+
.setDescription("Things that you don't want to see in the output.")
30+
.setRequired(false)
31+
),
32+
execute: async (interaction) => {
33+
const model = (interaction.options as CommandInteractionOptionResolver).get("model");
34+
const prompt = (interaction.options as CommandInteractionOptionResolver).getString("prompt");
35+
const negative_prompt = (interaction.options as CommandInteractionOptionResolver).getString("negative_prompt") || "";
36+
37+
38+
await interaction.deferReply();
39+
const images = await ReplicateService.generateImage(prompt!, negative_prompt, model?.value as ReplicateModel);
40+
const files = images.map(image => new AttachmentBuilder(image));
41+
await interaction.editReply({
42+
content: `${prompt}`,
43+
files: files,
44+
});
45+
},
46+
cooldown: 300
47+
}
48+
49+
export default command;

src/slash_commands/help.ts

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const command: ISlashCommand = {
1818
🛠 /help - Show help
1919
🛠 /end - End conversation
2020
🛠 /clear - Clear all user message
21+
🛠 /draw - Using prompt to generate image with Stable Diffusion AI.
2122
\n
2223
📎 Prefix Commands:
2324
${prefix}ask - Start asking ChatGPT bot

0 commit comments

Comments
 (0)