Skip to content

Commit c2685a9

Browse files
committed
feat: improve data collection and logging
1 parent 7b47a27 commit c2685a9

6 files changed

Lines changed: 730 additions & 505 deletions

File tree

src/balatrollm/__init__.py

Lines changed: 61 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
"""BalatroLLM project."""
22

3+
__version__ = "0.2.0"
4+
35
import argparse
46
import asyncio
57
import os
68
import sys
79
from pathlib import Path
810

9-
from .llm import Config, LLMBot, setup_logging
11+
from .bot import LLMBot, setup_logging
12+
from .config import Config
1013

1114

1215
def main() -> None:
1316
"""Main CLI entry point for balatrollm."""
17+
parser = _create_argument_parser()
18+
args = parser.parse_args()
19+
20+
_setup_logging(args.verbose)
21+
_validate_config_file(args.config)
22+
23+
asyncio.run(run_bot(args))
24+
25+
26+
def _create_argument_parser() -> argparse.ArgumentParser:
27+
"""Create and configure argument parser."""
1428
parser = argparse.ArgumentParser(
1529
description="LLM-powered Balatro bot using LiteLLM proxy",
1630
formatter_class=argparse.RawDescriptionHelpFormatter,
@@ -27,85 +41,96 @@ def main() -> None:
2741
default=os.getenv("LITELLM_MODEL", "cerebras-qwen3-235b"),
2842
help="Model name to use from LiteLLM proxy (default: cerebras-qwen3-235b)",
2943
)
30-
3144
parser.add_argument(
3245
"--proxy-url",
3346
default=os.getenv("LITELLM_PROXY_URL", "http://localhost:4000"),
3447
help="LiteLLM proxy URL (default: http://localhost:4000)",
3548
)
36-
3749
parser.add_argument(
3850
"--api-key",
3951
default=os.getenv("LITELLM_API_KEY", "sk-balatrollm-proxy-key"),
4052
help="LiteLLM proxy API key (default: sk-balatrollm-proxy-key)",
4153
)
42-
4354
parser.add_argument(
4455
"--list-models",
4556
action="store_true",
4657
help="List available models from the proxy and exit",
4758
)
48-
4959
parser.add_argument(
5060
"--config",
5161
default="config/litellm.yaml",
5262
help="Path to LiteLLM configuration file (default: config/litellm.yaml)",
5363
)
54-
64+
parser.add_argument(
65+
"--template",
66+
default=os.getenv("BALATROLLM_TEMPLATE", "default"),
67+
help="Strategy template to use (default: default)",
68+
)
5569
parser.add_argument(
5670
"--verbose", "-v", action="store_true", help="Enable verbose logging"
5771
)
5872

59-
args = parser.parse_args()
73+
return parser
6074

61-
# Configure logging
62-
import logging
6375

64-
setup_logging(args.verbose)
65-
logger = logging.getLogger(__name__)
76+
def _setup_logging(verbose: bool) -> None:
77+
"""Configure application logging."""
78+
setup_logging(verbose)
6679

67-
# Check if config file exists
68-
config_path = Path(args.config)
69-
if not config_path.exists():
70-
logger.error(f"LiteLLM config file not found: {config_path}")
80+
81+
def _validate_config_file(config_path: str) -> None:
82+
"""Validate LiteLLM config file exists."""
83+
import logging
84+
85+
config_file = Path(config_path)
86+
if not config_file.exists():
87+
logger = logging.getLogger(__name__)
88+
logger.error(f"LiteLLM config file not found: {config_file}")
7189
logger.error("Please create the config file or start the proxy manually:")
72-
logger.error(f" litellm --config {config_path}")
90+
logger.error(f" litellm --config {config_file}")
7391
sys.exit(1)
7492

75-
# Create and run the bot
76-
asyncio.run(run_bot(args))
77-
7893

7994
async def run_bot(args) -> None:
8095
"""Run the Balatro bot with the given arguments."""
8196
config = Config(
8297
model=args.model,
8398
proxy_url=args.proxy_url,
8499
api_key=args.api_key,
85-
template="default", # Default template, could be made configurable
100+
template=args.template,
86101
)
87-
bot = LLMBot(config)
102+
bot = LLMBot(config, verbose=args.verbose)
88103

89-
# List models if requested
90104
if args.list_models:
91-
print("Checking available models from LiteLLM proxy...")
92-
if not await bot.validate_proxy_connection():
93-
print(f"❌ Cannot connect to LiteLLM proxy at {args.proxy_url}")
94-
print(f"Please start the proxy with: litellm --config {args.config}")
95-
sys.exit(1)
96-
97-
models = await bot.list_available_models()
98-
if models:
99-
print("✅ Available models:")
100-
for model in models:
101-
print(f" - {model}")
102-
else:
103-
print("❌ No models available or failed to retrieve models")
105+
await _list_models(bot, args)
104106
return
105107

106-
# Validate proxy connection and model before starting game
108+
await _start_game(bot, args)
109+
110+
111+
async def _list_models(bot: LLMBot, args) -> None:
112+
"""List available models and exit."""
113+
print("Checking available models from LiteLLM proxy...")
114+
115+
if not await bot.validate_proxy_connection():
116+
print(f"❌ Cannot connect to LiteLLM proxy at {args.proxy_url}")
117+
print(f"Please start the proxy with: litellm --config {args.config}")
118+
sys.exit(1)
119+
120+
models = await bot.list_available_models()
121+
if models:
122+
print("✅ Available models:")
123+
for model in models:
124+
print(f" - {model}")
125+
else:
126+
print("❌ No models available or failed to retrieve models")
127+
128+
129+
async def _start_game(bot: LLMBot, args) -> None:
130+
"""Start the game after validation."""
107131
print(f"🤖 Starting Balatro LLM Bot with model: {args.model}")
108132

133+
# Validate connections
109134
if not await bot.validate_proxy_connection():
110135
print(f"❌ Cannot connect to LiteLLM proxy at {args.proxy_url}")
111136
print(f"Please start the proxy with: litellm --config {args.config}")

0 commit comments

Comments
 (0)