mirror of
https://github.com/aljazceru/chatgpt-telegram-bot.git
synced 2025-12-20 06:05:12 +01:00
support new models and update dependencies
`gpt-3.5-turbo-0613`, `gpt-3.5-turbo-16k`, `gpt-3.5-turbo-16k-0613`, `gpt-4-0613`, `gpt-4-32k-0613`
This commit is contained in:
@@ -69,12 +69,12 @@ Check out the [Budget Manual](https://github.com/n3d1117/chatgpt-telegram-bot/di
|
||||
|
||||
#### Additional optional configuration options
|
||||
| Parameter | Description | Default value |
|
||||
|------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------|
|
||||
|------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------|
|
||||
| `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_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`) | - |
|
||||
| `OPENAI_MODEL` | The OpenAI model to use for generating responses | `gpt-3.5-turbo` |
|
||||
| `OPENAI_MODEL` | The OpenAI model to use for generating responses. You can find all available models [here](https://platform.openai.com/docs/models/) | `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.` |
|
||||
| `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` |
|
||||
|
||||
@@ -13,10 +13,11 @@ from datetime import date
|
||||
from calendar import monthrange
|
||||
|
||||
# Models can be found here: https://platform.openai.com/docs/models/overview
|
||||
GPT_3_MODELS = ("gpt-3.5-turbo", "gpt-3.5-turbo-0301")
|
||||
GPT_4_MODELS = ("gpt-4", "gpt-4-0314")
|
||||
GPT_4_32K_MODELS = ("gpt-4-32k", "gpt-4-32k-0314")
|
||||
GPT_ALL_MODELS = GPT_3_MODELS + GPT_4_MODELS + GPT_4_32K_MODELS
|
||||
GPT_3_MODELS = ("gpt-3.5-turbo", "gpt-3.5-turbo-0301", "gpt-3.5-turbo-0613")
|
||||
GPT_3_16K_MODELS = ("gpt-3.5-turbo-16k", "gpt-3.5-turbo-16k-0613")
|
||||
GPT_4_MODELS = ("gpt-4", "gpt-4-0314", "gpt-4-0613")
|
||||
GPT_4_32K_MODELS = ("gpt-4-32k", "gpt-4-32k-0314", "gpt-4-32k-0613")
|
||||
GPT_ALL_MODELS = GPT_3_MODELS + GPT_3_16K_MODELS + GPT_4_MODELS + GPT_4_32K_MODELS
|
||||
|
||||
|
||||
def default_max_tokens(model: str) -> int:
|
||||
@@ -25,7 +26,16 @@ def default_max_tokens(model: str) -> int:
|
||||
:param model: The model name
|
||||
:return: The default number of max tokens
|
||||
"""
|
||||
return 1200 if model in GPT_3_MODELS else 2400
|
||||
base = 1200
|
||||
if model in GPT_3_MODELS:
|
||||
return base
|
||||
elif model in GPT_4_MODELS:
|
||||
return base * 2
|
||||
elif model in GPT_3_16K_MODELS:
|
||||
return base * 4
|
||||
elif model in GPT_4_32K_MODELS:
|
||||
return base * 8
|
||||
|
||||
|
||||
# Load translations
|
||||
parent_dir_path = os.path.join(os.path.dirname(__file__), os.pardir)
|
||||
@@ -33,6 +43,7 @@ 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)
|
||||
|
||||
|
||||
def localized_text(key, bot_language):
|
||||
"""
|
||||
Return translated text for a key in specified bot_language.
|
||||
@@ -272,12 +283,15 @@ class OpenAIHelper:
|
||||
return response.choices[0]['message']['content']
|
||||
|
||||
def __max_model_tokens(self):
|
||||
base = 4096
|
||||
if self.config['model'] in GPT_3_MODELS:
|
||||
return 4096
|
||||
return base
|
||||
if self.config['model'] in GPT_3_16K_MODELS:
|
||||
return base * 4
|
||||
if self.config['model'] in GPT_4_MODELS:
|
||||
return 8192
|
||||
return base * 2
|
||||
if self.config['model'] in GPT_4_32K_MODELS:
|
||||
return 32768
|
||||
return base * 8
|
||||
raise NotImplementedError(
|
||||
f"Max tokens for model {self.config['model']} is not implemented yet."
|
||||
)
|
||||
@@ -295,7 +309,7 @@ class OpenAIHelper:
|
||||
except KeyError:
|
||||
encoding = tiktoken.get_encoding("gpt-3.5-turbo")
|
||||
|
||||
if model in GPT_3_MODELS:
|
||||
if model in GPT_3_MODELS + GPT_3_16K_MODELS:
|
||||
tokens_per_message = 4 # every message follows <|start|>{role/name}\n{content}<|end|>\n
|
||||
tokens_per_name = -1 # if there's a name, the role is omitted
|
||||
elif model in GPT_4_MODELS + GPT_4_32K_MODELS:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
python-dotenv~=1.0.0
|
||||
pydub~=0.25.1
|
||||
tiktoken==0.3.3
|
||||
openai==0.27.4
|
||||
tiktoken==0.4.0
|
||||
openai==0.27.8
|
||||
python-telegram-bot==20.2
|
||||
Reference in New Issue
Block a user