From 5a1a3733c545db4e2284335938b2fda3c66e3f73 Mon Sep 17 00:00:00 2001 From: Kumi Date: Tue, 7 Nov 2023 14:02:10 +0100 Subject: [PATCH] Update OpenAI configuration with ImageModel and related changes Previously, there was no option to specify the model for image generation in the OpenAI configuration. This commit adds a new option called "ImageModel" where you can specify the desired model. The default value for this option is "dall-e-2". In the `GPTBot` class, the OpenAI object is now initialized with the `ImageModel` option if it is provided in the configuration. This allows the bot to use the specified image generation model in addition to the chat model. Furthermore, in the `OpenAI` class, the `image_api` attribute has been renamed to `image_model` to reflect its purpose more accurately. The default value has also been updated to "dall-e-2" to align with the new configuration option. This commit ensures that the OpenAI configuration is up-to-date and allows users to specify the desired image generation model. --- config.dist.ini | 4 ++++ src/gptbot/classes/bot.py | 3 ++- src/gptbot/classes/openai.py | 5 +++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/config.dist.ini b/config.dist.ini index 91fe066..a4026a5 100644 --- a/config.dist.ini +++ b/config.dist.ini @@ -67,6 +67,10 @@ LogLevel = info # # Model = gpt-3.5-turbo +# The Image Generation model you want to use. +# +# ImageModel = dall-e-2 + # Your OpenAI API key # # Find this in your OpenAI account: diff --git a/src/gptbot/classes/bot.py b/src/gptbot/classes/bot.py index 5e7c271..9800581 100644 --- a/src/gptbot/classes/bot.py +++ b/src/gptbot/classes/bot.py @@ -138,7 +138,8 @@ class GPTBot: bot.allowed_users = json.loads(config["GPTBot"]["AllowedUsers"]) bot.chat_api = bot.image_api = bot.classification_api = OpenAI( - config["OpenAI"]["APIKey"], config["OpenAI"].get("Model"), bot.logger + config["OpenAI"]["APIKey"], config["OpenAI"].get("Model"), + config["OpenAI"].get("ImageModel"), bot.logger ) bot.max_tokens = config["OpenAI"].getint("MaxTokens", bot.max_tokens) bot.max_messages = config["OpenAI"].getint("MaxMessages", bot.max_messages) diff --git a/src/gptbot/classes/openai.py b/src/gptbot/classes/openai.py index fcff3e3..8eb9344 100644 --- a/src/gptbot/classes/openai.py +++ b/src/gptbot/classes/openai.py @@ -21,11 +21,11 @@ class OpenAI: return self.chat_model classification_api = chat_api - image_api: str = "dalle" + image_model: str = "dall-e-2" operator: str = "OpenAI ([https://openai.com](https://openai.com))" - def __init__(self, api_key, chat_model=None, logger=None): + def __init__(self, api_key, chat_model=None, image_model=None, logger=None): self.api_key = api_key self.chat_model = chat_model or self.chat_model self.logger = logger or Logger() @@ -146,6 +146,7 @@ Only the event_types mentioned above are allowed, you must not respond in any ot image_partial = partial( openai.Image.acreate, + model=self.image_model, prompt=prompt, n=1, api_key=self.api_key,