Skip to content

Commit

Permalink
Fixes to imagen
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaUrsa committed Nov 19, 2023
1 parent 4a31183 commit a494a28
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
23 changes: 13 additions & 10 deletions src/discord/commands/guild/d.ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,7 @@ export async function aiImageAudit(

// const embed = await makePersonaEmbed(cleanPersona);
const embed = embedTemplate()
.setThumbnail(message.author.displayAvatarURL())
.setAuthor({ name: message.author.username, url: message.url, iconURL: message.author.displayAvatarURL() })
.setColor(Colors.Yellow);

embed.addFields(
Expand Down Expand Up @@ -1763,9 +1763,7 @@ export async function discordAiChat(

if (messageData.cleanContent.includes('imagen')) {
if (!messageData.member?.roles.cache.has(env.ROLE_PATRON)
&& messageData.author.id !== env.ROLE_TEAMTRIPSIT
&& !messageData.member?.roles.cache.has(env.TEAM_TRIPSIT)

&& !messageData.member?.roles.cache.has(env.ROLE_TEAMTRIPSIT)
) {
await messageData.reply('This beta feature is exclusive to active TripSit [Patreon](https://www.patreon.com/tripsit) subscribers.');
return;
Expand Down Expand Up @@ -1803,15 +1801,23 @@ export async function discordAiChat(
return;
}

const tripbotLog = await discordClient.channels.fetch(env.CHANNEL_BOTLOG) as TextChannel;
await tripbotLog.send(`${messageData.author.toString()} generated an image in ${messageData.url}`);

let waitingOnGen = true;
createImage(
messageData.cleanContent.replace('imgen', '').trim(),
messageData.cleanContent.replace('imgen', '').replace(tripbotUAT, '').replace('tripbot', '').trim(),
messageData.author.id,
)
.then(async response => {
waitingOnGen = false;
const { data } = response;
const [image] = data;
await aiImageAudit(
'DALL_E_3' as ai_model,
messageData,
image,
);
if (image.url) {
await messageData.reply(
{
Expand All @@ -1822,11 +1828,8 @@ export async function discordAiChat(
.setFooter({ text: `Beta feature only available to active TripSit Patreon subscribers (${imageLimit - imagesThisMonth} images left).` })],
},
);
await aiImageAudit(
'DALL_E_3' as ai_model,
messageData,
image,
);
} else {
await tripbotLog.send(`Error generating image: ${JSON.stringify(image, null, 2)}`);
}
});
// While the above function is running, send the typing function
Expand Down
16 changes: 14 additions & 2 deletions src/global/commands/g.ai.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import OpenAI from 'openai';
import { PrismaClient, ai_model, ai_personas } from '@prisma/client';
import { ModerationCreateResponse } from 'openai/resources';
import { ImagesResponse, ModerationCreateResponse } from 'openai/resources';
import { Assistant } from 'openai/resources/beta/assistants/assistants';
import { stripIndents } from 'common-tags';
import { Thread, ThreadDeleted } from 'openai/resources/beta/threads/threads';
Expand Down Expand Up @@ -234,7 +234,7 @@ export async function readRun(
export async function createImage(
prompt: string,
user: string,
) {
):Promise<ImagesResponse> {
log.debug(F, `createImage | prompt: ${prompt}`);
// log.debug(F, `image: ${JSON.stringify(image, null, 2)}`);

Expand Down Expand Up @@ -263,6 +263,18 @@ export async function createImage(
},
});

if (env.NODE_ENV === ' development') {
log.debug(F, ' returning dev image');
return {
created: 0,
data: [
{
url: 'https://i.imgur.com/1Z9zZ1i.png',
},
],
};
}

return openai.images.generate({
prompt,
model: 'dall-e-3',
Expand Down

0 comments on commit a494a28

Please sign in to comment.