-
-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
161 additions
and
14 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/*! | ||
* @author TRACTION (iamtraction) | ||
* @copyright 2023 | ||
*/ | ||
import { ApplicationCommandOptionType, ChatInputCommandInteraction } from "discord.js"; | ||
import { Client, Command } from "@bastion/tesseract"; | ||
import OpenAI from "openai"; | ||
|
||
import Settings from "../utils/settings.js"; | ||
|
||
class ChatCommand extends Command { | ||
constructor() { | ||
super({ | ||
name: "chat", | ||
description: "Ask questions or chat with ChatGPT from OpenAI.", | ||
owner: true, | ||
options: [ | ||
{ | ||
type: ApplicationCommandOptionType.String, | ||
name: "message", | ||
description: "Your message.", | ||
required: true, | ||
}, | ||
], | ||
}); | ||
} | ||
|
||
public async exec(interaction: ChatInputCommandInteraction<"cached">): Promise<void> { | ||
await interaction.deferReply(); | ||
|
||
const message = interaction.options.getString("message"); | ||
|
||
const openai = new OpenAI({ | ||
apiKey: ((interaction.client as Client).settings as Settings).get("openai").apiKey, | ||
}); | ||
|
||
const response = await openai.chat.completions.create({ | ||
model: ((interaction.client as Client).settings as Settings).get("openai").model || "gpt-3.5-turbo", | ||
messages: [ | ||
{ | ||
role: "user", | ||
content: message, | ||
}, | ||
], | ||
max_tokens: ((interaction.client as Client).settings as Settings).get("openai").maxTokens || 100, | ||
user: interaction.member.id, | ||
}); | ||
|
||
await interaction.editReply({ | ||
content: response.choices[0].message.content, | ||
}); | ||
} | ||
} | ||
|
||
export { ChatCommand as Command }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/*! | ||
* @author TRACTION (iamtraction) | ||
* @copyright 2023 | ||
*/ | ||
import { ApplicationCommandOptionType, ChatInputCommandInteraction } from "discord.js"; | ||
import { Client, Command } from "@bastion/tesseract"; | ||
import OpenAI from "openai"; | ||
|
||
import Settings from "../../utils/settings.js"; | ||
|
||
class ImageGenerateCommand extends Command { | ||
constructor() { | ||
super({ | ||
name: "generate", | ||
description: "Generate an image with DALL-E from OpenAI.", | ||
owner: true, | ||
options: [ | ||
{ | ||
type: ApplicationCommandOptionType.String, | ||
name: "prompt", | ||
description: "A description of the desired image.", | ||
required: true, | ||
}, | ||
{ | ||
type: ApplicationCommandOptionType.String, | ||
name: "size", | ||
description: "The size of the generated image.", | ||
choices: [ | ||
{ | ||
name: "Square", | ||
value: "1024x1024", | ||
}, | ||
{ | ||
name: "Portrait", | ||
value: "1024x1792", | ||
}, | ||
{ | ||
name: "Landscape", | ||
value: "1792x1024", | ||
}, | ||
], | ||
}, | ||
], | ||
}); | ||
} | ||
|
||
public async exec(interaction: ChatInputCommandInteraction<"cached">): Promise<void> { | ||
await interaction.deferReply(); | ||
|
||
const prompt = interaction.options.getString("prompt"); | ||
const size = interaction.options.getString("size") as "1024x1024" | "1024x1792" | "1792x1024" || "1024x1024"; | ||
|
||
const openai = new OpenAI({ | ||
apiKey: ((interaction.client as Client).settings as Settings).get("openai").apiKey, | ||
}); | ||
|
||
const response = await openai.images.generate({ | ||
model: "dall-e-3", | ||
prompt: prompt, | ||
response_format: "url", | ||
size: size, | ||
user: interaction.member.id, | ||
}); | ||
|
||
await interaction.editReply({ | ||
content: response.data[0].revised_prompt, | ||
files: [{ | ||
attachment: response.data[0].url, | ||
}], | ||
}); | ||
} | ||
} | ||
|
||
export { ImageGenerateCommand as Command }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters