Skip to content

Commit

Permalink
move set functions to modelizer
Browse files Browse the repository at this point in the history
  • Loading branch information
A-Baji committed Jul 1, 2024
1 parent 209780c commit 845cab5
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions discordai/command_line/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,6 @@
from discordai import bot
from discordai.command_line import subparsers
from discordai_modelizer.command_line import command_line
from discordai_modelizer.command_line.subparsers import (
set_openai_help_str,
set_bot_key_help_str,
)


def set_openai_api_key(key: str, config):
if not key and not config["OPENAI_API_KEY"]:
raise ValueError(
f"Your OpenAI API key must either be passed in as an argument or set {set_openai_help_str(is_parent=True)}",
)
else:
return key or config["OPENAI_API_KEY"]


def set_bot_token(token: str, config):
if not token and not config["DISCORD_BOT_TOKEN"]:
raise ValueError(
f"Your Discord bot token must either be passed in as an argument or set {set_bot_key_help_str(is_parent=True)}",
)
else:
return token or config["DISCORD_BOT_TOKEN"]


def discordai():
Expand Down Expand Up @@ -58,9 +36,13 @@ def discordai():
args = parser.parse_args()
config = configuration.get()
if hasattr(args, "openai_key"):
args.openai_key = set_openai_api_key(args.openai_key, config)
args.openai_key = command_line.set_openai_api_key(
args.openai_key, config, is_parent=True
)
if hasattr(args, "discord_token"):
args.discord_token = set_bot_token(args.discord_token, config)
args.discord_token = command_line.set_bot_token(
args.discord_token, config, is_parent=True
)

if args.command in ["model", "job"]:
command_line.read_modelizer_args(args, model_subcommand, job_subcommand)
Expand Down

0 comments on commit 845cab5

Please sign in to comment.