mirror of
https://github.com/aljazceru/chatgpt-telegram-bot.git
synced 2025-12-23 23:55:05 +01:00
Merge branch 'main' into Chinese
This commit is contained in:
46
README.md
46
README.md
@@ -25,7 +25,7 @@ A [Telegram bot](https://core.telegram.org/bots/api) that integrates with OpenAI
|
|||||||
- [x] (NEW!) GPT-4 support
|
- [x] (NEW!) GPT-4 support
|
||||||
- If you have access to the GPT-4 API, simply change the `OPENAI_MODEL` parameter to `gpt-4`
|
- If you have access to the GPT-4 API, simply change the `OPENAI_MODEL` parameter to `gpt-4`
|
||||||
- [x] (NEW!) Localized bot language
|
- [x] (NEW!) Localized bot language
|
||||||
- Available languages :gb: :de: :ru: :tr: :it: :es: :indonesia: :cn:
|
- Available languages :gb: :de: :ru: :tr: :it: :es: :indonesia: :netherlands: :cn:
|
||||||
- [x] (NEW!) Improved inline queries support for group and private chats - by [@bugfloyd](https://github.com/bugfloyd)
|
- [x] (NEW!) Improved inline queries support for group and private chats - by [@bugfloyd](https://github.com/bugfloyd)
|
||||||
- To use this feature, enable inline queries for your bot in BotFather via the `/setinline` [command](https://core.telegram.org/bots/inline)
|
- To use this feature, enable inline queries for your bot in BotFather via the `/setinline` [command](https://core.telegram.org/bots/inline)
|
||||||
|
|
||||||
@@ -68,28 +68,28 @@ The following parameters are optional and can be set in the `.env` file:
|
|||||||
Check out the [Budget Manual](https://github.com/n3d1117/chatgpt-telegram-bot/discussions/184) for possible budget configurations.
|
Check out the [Budget Manual](https://github.com/n3d1117/chatgpt-telegram-bot/discussions/184) for possible budget configurations.
|
||||||
|
|
||||||
#### Additional optional configuration options
|
#### Additional optional configuration options
|
||||||
| Parameter | Description | Default value |
|
| Parameter | Description | Default value |
|
||||||
|------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------|
|
|------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------|
|
||||||
| `ENABLE_QUOTING` | Whether to enable message quoting in private chats | `true` |
|
| `ENABLE_QUOTING` | Whether to enable message quoting in private chats | `true` |
|
||||||
| `ENABLE_IMAGE_GENERATION` | Whether to enable image generation via the `/image` command | `true` |
|
| `ENABLE_IMAGE_GENERATION` | Whether to enable image generation via the `/image` command | `true` |
|
||||||
| `ENABLE_TRANSCRIPTION` | Whether to enable transcriptions of audio and video messages | `true` |
|
| `ENABLE_TRANSCRIPTION` | Whether to enable transcriptions of audio and video messages | `true` |
|
||||||
| `PROXY` | Proxy to be used for OpenAI and Telegram bot (e.g. `http://localhost:8080`) | - |
|
| `PROXY` | Proxy to be used for OpenAI and Telegram bot (e.g. `http://localhost:8080`) | - |
|
||||||
| `OPENAI_MODEL` | The OpenAI model to use for generating responses | `gpt-3.5-turbo` |
|
| `OPENAI_MODEL` | The OpenAI model to use for generating responses | `gpt-3.5-turbo` |
|
||||||
| `ASSISTANT_PROMPT` | A system message that sets the tone and controls the behavior of the assistant | `You are a helpful assistant.` |
|
| `ASSISTANT_PROMPT` | A system message that sets the tone and controls the behavior of the assistant | `You are a helpful assistant.` |
|
||||||
| `SHOW_USAGE` | Whether to show OpenAI token usage information after each response | `false` |
|
| `SHOW_USAGE` | Whether to show OpenAI token usage information after each response | `false` |
|
||||||
| `STREAM` | Whether to stream responses. **Note**: incompatible, if enabled, with `N_CHOICES` higher than 1 | `true` |
|
| `STREAM` | Whether to stream responses. **Note**: incompatible, if enabled, with `N_CHOICES` higher than 1 | `true` |
|
||||||
| `MAX_TOKENS` | Upper bound on how many tokens the ChatGPT API will return | `1200` for GPT-3, `2400` for GPT-4 |
|
| `MAX_TOKENS` | Upper bound on how many tokens the ChatGPT API will return | `1200` for GPT-3, `2400` for GPT-4 |
|
||||||
| `MAX_HISTORY_SIZE` | Max number of messages to keep in memory, after which the conversation will be summarised to avoid excessive token usage | `15` |
|
| `MAX_HISTORY_SIZE` | Max number of messages to keep in memory, after which the conversation will be summarised to avoid excessive token usage | `15` |
|
||||||
| `MAX_CONVERSATION_AGE_MINUTES` | Maximum number of minutes a conversation should live since the last message, after which the conversation will be reset | `180` |
|
| `MAX_CONVERSATION_AGE_MINUTES` | Maximum number of minutes a conversation should live since the last message, after which the conversation will be reset | `180` |
|
||||||
| `VOICE_REPLY_WITH_TRANSCRIPT_ONLY` | Whether to answer to voice messages with the transcript only or with a ChatGPT response of the transcript | `true` |
|
| `VOICE_REPLY_WITH_TRANSCRIPT_ONLY` | Whether to answer to voice messages with the transcript only or with a ChatGPT response of the transcript | `true` |
|
||||||
| `N_CHOICES` | Number of answers to generate for each input message. **Note**: setting this to a number higher than 1 will not work properly if `STREAM` is enabled | `1` |
|
| `N_CHOICES` | Number of answers to generate for each input message. **Note**: setting this to a number higher than 1 will not work properly if `STREAM` is enabled | `1` |
|
||||||
| `TEMPERATURE` | Number between 0 and 2. Higher values will make the output more random | `1.0` |
|
| `TEMPERATURE` | Number between 0 and 2. Higher values will make the output more random | `1.0` |
|
||||||
| `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` |
|
| `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` |
|
| `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_SIZE` | The DALL·E generated image size. Allowed values: `256x256`, `512x512` or `1024x1024` | `512x512` |
|
||||||
| `GROUP_TRIGGER_KEYWORD` | If set, the bot in group chats will only respond to messages that start with this keyword | - |
|
| `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` |
|
| `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`, `es`, `id`, `cn`. **Note** [Contribute additional translations](https://github.com/n3d1117/chatgpt-telegram-bot/discussions/219) | `en` |
|
| `BOT_LANGUAGE` | Language of general bot messages. Currently available: `en`, `de`, `ru`, `tr`, `it`, `es`, `id`, `nl`, `cn`. [Contribute with additional translations](https://github.com/n3d1117/chatgpt-telegram-bot/discussions/219) | `en` |
|
||||||
|
|
||||||
Check out the [official API reference](https://platform.openai.com/docs/api-reference/chat) for more details.
|
Check out the [official API reference](https://platform.openai.com/docs/api-reference/chat) for more details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
import tiktoken
|
import tiktoken
|
||||||
|
|
||||||
@@ -26,11 +27,12 @@ def default_max_tokens(model: str) -> int:
|
|||||||
"""
|
"""
|
||||||
return 1200 if model in GPT_3_MODELS else 2400
|
return 1200 if model in GPT_3_MODELS else 2400
|
||||||
|
|
||||||
|
# Load translations
|
||||||
with open('translations.json', 'r', encoding='utf-8') as f:
|
parent_dir_path = os.path.join(os.path.dirname(__file__), os.pardir)
|
||||||
|
translations_file_path = os.path.join(parent_dir_path, 'translations.json')
|
||||||
|
with open(translations_file_path, 'r', encoding='utf-8') as f:
|
||||||
translations = json.load(f)
|
translations = json.load(f)
|
||||||
|
|
||||||
|
|
||||||
def localized_text(key, bot_language):
|
def localized_text(key, bot_language):
|
||||||
"""
|
"""
|
||||||
Return translated text for a key in specified bot_language.
|
Return translated text for a key in specified bot_language.
|
||||||
|
|||||||
@@ -293,6 +293,48 @@
|
|||||||
"ask_chatgpt": "Tanya ChatGPT",
|
"ask_chatgpt": "Tanya ChatGPT",
|
||||||
"loading": "Sedang memuat..."
|
"loading": "Sedang memuat..."
|
||||||
},
|
},
|
||||||
|
"nl": {
|
||||||
|
"help_description":"Toon uitleg",
|
||||||
|
"reset_description":"Herstart het gesprek. Voeg eventueel instructies toe (bijv. /reset Je bent een behulpzame assistent)",
|
||||||
|
"image_description":"Genereer een afbeelding van een prompt (bijv. /image kat)",
|
||||||
|
"stats_description":"Bekijk je huidige gebruiksstatistieken",
|
||||||
|
"resend_description":"Verstuur het laatste bericht opnieuw",
|
||||||
|
"chat_description":"Chat met de bot!",
|
||||||
|
"disallowed":"Sorry, je hebt geen bevoegdheid om deze bot te gebruiken. Je kunt de sourcecode bekijken op https://github.com/n3d1117/chatgpt-telegram-bot",
|
||||||
|
"budget_limit":"Sorry, je hebt je gebruikslimiet bereikt.",
|
||||||
|
"help_text":["Ik ben een ChatGPT bot, praat met me.", "Stuur me een spraakbericht en ik transcribreer het", "Open de source code op https://github.com/n3d1117/chatgpt-telegram-bot"],
|
||||||
|
"stats_conversation":["Huidig gesprek", "chatberichten in historie", "chat tokens in historie"],
|
||||||
|
"usage_today":"Gebruik vandaag",
|
||||||
|
"usage_month":"Gebruik deze maand",
|
||||||
|
"stats_tokens":"chat tokens gebruikt",
|
||||||
|
"stats_images":"afbeeldingen gegenereerd",
|
||||||
|
"stats_transcribe":["minuten en", "seconden getranscribreerd"],
|
||||||
|
"stats_total":"💰 Voor een totaal van $",
|
||||||
|
"stats_budget":"Je resterende budget",
|
||||||
|
"monthly":" voor deze maand",
|
||||||
|
"daily":" voor vandaag",
|
||||||
|
"all-time":"",
|
||||||
|
"stats_openai":"Deze maand is je OpenAI account gefactureerd voor $",
|
||||||
|
"resend_failed":"Je hebt niks om opnieuw te sturen",
|
||||||
|
"reset_done":"Klaar!",
|
||||||
|
"image_no_prompt":"Geef a.u.b. een prompt! (bijv. /image kat)",
|
||||||
|
"image_fail":"Afbeelding genereren mislukt",
|
||||||
|
"media_download_fail":["Audio bestand downloaden mislukt", "Check of het niet te groot is. (max 20MB)"],
|
||||||
|
"media_type_fail":"Niet ondersteund bestandsformaat",
|
||||||
|
"transcript":"Transcriptie",
|
||||||
|
"answer":"Antwoord",
|
||||||
|
"transcribe_fail":"Transcribreren mislukt",
|
||||||
|
"chat_fail":"Reactie verkrijgen mislukt",
|
||||||
|
"prompt":"prompt",
|
||||||
|
"completion":"completion",
|
||||||
|
"openai_rate_limit":"OpenAI Rate Limit overschreden",
|
||||||
|
"openai_invalid":"OpenAI ongeldig verzoek",
|
||||||
|
"error":"Er is een fout opgetreden",
|
||||||
|
"try_again":"Probeer het a.u.b. later opnieuw",
|
||||||
|
"answer_with_chatgpt":"Antwoord met ChatGPT",
|
||||||
|
"ask_chatgpt":"Vraag ChatGPT",
|
||||||
|
"loading":"Laden..."
|
||||||
|
},
|
||||||
"cn": {
|
"cn": {
|
||||||
"help_description":"显示帮助信息",
|
"help_description":"显示帮助信息",
|
||||||
"reset_description":"重置对话。可以选择传递高级指令(例如/reset 你是一个有用的助手)",
|
"reset_description":"重置对话。可以选择传递高级指令(例如/reset 你是一个有用的助手)",
|
||||||
|
|||||||
Reference in New Issue
Block a user