feat(04-01): add openai dependency and AI config
- Add openai package to dependencies in pyproject.toml - Extend BotConfig with ai_router, ai_api_key, ai_referer attributes - Load AI settings from environment with sensible defaults Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
4ea13efe8f
commit
3740691dac
2 changed files with 18 additions and 0 deletions
|
|
@ -9,6 +9,7 @@ dependencies = [
|
||||||
"sqlalchemy",
|
"sqlalchemy",
|
||||||
"httpx",
|
"httpx",
|
||||||
"aiosqlite",
|
"aiosqlite",
|
||||||
|
"openai",
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.optional-dependencies]
|
[project.optional-dependencies]
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,18 @@ class BotConfig:
|
||||||
allowed_users: Set of allowed Telegram user IDs. Empty means all users allowed.
|
allowed_users: Set of allowed Telegram user IDs. Empty means all users allowed.
|
||||||
database_url: SQLAlchemy database URL.
|
database_url: SQLAlchemy database URL.
|
||||||
log_level: Logging level string (DEBUG, INFO, WARNING, ERROR).
|
log_level: Logging level string (DEBUG, INFO, WARNING, ERROR).
|
||||||
|
ai_router: AI router service ("requesty" or "openrouter").
|
||||||
|
ai_api_key: API key for the AI router service.
|
||||||
|
ai_referer: HTTP-Referer header for OpenRouter (optional).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
bot_token: str
|
bot_token: str
|
||||||
allowed_users: set[int]
|
allowed_users: set[int]
|
||||||
database_url: str
|
database_url: str
|
||||||
log_level: str
|
log_level: str
|
||||||
|
ai_router: str
|
||||||
|
ai_api_key: str
|
||||||
|
ai_referer: str | None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_env(cls) -> "BotConfig":
|
def from_env(cls) -> "BotConfig":
|
||||||
|
|
@ -33,6 +39,9 @@ class BotConfig:
|
||||||
ALLOWED_USERS (optional): Comma-separated Telegram user IDs.
|
ALLOWED_USERS (optional): Comma-separated Telegram user IDs.
|
||||||
DATABASE_URL (optional): Database URL, defaults to SQLite.
|
DATABASE_URL (optional): Database URL, defaults to SQLite.
|
||||||
LOG_LEVEL (optional): Logging level, defaults to INFO.
|
LOG_LEVEL (optional): Logging level, defaults to INFO.
|
||||||
|
AI_ROUTER (optional): AI router service, defaults to "requesty".
|
||||||
|
AI_API_KEY (optional): API key for the AI router service.
|
||||||
|
AI_REFERER (optional): HTTP-Referer header for OpenRouter.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
BotConfig instance populated from environment.
|
BotConfig instance populated from environment.
|
||||||
|
|
@ -56,9 +65,17 @@ class BotConfig:
|
||||||
database_url = os.environ.get("DATABASE_URL", "sqlite+aiosqlite:///./moai.db")
|
database_url = os.environ.get("DATABASE_URL", "sqlite+aiosqlite:///./moai.db")
|
||||||
log_level = os.environ.get("LOG_LEVEL", "INFO")
|
log_level = os.environ.get("LOG_LEVEL", "INFO")
|
||||||
|
|
||||||
|
# AI router configuration
|
||||||
|
ai_router = os.environ.get("AI_ROUTER", "requesty")
|
||||||
|
ai_api_key = os.environ.get("AI_API_KEY", "")
|
||||||
|
ai_referer = os.environ.get("AI_REFERER")
|
||||||
|
|
||||||
return cls(
|
return cls(
|
||||||
bot_token=bot_token,
|
bot_token=bot_token,
|
||||||
allowed_users=allowed_users,
|
allowed_users=allowed_users,
|
||||||
database_url=database_url,
|
database_url=database_url,
|
||||||
log_level=log_level,
|
log_level=log_level,
|
||||||
|
ai_router=ai_router,
|
||||||
|
ai_api_key=ai_api_key,
|
||||||
|
ai_referer=ai_referer,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue