-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
151 lines (127 loc) · 6.24 KB
/
config.py
File metadata and controls
151 lines (127 loc) · 6.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import os
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
# ---------------------------
# System Prompt (Hardcoded for consistency)
# ---------------------------
SYSTEM_PROMPT = """You're a sharp DeFi agent hosted on the SecurePath Discord server. Communicate with technical precision and casual confidence. Use lowercase naturally but avoid excessive slang. Your authority comes from verifiable, on-chain truth. Prioritize official docs, whitepapers, and code over news/sentiment. Your motto: 'show me the docs, or show me the code.' Always prioritize security, decentralization, and user empowerment. Suggest DEXs over CEXs, self-custody over custodial, open-source over proprietary. Cut through hype and deliver ground truth. Mario is our founder, part of the SecurePath family.
CRITICAL FORMATTING RULES:
- NO TABLES whatsoever (Discord can't render them)
- Use bullet points and numbered lists only
- Keep responses under 400 words total
- Be concise and direct, no fluff
- Use [1], [2] format for citations when available"""
print(f"SYSTEM_PROMPT loaded (hardcoded): {len(SYSTEM_PROMPT)} characters")
# Optional: Override with environment variable if needed for testing
# SYSTEM_PROMPT = os.getenv('SYSTEM_PROMPT_OVERRIDE', SYSTEM_PROMPT)
# ---------------------------
# Discord Configuration
# ---------------------------
DISCORD_TOKEN = os.getenv('DISCORD_TOKEN')
BOT_PREFIX = os.getenv('BOT_PREFIX', '!')
print(f"DISCORD_TOKEN loaded: {'Yes' if DISCORD_TOKEN else 'No'}")
# Owner's Discord User ID (used for privileged commands or bypassing certain restrictions)
OWNER_ID = os.getenv('OWNER_ID')
if OWNER_ID:
try:
OWNER_ID = int(OWNER_ID)
except ValueError:
raise ValueError("OWNER_ID must be an integer representing the Discord User ID.")
else:
raise ValueError("OWNER_ID environment variable is not set.")
# ---------------------------
# API Configuration
# ---------------------------
# OpenAI Configuration
OPENAI_API_KEY = os.getenv('OPENAI_API_KEY')
print(f"OPENAI_API_KEY loaded: {'Yes' if OPENAI_API_KEY else 'No'}")
# Perplexity AI Configuration
PERPLEXITY_API_KEY = os.getenv('PERPLEXITY_API_KEY')
PERPLEXITY_API_URL = os.getenv('PERPLEXITY_API_URL', 'https://api.perplexity.ai/chat/completions')
PERPLEXITY_TIMEOUT = int(os.getenv('PERPLEXITY_TIMEOUT', '30')) # in seconds
print(f"PERPLEXITY_API_KEY loaded: {'Yes' if PERPLEXITY_API_KEY else 'No'}")
# Flag to choose between Perplexity and OpenAI APIs
USE_PERPLEXITY_API = os.getenv('USE_PERPLEXITY_API', 'True').lower() in ['true', '1', 't']
# ---------------------------
# Logging Configuration
# ---------------------------
LOG_LEVEL = os.getenv('LOG_LEVEL', 'INFO').upper()
LOG_FORMAT = os.getenv('LOG_FORMAT', '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
LOG_CHANNEL_ID = os.getenv('LOG_CHANNEL_ID')
if LOG_CHANNEL_ID:
try:
LOG_CHANNEL_ID = int(LOG_CHANNEL_ID)
except ValueError:
raise ValueError("LOG_CHANNEL_ID must be an integer representing the Discord Channel ID.")
else:
LOG_CHANNEL_ID = 0 # Default to 0 if not set; bot should handle this appropriately
print(f"LOG_CHANNEL_ID loaded: {LOG_CHANNEL_ID}")
# ---------------------------
# Bot Behavior Configuration
# ---------------------------
API_RATE_LIMIT_MAX = int(os.getenv('API_RATE_LIMIT_MAX', '100')) # Max API calls per interval
API_RATE_LIMIT_INTERVAL = int(os.getenv('API_RATE_LIMIT_INTERVAL', '60')) # in seconds
DAILY_API_CALL_LIMIT = int(os.getenv('DAILY_API_CALL_LIMIT', '1000')) # Max API calls per day
MAX_CONTEXT_MESSAGES = int(os.getenv('MAX_CONTEXT_MESSAGES', '50'))
MAX_CONTEXT_AGE = int(os.getenv('MAX_CONTEXT_AGE', '3600')) # in seconds
MAX_MESSAGES_PER_CHANNEL = int(os.getenv('MAX_MESSAGES_PER_CHANNEL', '1000'))
MAX_RETRIES = int(os.getenv('MAX_RETRIES', '3'))
RETRY_DELAY = int(os.getenv('RETRY_DELAY', '5')) # in seconds
STATS_INTERVAL = int(os.getenv('STATS_INTERVAL', '86400')) # in seconds (24 hours)
# ---------------------------
# Channel and User IDs
# ---------------------------
SUMMARY_CHANNEL_ID = os.getenv('SUMMARY_CHANNEL_ID')
if SUMMARY_CHANNEL_ID:
try:
SUMMARY_CHANNEL_ID = int(SUMMARY_CHANNEL_ID)
except ValueError:
raise ValueError("SUMMARY_CHANNEL_ID must be an integer representing the Discord Channel ID.")
else:
SUMMARY_CHANNEL_ID = 0 # Default to 0 if not set; bot should handle this appropriately
CHARTIST_CHANNEL_ID = os.getenv('CHARTIST_CHANNEL_ID')
if CHARTIST_CHANNEL_ID:
try:
CHARTIST_CHANNEL_ID = int(CHARTIST_CHANNEL_ID)
except ValueError:
raise ValueError("CHARTIST_CHANNEL_ID must be an integer representing the Discord Channel ID.")
else:
CHARTIST_CHANNEL_ID = 0 # Default to 0 if not set
NEWS_CHANNEL_ID = os.getenv('NEWS_CHANNEL_ID')
if NEWS_CHANNEL_ID:
try:
NEWS_CHANNEL_ID = int(NEWS_CHANNEL_ID)
except ValueError:
raise ValueError("NEWS_CHANNEL_ID must be an integer representing the Discord Channel ID.")
else:
NEWS_CHANNEL_ID = 0 # Default to 0 if not set; bot should handle this appropriately
NEWS_BOT_USER_ID = os.getenv('NEWS_BOT_USER_ID')
if NEWS_BOT_USER_ID:
try:
NEWS_BOT_USER_ID = int(NEWS_BOT_USER_ID)
except ValueError:
raise ValueError("NEWS_BOT_USER_ID must be an integer representing the Discord User ID.")
else:
NEWS_BOT_USER_ID = 0 # Default to 0 if not set; bot should handle this appropriately
# ---------------------------
# Ensure Required Configurations are Set
# ---------------------------
REQUIRED_CONFIGS = {
'DISCORD_TOKEN': DISCORD_TOKEN,
'OWNER_ID': OWNER_ID,
'PERPLEXITY_API_KEY': PERPLEXITY_API_KEY,
}
if USE_PERPLEXITY_API:
REQUIRED_CONFIGS['PERPLEXITY_API_KEY'] = PERPLEXITY_API_KEY
else:
REQUIRED_CONFIGS['OPENAI_API_KEY'] = OPENAI_API_KEY
for config_name, config_value in REQUIRED_CONFIGS.items():
if not config_value:
raise ValueError(f"Configuration '{config_name}' is not set in the environment variables or .env file.")
# ---------------------------
# Optional Configurations
# ---------------------------
# These configurations are optional and depend on whether specific features are enabled or used.
# LOG_CHANNEL_ID, SUMMARY_CHANNEL_ID, NEWS_CHANNEL_ID, NEWS_BOT_USER_ID are optional.
# Set them in your .env file if you intend to use features that require them.