From b142228d93f96560dfa1e3ac431a10a54a1fab72 Mon Sep 17 00:00:00 2001 From: fegloff Date: Mon, 8 Jan 2024 11:47:19 -0400 Subject: [PATCH 1/7] add basic dalle-3 logic --- src/modules/open-ai/api/openAi.ts | 3 +++ src/modules/open-ai/helpers.ts | 24 ++++++++++++------------ src/modules/open-ai/types.ts | 8 ++++++++ 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/modules/open-ai/api/openAi.ts b/src/modules/open-ai/api/openAi.ts index dc7b8188..9e053560 100644 --- a/src/modules/open-ai/api/openAi.ts +++ b/src/modules/open-ai/api/openAi.ts @@ -35,6 +35,8 @@ export async function postGenerateImg ( imgSize?: string ): Promise { const payload = { + model: 'dall-e-3', + quality: 'hd', prompt, n: numImgs ?? config.openAi.dalle.sessionDefault.numImages, size: imgSize ?? config.openAi.dalle.sessionDefault.imgSize @@ -42,6 +44,7 @@ export async function postGenerateImg ( const response = await openai.images.generate( payload as OpenAI.Images.ImageGenerateParams ) + console.log(response) return response.data } diff --git a/src/modules/open-ai/helpers.ts b/src/modules/open-ai/helpers.ts index 847cb460..9f8580b5 100644 --- a/src/modules/open-ai/helpers.ts +++ b/src/modules/open-ai/helpers.ts @@ -259,6 +259,18 @@ export const limitPrompt = (prompt: string): string => { return `${prompt} in around ${config.openAi.chatGpt.wordLimit} words` } +export const getUrlFromText = (ctx: OnMessageContext | OnCallBackQueryData): string | undefined => { + const entities = ctx.message?.reply_to_message?.entities + if (entities) { + const urlEntity = entities.find(e => e.type === 'url') + if (urlEntity) { + const url = ctx.message?.reply_to_message?.text?.slice(urlEntity.offset, urlEntity.offset + urlEntity.length) + return url + } + } + return undefined +} + // export async function addUrlToCollection (ctx: OnMessageContext | OnCallBackQueryData, chatId: number, url: string, prompt: string): Promise { // const collectionName = await llmAddUrlDocument({ // chatId, @@ -278,15 +290,3 @@ export const limitPrompt = (prompt: string): string => { // msgId // }) // } - -export const getUrlFromText = (ctx: OnMessageContext | OnCallBackQueryData): string | undefined => { - const entities = ctx.message?.reply_to_message?.entities - if (entities) { - const urlEntity = entities.find(e => e.type === 'url') - if (urlEntity) { - const url = ctx.message?.reply_to_message?.text?.slice(urlEntity.offset, urlEntity.offset + urlEntity.length) - return url - } - } - return undefined -} diff --git a/src/modules/open-ai/types.ts b/src/modules/open-ai/types.ts index 8c2e6b6f..46a214fb 100644 --- a/src/modules/open-ai/types.ts +++ b/src/modules/open-ai/types.ts @@ -50,6 +50,14 @@ export const ChatGPTModels: Record = { } export const DalleGPTModels: Record = { + '1024x1792': { + size: '1024x1792', + price: 0.02 + }, + '1792x1024': { + size: '1792x1024', + price: 0.02 + }, '1024x1024': { size: '1024x1024', price: 0.02 From 40a1c5cd50ace8bfca0422633d04539017428097 Mon Sep 17 00:00:00 2001 From: fegloff Date: Mon, 8 Jan 2024 13:17:04 -0400 Subject: [PATCH 2/7] update config file --- src/config.ts | 2 ++ src/modules/open-ai/api/openAi.ts | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/config.ts b/src/config.ts index af086989..87167de3 100644 --- a/src/config.ts +++ b/src/config.ts @@ -54,6 +54,8 @@ export default { defaultPrompt: 'beautiful waterfall in a lush jungle, with sunlight shining through the trees', sessionDefault: { + model: 'dall-e-3', + quality: 'hd', numImages: 1, imgSize: '1024x1024' } diff --git a/src/modules/open-ai/api/openAi.ts b/src/modules/open-ai/api/openAi.ts index 9e053560..d1d431d5 100644 --- a/src/modules/open-ai/api/openAi.ts +++ b/src/modules/open-ai/api/openAi.ts @@ -35,8 +35,8 @@ export async function postGenerateImg ( imgSize?: string ): Promise { const payload = { - model: 'dall-e-3', - quality: 'hd', + model: config.openAi.dalle.sessionDefault.model, + quality: config.openAi.dalle.sessionDefault.quality, prompt, n: numImgs ?? config.openAi.dalle.sessionDefault.numImages, size: imgSize ?? config.openAi.dalle.sessionDefault.imgSize From 68b34bcd5be442ac5253e1275ebafc0e632bd152 Mon Sep 17 00:00:00 2001 From: fegloff Date: Mon, 8 Jan 2024 18:54:52 -0400 Subject: [PATCH 3/7] add img generation session queue --- src/bot.ts | 4 ++- src/modules/open-ai/index.ts | 63 +++++++++++++++++++++++++++++------- src/modules/types.ts | 10 +++++- 3 files changed, 63 insertions(+), 14 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index 7c476166..0348b6df 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -186,7 +186,9 @@ function createInitialSessionData (): BotSessionData { imageGen: { numImages: config.openAi.dalle.sessionDefault.numImages, imgSize: config.openAi.dalle.sessionDefault.imgSize, - isEnabled: config.openAi.dalle.isEnabled + isEnabled: config.openAi.dalle.isEnabled, + imgRequestQueue: [], + isProcessingQueue: false }, chatGpt: { model: config.openAi.chatGpt.model, diff --git a/src/modules/open-ai/index.ts b/src/modules/open-ai/index.ts index 6c76010d..eb450b47 100644 --- a/src/modules/open-ai/index.ts +++ b/src/modules/open-ai/index.ts @@ -43,6 +43,7 @@ import { now } from '../../utils/perf' import { AxiosError } from 'axios' import { Callbacks } from '../types' import { LlmsBot } from '../llms' +import { type PhotoSize } from 'grammy/types' export class OpenAIBot implements PayableBot { public readonly module = 'OpenAIBot' @@ -156,7 +157,19 @@ export class OpenAIBot implements PayableBot { ctx.transient.analytics.sessionState = RequestState.Success if (this.isSupportedImageReply(ctx)) { - await this.onAlterImage(ctx) + const photo = ctx.message?.photo ?? ctx.message?.reply_to_message?.photo + const prompt = ctx.message?.caption ?? ctx.message?.text + ctx.session.openAi.imageGen.imgRequestQueue.push({ + prompt, + photo, + command: 'alter' + }) + if (!ctx.session.openAi.imageGen.isProcessingQueue) { + ctx.session.openAi.imageGen.isProcessingQueue = true + await this.onImgRequestHandler(ctx).then(() => { + ctx.session.openAi.imageGen.isProcessingQueue = false + }) + } return } @@ -217,7 +230,20 @@ export class OpenAIBot implements PayableBot { ctx.hasCommand(SupportedCommands.dalleLC.name) || (ctx.message?.text?.startsWith('dalle ') && ctx.chat?.type === 'private') ) { - await this.onGenImgCmd(ctx) + let prompt = (ctx.match ? ctx.match : ctx.message?.text) as string + if (!prompt || prompt.split(' ').length === 1) { + prompt = config.openAi.dalle.defaultPrompt + } + ctx.session.openAi.imageGen.imgRequestQueue.push({ + command: 'dalle', + prompt + }) + if (!ctx.session.openAi.imageGen.isProcessingQueue) { + ctx.session.openAi.imageGen.isProcessingQueue = true + await this.onImgRequestHandler(ctx).then(() => { + ctx.session.openAi.imageGen.isProcessingQueue = false + }) + } return } @@ -497,17 +523,33 @@ export class OpenAIBot implements PayableBot { } } - onGenImgCmd = async (ctx: OnMessageContext | OnCallBackQueryData): Promise => { + async onImgRequestHandler (ctx: OnMessageContext | OnCallBackQueryData): Promise { + while (ctx.session.openAi.imageGen.imgRequestQueue.length > 0) { + try { + const img = ctx.session.openAi.imageGen.imgRequestQueue.shift() + if (await this.hasBalance(ctx)) { + if (img?.command === 'dalle') { + await this.onGenImgCmd(img?.prompt, ctx) + } else { + await this.onAlterImage(img?.photo, img?.prompt, ctx) + } + ctx.chatAction = null + } else { + await this.onNotBalanceMessage(ctx) + } + } catch (e: any) { + await this.onError(ctx, e) + } + } + } + + onGenImgCmd = async (prompt: string | undefined, ctx: OnMessageContext | OnCallBackQueryData): Promise => { try { if (ctx.session.openAi.imageGen.isEnabled) { - let prompt = (ctx.match ? ctx.match : ctx.message?.text) as string - if (!prompt || prompt.split(' ').length === 1) { - prompt = config.openAi.dalle.defaultPrompt - } ctx.chatAction = 'upload_photo' const numImages = ctx.session.openAi.imageGen.numImages const imgSize = ctx.session.openAi.imageGen.imgSize - const imgs = await postGenerateImg(prompt, numImages, imgSize) + const imgs = await postGenerateImg(prompt ?? '', numImages, imgSize) const msgExtras = getMessageExtras({ caption: `/dalle ${prompt}` }) await Promise.all(imgs.map(async (img: any) => { await ctx.replyWithPhoto(img.url, msgExtras).catch(async (e) => { @@ -533,12 +575,9 @@ export class OpenAIBot implements PayableBot { } } - onAlterImage = async (ctx: OnMessageContext | OnCallBackQueryData): Promise => { + onAlterImage = async (photo: PhotoSize[] | undefined, prompt: string | undefined, ctx: OnMessageContext | OnCallBackQueryData): Promise => { try { if (ctx.session.openAi.imageGen.isEnabled) { - const photo = - ctx.message?.photo ?? ctx.message?.reply_to_message?.photo - const prompt = ctx.message?.caption ?? ctx.message?.text const fileId = photo?.pop()?.file_id // with pop() get full image quality if (!fileId) { await ctx.reply('Cannot retrieve the image file. Please try again.') diff --git a/src/modules/types.ts b/src/modules/types.ts index 5ce60a29..2d34a5b6 100644 --- a/src/modules/types.ts +++ b/src/modules/types.ts @@ -9,7 +9,7 @@ import { type ConversationFlavor } from '@grammyjs/conversations' import { type AutoChatActionFlavor } from '@grammyjs/auto-chat-action' -import { type ParseMode } from 'grammy/types' +import { type PhotoSize, type ParseMode } from 'grammy/types' import { type InlineKeyboardMarkup } from 'grammy/out/types' import type { FileFlavor } from '@grammyjs/files' @@ -17,6 +17,8 @@ export interface ImageGenSessionData { numImages: number imgSize: string isEnabled: boolean + imgRequestQueue: ImageRequest[] + isProcessingQueue: boolean } export interface MessageExtras { @@ -43,6 +45,12 @@ export interface ChatConversation { content: string model?: string } + +export interface ImageRequest { + command?: 'dalle' | 'alter' + prompt?: string + photo?: PhotoSize[] | undefined +} export interface ChatGptSessionData { model: string isEnabled: boolean From f6727723952c74c3b21da3b747f9835e7a0e3a3a Mon Sep 17 00:00:00 2001 From: fegloff Date: Mon, 8 Jan 2024 21:42:21 -0400 Subject: [PATCH 4/7] add status text --- src/modules/open-ai/index.ts | 78 +++--------------------------------- 1 file changed, 6 insertions(+), 72 deletions(-) diff --git a/src/modules/open-ai/index.ts b/src/modules/open-ai/index.ts index eb450b47..761d7596 100644 --- a/src/modules/open-ai/index.ts +++ b/src/modules/open-ai/index.ts @@ -545,8 +545,12 @@ export class OpenAIBot implements PayableBot { onGenImgCmd = async (prompt: string | undefined, ctx: OnMessageContext | OnCallBackQueryData): Promise => { try { - if (ctx.session.openAi.imageGen.isEnabled) { + if (ctx.session.openAi.imageGen.isEnabled && ctx.chat?.id) { ctx.chatAction = 'upload_photo' + // eslint-disable-next-line @typescript-eslint/naming-convention + const { message_id } = await ctx.reply( + 'Generating dalle image...', { message_thread_id: ctx.message?.message_thread_id } + ) const numImages = ctx.session.openAi.imageGen.numImages const imgSize = ctx.session.openAi.imageGen.imgSize const imgs = await postGenerateImg(prompt ?? '', numImages, imgSize) @@ -556,6 +560,7 @@ export class OpenAIBot implements PayableBot { await this.onError(ctx, e, MAX_TRIES) }) })) + await ctx.api.deleteMessage(ctx.chat?.id, message_id) ctx.transient.analytics.sessionState = RequestState.Success ctx.transient.analytics.actualResponseTime = now() } else { @@ -749,74 +754,3 @@ export class OpenAIBot implements PayableBot { } } } - -// onGenImgEnCmd = async (ctx: OnMessageContext | OnCallBackQueryData) => { -// try { -// if (ctx.session.openAi.imageGen.isEnabled) { -// const prompt = await ctx.match; -// if (!prompt) { -// sendMessage(ctx, "Error: Missing prompt", { -// topicId: ctx.message?.message_thread_id, -// }).catch((e) => -// this.onError(ctx, e, MAX_TRIES, "Error: Missing prompt") -// ); -// return; -// } -// const payload = { -// chatId: await ctx.chat?.id!, -// prompt: prompt as string, -// numImages: await ctx.session.openAi.imageGen.numImages, -// imgSize: await ctx.session.openAi.imageGen.imgSize, -// }; -// sendMessage(ctx, "generating improved prompt...", { -// topicId: ctx.message?.message_thread_id, -// }).catch((e) => -// this.onError(ctx, e, MAX_TRIES, "generating improved prompt...") -// ); -// await imgGenEnhanced(payload, ctx); -// } else { -// sendMessage(ctx, "Bot disabled", { -// topicId: ctx.message?.message_thread_id, -// }).catch((e) => this.onError(ctx, e, MAX_TRIES, "Bot disabled")); -// } -// } catch (e) { -// this.onError(ctx, e); -// } -// }; - -// private async imgGenEnhanced( -// data: ImageGenPayload, -// ctx: OnMessageContext | OnCallBackQueryData -// ) { -// const { chatId, prompt, numImages, imgSize, model } = data; -// try { -// const upgratedPrompt = await improvePrompt(prompt, model!); -// if (upgratedPrompt) { -// await ctx -// .reply( -// `The following description was added to your prompt: ${upgratedPrompt}` -// ) -// .catch((e) => { -// throw e; -// }); -// } -// // bot.api.sendMessage(chatId, "generating the output..."); -// const imgs = await postGenerateImg( -// upgratedPrompt || prompt, -// numImages, -// imgSize -// ); -// imgs.map(async (img: any) => { -// await ctx -// .replyWithPhoto(img.url, { -// caption: `/DALLE ${upgratedPrompt || prompt}`, -// }) -// .catch((e) => { -// throw e; -// }); -// }); -// return true; -// } catch (e) { -// throw e; -// } -// }; From 8b70ba045a16aa26cbcbace54bc1d3f2d4e1f4c8 Mon Sep 17 00:00:00 2001 From: fegloff Date: Tue, 9 Jan 2024 19:31:39 -0400 Subject: [PATCH 5/7] assign image, img, i. to dalle command + add sdimage sdimages sdimg commands/prefix --- src/config.ts | 5 +---- src/modules/open-ai/helpers.ts | 8 +++++--- src/modules/open-ai/index.ts | 33 ++++++++++++++++++++++++++------ src/modules/sd-images/helpers.ts | 12 ++++++------ 4 files changed, 39 insertions(+), 19 deletions(-) diff --git a/src/config.ts b/src/config.ts index 87167de3..a917ce31 100644 --- a/src/config.ts +++ b/src/config.ts @@ -38,7 +38,7 @@ export default { model: 'chat-bison', minimumBalance: 0, isEnabled: Boolean(parseInt(process.env.LLMS_ENABLED ?? '1')), - prefixes: { bardPrefix: [',', 'b.', 'B.'] }, + prefixes: { bardPrefix: ['b.', 'B.'] }, pdfUrl: process.env.PDF_URL ?? '', processingTime: 300000 }, @@ -84,9 +84,6 @@ export default { chatPrefix: process.env.ASK_PREFIX ? process.env.ASK_PREFIX.split(',') : ['a.', '.'], // , "?", ">", - dallePrefix: process.env.DALLE_PREFIX - ? process.env.DALLE_PREFIX.split(',') - : ['d.'], newPrefix: process.env.NEW_PREFIX ? process.env.NEW_PREFIX.split(',') : ['n.', '..'], diff --git a/src/modules/open-ai/helpers.ts b/src/modules/open-ai/helpers.ts index 9f8580b5..dc329752 100644 --- a/src/modules/open-ai/helpers.ts +++ b/src/modules/open-ai/helpers.ts @@ -16,8 +16,8 @@ export const SupportedCommands = { ask32: { name: 'ask32' }, gpt: { name: 'gpt' }, last: { name: 'last' }, - dalle: { name: 'DALLE' }, - dalleLC: { name: 'dalle' }, + dalle: { name: 'image' }, + dalleShort: { name: 'img' }, genImgEn: { name: 'genImgEn' }, on: { name: 'on' }, off: { name: 'off' } @@ -25,6 +25,8 @@ export const SupportedCommands = { export const MAX_TRIES = 3 +const DALLE_PREFIX_LIST = ['i.', ', ', 'image ', 'd.', 'img '] + export const isMentioned = ( ctx: OnMessageContext | OnCallBackQueryData ): boolean => { @@ -52,7 +54,7 @@ export const hasChatPrefix = (prompt: string): string => { } export const hasDallePrefix = (prompt: string): string => { - const prefixList = config.openAi.chatGpt.prefixes.dallePrefix + const prefixList = DALLE_PREFIX_LIST for (let i = 0; i < prefixList.length; i++) { if (prompt.toLocaleLowerCase().startsWith(prefixList[i])) { return prefixList[i] diff --git a/src/modules/open-ai/index.ts b/src/modules/open-ai/index.ts index 761d7596..3642eac4 100644 --- a/src/modules/open-ai/index.ts +++ b/src/modules/open-ai/index.ts @@ -29,6 +29,7 @@ import { getMessageExtras, getPromptPrice, hasChatPrefix, + hasDallePrefix, hasNewPrefix, hasPrefix, hasUrl, @@ -101,7 +102,7 @@ export class OpenAIBot implements PayableBot { } if ( ctx.hasCommand(SupportedCommands.dalle.name) || - ctx.hasCommand(SupportedCommands.dalleLC.name) + ctx.hasCommand(SupportedCommands.dalleShort.name) ) { const imageNumber = ctx.session.openAi.imageGen.numImages const imageSize = ctx.session.openAi.imageGen.imgSize @@ -226,9 +227,8 @@ export class OpenAIBot implements PayableBot { } if ( - ctx.hasCommand(SupportedCommands.dalle.name) || - ctx.hasCommand(SupportedCommands.dalleLC.name) || - (ctx.message?.text?.startsWith('dalle ') && ctx.chat?.type === 'private') + ctx.hasCommand([SupportedCommands.dalle.name, SupportedCommands.dalleShort.name]) || + (ctx.message?.text?.startsWith('image ') && ctx.chat?.type === 'private') ) { let prompt = (ctx.match ? ctx.match : ctx.message?.text) as string if (!prompt || prompt.split(' ').length === 1) { @@ -257,13 +257,34 @@ export class OpenAIBot implements PayableBot { return } - if (hasNewPrefix(ctx.message?.text ?? '') !== '') { + const text = ctx.message?.text ?? '' + + if (hasNewPrefix(text) !== '') { await this.onEnd(ctx) await this.onPrefix(ctx) return } - if (hasChatPrefix(ctx.message?.text ?? '') !== '') { + if (hasDallePrefix(text) !== '') { + const prefix = hasDallePrefix(text) + let prompt = (ctx.match ? ctx.match : ctx.message?.text) as string + if (!prompt || prompt.split(' ').length === 1) { + prompt = config.openAi.dalle.defaultPrompt + } + ctx.session.openAi.imageGen.imgRequestQueue.push({ + command: 'dalle', + prompt: prompt.slice(prefix.length) + }) + if (!ctx.session.openAi.imageGen.isProcessingQueue) { + ctx.session.openAi.imageGen.isProcessingQueue = true + await this.onImgRequestHandler(ctx).then(() => { + ctx.session.openAi.imageGen.isProcessingQueue = false + }) + } + return + } + + if (hasChatPrefix(text) !== '') { await this.onPrefix(ctx) return } diff --git a/src/modules/sd-images/helpers.ts b/src/modules/sd-images/helpers.ts index 8b2f2e03..9025679e 100644 --- a/src/modules/sd-images/helpers.ts +++ b/src/modules/sd-images/helpers.ts @@ -5,9 +5,9 @@ import { getLoraByParam, type ILora } from './api/loras-config' import { childrenWords, sexWords } from './words-blacklist' export enum COMMAND { - TEXT_TO_IMAGE = 'image', + TEXT_TO_IMAGE = 'sdimage', IMAGE_TO_IMAGE = 'img2img', - TEXT_TO_IMAGES = 'images', + TEXT_TO_IMAGES = 'sdimages', CONSTRUCTOR = 'constructor', HELP = 'help', TRAIN = 'train' @@ -38,7 +38,7 @@ const removeSpaceFromBegin = (text: string): string => { return text.slice(idx) } -const SPECIAL_IMG_CMD_SYMBOLS = ['i.', 'l.', 'I.', '? ', '! ', ': ', '; ', 'r.', 'R.', 'd.', 'D.', '( ', '$ ', '& ', '< '] +const SPECIAL_IMG_CMD_SYMBOLS = ['l.', '? ', '! ', ': ', '; ', 'r.', 'R.', 'd.', 'D.', '( ', '$ ', '& ', '< '] export const getPrefix = (prompt: string, prefixList: string[]): string => { for (let i = 0; i < prefixList.length; i++) { @@ -126,13 +126,13 @@ export const parseCtx = (ctx: Context): IOperation | false => { } if ( - (hasCommand(ctx, 'image') || hasCommand(ctx, 'imagine')) || hasCommand(ctx, 'img') + (hasCommand(ctx, 'sdimage') || hasCommand(ctx, 'sdimagine')) || hasCommand(ctx, 'sdimg') ) { command = COMMAND.TEXT_TO_IMAGE } if ( - (hasCommand(ctx, 'image2') || hasCommand(ctx, 'imagine2')) || hasCommand(ctx, 'img2') + (hasCommand(ctx, 'sdimage2') || hasCommand(ctx, 'sdimagine2')) || hasCommand(ctx, 'sdimg2') ) { command = COMMAND.TEXT_TO_IMAGE model = model && ({ ...model, serverNumber: 2 }) @@ -146,7 +146,7 @@ export const parseCtx = (ctx: Context): IOperation | false => { lora = getLoraByParam('logo', model?.baseModel ?? 'SDXL 1.0') } - if (hasCommand(ctx, 'images')) { + if (hasCommand(ctx, 'sd-images')) { command = COMMAND.TEXT_TO_IMAGES } From bb8833f052a52531937ddd7aeb82bde6135c758e Mon Sep 17 00:00:00 2001 From: fegloff Date: Tue, 9 Jan 2024 21:03:23 -0400 Subject: [PATCH 6/7] update dalle pricing --- src/modules/open-ai/types.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/modules/open-ai/types.ts b/src/modules/open-ai/types.ts index 46a214fb..46a60c9e 100644 --- a/src/modules/open-ai/types.ts +++ b/src/modules/open-ai/types.ts @@ -52,22 +52,22 @@ export const ChatGPTModels: Record = { export const DalleGPTModels: Record = { '1024x1792': { size: '1024x1792', - price: 0.02 + price: 0.10 }, '1792x1024': { size: '1792x1024', - price: 0.02 + price: 0.10 }, '1024x1024': { size: '1024x1024', - price: 0.02 + price: 0.10 }, '512x512': { size: '512x512', - price: 0.018 + price: 0.10 }, '256x256': { size: '256x256', - price: 0.016 + price: 0.10 } } From 499ad36a56a5ef12f4c20a8a6d0eb9895ece8a30 Mon Sep 17 00:00:00 2001 From: fegloff Date: Wed, 10 Jan 2024 23:31:43 -0400 Subject: [PATCH 7/7] add /i command --- src/modules/open-ai/helpers.ts | 6 ++++-- src/modules/open-ai/index.ts | 11 ++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/modules/open-ai/helpers.ts b/src/modules/open-ai/helpers.ts index dc329752..a873124f 100644 --- a/src/modules/open-ai/helpers.ts +++ b/src/modules/open-ai/helpers.ts @@ -16,8 +16,10 @@ export const SupportedCommands = { ask32: { name: 'ask32' }, gpt: { name: 'gpt' }, last: { name: 'last' }, - dalle: { name: 'image' }, + dalle: { name: 'dalle' }, + dalleImg: { name: 'image' }, dalleShort: { name: 'img' }, + dalleShorter: { name: 'i' }, genImgEn: { name: 'genImgEn' }, on: { name: 'on' }, off: { name: 'off' } @@ -25,7 +27,7 @@ export const SupportedCommands = { export const MAX_TRIES = 3 -const DALLE_PREFIX_LIST = ['i.', ', ', 'image ', 'd.', 'img '] +const DALLE_PREFIX_LIST = ['i. ', ',', 'image ', 'd.', 'img ', 'i '] export const isMentioned = ( ctx: OnMessageContext | OnCallBackQueryData diff --git a/src/modules/open-ai/index.ts b/src/modules/open-ai/index.ts index 3642eac4..809006aa 100644 --- a/src/modules/open-ai/index.ts +++ b/src/modules/open-ai/index.ts @@ -101,8 +101,10 @@ export class OpenAIBot implements PayableBot { return 0 } if ( - ctx.hasCommand(SupportedCommands.dalle.name) || - ctx.hasCommand(SupportedCommands.dalleShort.name) + ctx.hasCommand([SupportedCommands.dalle.name, + SupportedCommands.dalleImg.name, + SupportedCommands.dalleShort.name, + SupportedCommands.dalleShorter.name]) ) { const imageNumber = ctx.session.openAi.imageGen.numImages const imageSize = ctx.session.openAi.imageGen.imgSize @@ -227,7 +229,10 @@ export class OpenAIBot implements PayableBot { } if ( - ctx.hasCommand([SupportedCommands.dalle.name, SupportedCommands.dalleShort.name]) || + ctx.hasCommand([SupportedCommands.dalle.name, + SupportedCommands.dalleImg.name, + SupportedCommands.dalleShort.name, + SupportedCommands.dalleShorter.name]) || (ctx.message?.text?.startsWith('image ') && ctx.chat?.type === 'private') ) { let prompt = (ctx.match ? ctx.match : ctx.message?.text) as string