mirror of
https://github.com/aljazceru/chatgpt-telegram-bot.git
synced 2025-12-20 22:24:57 +01:00
Merge branch 'main' into tts-support
This commit is contained in:
@@ -21,10 +21,11 @@ from plugin_manager import PluginManager
|
||||
|
||||
# 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-3.5-turbo-0613")
|
||||
GPT_3_16K_MODELS = ("gpt-3.5-turbo-16k", "gpt-3.5-turbo-16k-0613")
|
||||
GPT_3_16K_MODELS = ("gpt-3.5-turbo-16k", "gpt-3.5-turbo-16k-0613", "gpt-3.5-turbo-1106")
|
||||
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
|
||||
GPT_4_128K_MODELS = ("gpt-4-1106-preview",)
|
||||
GPT_ALL_MODELS = GPT_3_MODELS + GPT_3_16K_MODELS + GPT_4_MODELS + GPT_4_32K_MODELS + GPT_4_128K_MODELS
|
||||
|
||||
|
||||
def default_max_tokens(model: str) -> int:
|
||||
@@ -38,10 +39,14 @@ def default_max_tokens(model: str) -> int:
|
||||
return base
|
||||
elif model in GPT_4_MODELS:
|
||||
return base * 2
|
||||
elif model in GPT_3_16K_MODELS:
|
||||
elif model in GPT_3_16K_MODELS:
|
||||
if model == "gpt-3.5-turbo-1106":
|
||||
return 4096
|
||||
return base * 4
|
||||
elif model in GPT_4_32K_MODELS:
|
||||
return base * 8
|
||||
elif model in GPT_4_128K_MODELS:
|
||||
return 4096
|
||||
|
||||
|
||||
def are_functions_available(model: str) -> bool:
|
||||
@@ -52,7 +57,7 @@ def are_functions_available(model: str) -> bool:
|
||||
if model in ("gpt-3.5-turbo-0301", "gpt-4-0314", "gpt-4-32k-0314"):
|
||||
return False
|
||||
# Stable models will be updated to support functions on June 27, 2023
|
||||
if model in ("gpt-3.5-turbo", "gpt-4", "gpt-4-32k"):
|
||||
if model in ("gpt-3.5-turbo", "gpt-3.5-turbo-1106", "gpt-4", "gpt-4-32k","gpt-4-1106-preview"):
|
||||
return datetime.date.today() > datetime.date(2023, 6, 27)
|
||||
return True
|
||||
|
||||
@@ -321,6 +326,9 @@ class OpenAIHelper:
|
||||
response = await self.client.images.generate(
|
||||
prompt=prompt,
|
||||
n=1,
|
||||
model=self.config['image_model'],
|
||||
quality=self.config['image_quality'],
|
||||
style=self.config['image_style'],
|
||||
size=self.config['image_size']
|
||||
)
|
||||
|
||||
@@ -421,7 +429,7 @@ class OpenAIHelper:
|
||||
messages=messages,
|
||||
temperature=0.4
|
||||
)
|
||||
return response.choices[0]['message']['content']
|
||||
return response.choices[0].message.content
|
||||
|
||||
def __max_model_tokens(self):
|
||||
base = 4096
|
||||
@@ -433,6 +441,8 @@ class OpenAIHelper:
|
||||
return base * 2
|
||||
if self.config['model'] in GPT_4_32K_MODELS:
|
||||
return base * 8
|
||||
if self.config['model'] in GPT_4_128K_MODELS:
|
||||
return base * 31
|
||||
raise NotImplementedError(
|
||||
f"Max tokens for model {self.config['model']} is not implemented yet."
|
||||
)
|
||||
@@ -453,7 +463,7 @@ class OpenAIHelper:
|
||||
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:
|
||||
elif model in GPT_4_MODELS + GPT_4_32K_MODELS + GPT_4_128K_MODELS:
|
||||
tokens_per_message = 3
|
||||
tokens_per_name = 1
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user