mirror of
https://github.com/aljazceru/chatgpt-telegram-bot.git
synced 2026-01-07 15:05:41 +01:00
add image receive mode
This commit is contained in:
@@ -35,6 +35,7 @@ ALLOWED_TELEGRAM_USER_IDS=USER_ID_1,USER_ID_2
|
||||
# PRESENCE_PENALTY=0.0
|
||||
# FREQUENCY_PENALTY=0.0
|
||||
# IMAGE_SIZE=512x512
|
||||
# IMAGE_FORMAT=document
|
||||
# GROUP_TRIGGER_KEYWORD=""
|
||||
# IGNORE_GROUP_TRANSCRIPTIONS=true
|
||||
# BOT_LANGUAGE=en
|
||||
@@ -96,6 +96,7 @@ Check out the [Budget Manual](https://github.com/n3d1117/chatgpt-telegram-bot/di
|
||||
| `PRESENCE_PENALTY` | Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far | `0.0` |
|
||||
| `FREQUENCY_PENALTY` | Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far | `0.0` |
|
||||
| `IMAGE_SIZE` | The DALL·E generated image size. Allowed values: `256x256`, `512x512` or `1024x1024` | `512x512` |
|
||||
| `IMAGE_RECEIVE_MODE` | The Telegram image receive mode. Allowed values: `document` or `photo` | `photo` |
|
||||
| `GROUP_TRIGGER_KEYWORD` | If set, the bot in group chats will only respond to messages that start with this keyword | - |
|
||||
| `IGNORE_GROUP_TRANSCRIPTIONS` | If set to true, the bot will not process transcriptions in group chats | `true` |
|
||||
| `BOT_LANGUAGE` | Language of general bot messages. Currently available: `en`, `de`, `ru`, `tr`, `it`, `fi`, `es`, `id`, `nl`, `zh-cn`, `zh-tw`, `vi`, `fa`, `pt-br`, `uk`, `ms`. [Contribute with additional translations](https://github.com/n3d1117/chatgpt-telegram-bot/discussions/219) | `en` |
|
||||
|
||||
@@ -81,6 +81,7 @@ def main():
|
||||
'group_trigger_keyword': os.environ.get('GROUP_TRIGGER_KEYWORD', ''),
|
||||
'token_price': float(os.environ.get('TOKEN_PRICE', 0.002)),
|
||||
'image_prices': [float(i) for i in os.environ.get('IMAGE_PRICES', "0.016,0.018,0.02").split(",")],
|
||||
'image_receive_mode': os.environ.get('IMAGE_RECEIVE_MODE', "photo"),
|
||||
'transcription_price': float(os.environ.get('TRANSCRIPTION_PRICE', 0.006)),
|
||||
'bot_language': os.environ.get('BOT_LANGUAGE', 'en'),
|
||||
}
|
||||
|
||||
@@ -228,10 +228,18 @@ class ChatGPTTelegramBot:
|
||||
async def _generate():
|
||||
try:
|
||||
image_url, image_size = await self.openai.generate_image(prompt=image_query)
|
||||
await update.effective_message.reply_photo(
|
||||
reply_to_message_id=get_reply_to_message_id(self.config, update),
|
||||
photo=image_url
|
||||
)
|
||||
if self.config['image_receive_mode'] == 'photo':
|
||||
await update.effective_message.reply_photo(
|
||||
reply_to_message_id=get_reply_to_message_id(self.config, update),
|
||||
photo=image_url
|
||||
)
|
||||
elif self.config['image_receive_mode'] == 'document':
|
||||
await update.effective_message.reply_document(
|
||||
reply_to_message_id=get_reply_to_message_id(self.config, update),
|
||||
document=image_url
|
||||
)
|
||||
else:
|
||||
raise Exception(f"env variable IMAGE_RECEIVE_MODE has invalid value {self.config['image_receive_mode']}")
|
||||
# add image request to users usage tracker
|
||||
user_id = update.message.from_user.id
|
||||
self.usage[user_id].add_image_request(image_size, self.config['image_prices'])
|
||||
|
||||
Reference in New Issue
Block a user