mirror of
https://github.com/aljazceru/chatgpt-telegram-bot.git
synced 2026-01-11 08:55:46 +01:00
Merge branch 'feature/voice-chat-mode'
This commit is contained in:
@@ -11,4 +11,7 @@ ALLOWED_TELEGRAM_USER_IDS="USER_ID_1,USER_ID_2"
|
||||
SHOW_USAGE=false
|
||||
|
||||
# Max number of messages to keep in memory, after which the conversation will be summarised
|
||||
MAX_HISTORY_SIZE=10
|
||||
MAX_HISTORY_SIZE=10
|
||||
|
||||
# Whether to answer to voice messages with the transcript or with a ChatGPT response of the transcript
|
||||
VOICE_REPLY_WITH_TRANSCRIPT_ONLY=true
|
||||
@@ -45,6 +45,7 @@ ALLOWED_TELEGRAM_USER_IDS="USER_ID_1,USER_ID_2,..." # Defaults to "*" (everyone)
|
||||
PROXY="YOUR_PROXY" # e.g. "http://localhost:8080", defaults to none
|
||||
SHOW_USAGE=true # Defaults to false
|
||||
MAX_HISTORY_SIZE=15 # Defaults to 10
|
||||
VOICE_REPLY_WITH_TRANSCRIPT_ONLY=false # Defaults to true
|
||||
```
|
||||
* `OPENAI_API_KEY`: Your OpenAI API key, you can get it from [here](https://platform.openai.com/account/api-keys)
|
||||
* `TELEGRAM_BOT_TOKEN`: Your Telegram bot's token, obtained using [BotFather](http://t.me/botfather) (see [tutorial](https://core.telegram.org/bots/tutorial#obtain-your-bot-token))
|
||||
@@ -52,6 +53,7 @@ MAX_HISTORY_SIZE=15 # Defaults to 10
|
||||
* `PROXY`: Proxy to be used for OpenAI and Telegram bot
|
||||
* `SHOW_USAGE`: Whether to show OpenAI token usage information after each response
|
||||
* `MAX_HISTORY_SIZE`: Max number of messages to keep in memory, after which the conversation will be summarised to avoid excessive token usage ([#34](https://github.com/n3d1117/chatgpt-telegram-bot/issues/34))
|
||||
* `VOICE_REPLY_WITH_TRANSCRIPT_ONLY`: Whether to answer to voice messages with the transcript only or with a ChatGPT response of the transcript ([#38](https://github.com/n3d1117/chatgpt-telegram-bot/issues/38))
|
||||
|
||||
Additional model parameters can be configured from the `main.py` file:
|
||||
```python
|
||||
|
||||
3
main.py
3
main.py
@@ -62,7 +62,8 @@ def main():
|
||||
telegram_config = {
|
||||
'token': os.environ['TELEGRAM_BOT_TOKEN'],
|
||||
'allowed_user_ids': os.environ.get('ALLOWED_TELEGRAM_USER_IDS', '*'),
|
||||
'proxy': os.environ.get('PROXY', None)
|
||||
'proxy': os.environ.get('PROXY', None),
|
||||
'voice_reply_transcript': os.environ.get('VOICE_REPLY_WITH_TRANSCRIPT_ONLY', 'true').lower() == 'true',
|
||||
}
|
||||
|
||||
# Setup and run ChatGPT and Telegram bot
|
||||
|
||||
@@ -122,13 +122,23 @@ class ChatGPT3TelegramBot:
|
||||
# Transcribe the audio file
|
||||
transcript = self.openai.transcribe(filename_mp3)
|
||||
|
||||
# Send the transcript
|
||||
await context.bot.send_message(
|
||||
chat_id=chat_id,
|
||||
reply_to_message_id=update.message.message_id,
|
||||
text=transcript,
|
||||
parse_mode=constants.ParseMode.MARKDOWN
|
||||
)
|
||||
if self.config['voice_reply_transcript']:
|
||||
# Send the transcript
|
||||
await context.bot.send_message(
|
||||
chat_id=chat_id,
|
||||
reply_to_message_id=update.message.message_id,
|
||||
text=f'_Transcript:_\n"{transcript}"',
|
||||
parse_mode=constants.ParseMode.MARKDOWN
|
||||
)
|
||||
else:
|
||||
# Send the response of the transcript
|
||||
response = self.openai.get_chat_response(chat_id=chat_id, query=transcript)
|
||||
await context.bot.send_message(
|
||||
chat_id=chat_id,
|
||||
reply_to_message_id=update.message.message_id,
|
||||
text=response,
|
||||
parse_mode=constants.ParseMode.MARKDOWN
|
||||
)
|
||||
except Exception as e:
|
||||
logging.exception(e)
|
||||
await context.bot.send_message(
|
||||
|
||||
Reference in New Issue
Block a user