aaa
This commit is contained in:
parent
6f8a337835
commit
dd8bc2f6a4
18
gurt/cog.py
18
gurt/cog.py
@ -16,7 +16,7 @@ from tavily import TavilyClient # Needed for tavily_client init
|
|||||||
|
|
||||||
# --- Relative Imports from Gurt Package ---
|
# --- Relative Imports from Gurt Package ---
|
||||||
from .config import (
|
from .config import (
|
||||||
API_KEY, TAVILY_API_KEY, OPENROUTER_API_URL, DEFAULT_MODEL, FALLBACK_MODEL,
|
PROJECT_ID, LOCATION, TAVILY_API_KEY, DEFAULT_MODEL, FALLBACK_MODEL, # Use GCP config
|
||||||
DB_PATH, CHROMA_PATH, SEMANTIC_MODEL_NAME, MAX_USER_FACTS, MAX_GENERAL_FACTS,
|
DB_PATH, CHROMA_PATH, SEMANTIC_MODEL_NAME, MAX_USER_FACTS, MAX_GENERAL_FACTS,
|
||||||
MOOD_OPTIONS, BASELINE_PERSONALITY, BASELINE_INTERESTS, MOOD_CHANGE_INTERVAL_MIN,
|
MOOD_OPTIONS, BASELINE_PERSONALITY, BASELINE_INTERESTS, MOOD_CHANGE_INTERVAL_MIN,
|
||||||
MOOD_CHANGE_INTERVAL_MAX, CHANNEL_TOPIC_CACHE_TTL, CONTEXT_WINDOW_SIZE,
|
MOOD_CHANGE_INTERVAL_MAX, CHANNEL_TOPIC_CACHE_TTL, CONTEXT_WINDOW_SIZE,
|
||||||
@ -41,14 +41,13 @@ from . import config as GurtConfig # Import config module for get_gurt_stats
|
|||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
class GurtCog(commands.Cog, name="Gurt"): # Added explicit Cog name
|
class GurtCog(commands.Cog, name="Gurt"): # Added explicit Cog name
|
||||||
"""A special cog for the Gurt bot that uses OpenRouter API"""
|
"""A special cog for the Gurt bot that uses Google Vertex AI API"""
|
||||||
|
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.api_key = API_KEY # Use imported config
|
# GCP Project/Location are used by vertexai.init() in api.py
|
||||||
self.tavily_api_key = TAVILY_API_KEY # Use imported config
|
self.tavily_api_key = TAVILY_API_KEY # Use imported config
|
||||||
self.api_url = OPENROUTER_API_URL # Use imported config
|
self.session: Optional[aiohttp.ClientSession] = None # Keep for other potential HTTP requests (e.g., Piston)
|
||||||
self.session: Optional[aiohttp.ClientSession] = None # Initialize session as None
|
|
||||||
self.tavily_client = TavilyClient(api_key=self.tavily_api_key) if self.tavily_api_key else None
|
self.tavily_client = TavilyClient(api_key=self.tavily_api_key) if self.tavily_api_key else None
|
||||||
self.default_model = DEFAULT_MODEL # Use imported config
|
self.default_model = DEFAULT_MODEL # Use imported config
|
||||||
self.fallback_model = FALLBACK_MODEL # Use imported config
|
self.fallback_model = FALLBACK_MODEL # Use imported config
|
||||||
@ -161,10 +160,8 @@ class GurtCog(commands.Cog, name="Gurt"): # Added explicit Cog name
|
|||||||
await self.memory_manager.load_baseline_personality(BASELINE_PERSONALITY)
|
await self.memory_manager.load_baseline_personality(BASELINE_PERSONALITY)
|
||||||
await self.memory_manager.load_baseline_interests(BASELINE_INTERESTS)
|
await self.memory_manager.load_baseline_interests(BASELINE_INTERESTS)
|
||||||
|
|
||||||
if not self.api_key:
|
# Vertex AI initialization happens in api.py using PROJECT_ID and LOCATION from config
|
||||||
print("WARNING: OpenRouter API key not configured (AI_API_KEY).")
|
print(f"GurtCog: Using default model: {self.default_model}")
|
||||||
else:
|
|
||||||
print(f"GurtCog: Using model: {self.default_model}")
|
|
||||||
if not self.tavily_api_key:
|
if not self.tavily_api_key:
|
||||||
print("WARNING: Tavily API key not configured (TAVILY_API_KEY). Web search disabled.")
|
print("WARNING: Tavily API key not configured (TAVILY_API_KEY). Web search disabled.")
|
||||||
|
|
||||||
@ -258,7 +255,8 @@ class GurtCog(commands.Cog, name="Gurt"): # Added explicit Cog name
|
|||||||
stats["config"]["topic_update_interval"] = GurtConfig.TOPIC_UPDATE_INTERVAL
|
stats["config"]["topic_update_interval"] = GurtConfig.TOPIC_UPDATE_INTERVAL
|
||||||
stats["config"]["sentiment_update_interval"] = GurtConfig.SENTIMENT_UPDATE_INTERVAL
|
stats["config"]["sentiment_update_interval"] = GurtConfig.SENTIMENT_UPDATE_INTERVAL
|
||||||
stats["config"]["docker_command_timeout"] = GurtConfig.DOCKER_COMMAND_TIMEOUT
|
stats["config"]["docker_command_timeout"] = GurtConfig.DOCKER_COMMAND_TIMEOUT
|
||||||
stats["config"]["api_key_set"] = bool(GurtConfig.API_KEY) # Don't expose key itself
|
stats["config"]["project_id_set"] = bool(GurtConfig.PROJECT_ID != "your-gcp-project-id") # Check if default is overridden
|
||||||
|
stats["config"]["location_set"] = bool(GurtConfig.LOCATION != "us-central1") # Check if default is overridden
|
||||||
stats["config"]["tavily_api_key_set"] = bool(GurtConfig.TAVILY_API_KEY)
|
stats["config"]["tavily_api_key_set"] = bool(GurtConfig.TAVILY_API_KEY)
|
||||||
stats["config"]["piston_api_url_set"] = bool(GurtConfig.PISTON_API_URL)
|
stats["config"]["piston_api_url_set"] = bool(GurtConfig.PISTON_API_URL)
|
||||||
|
|
||||||
|
@ -39,7 +39,6 @@ async def main():
|
|||||||
"""Main async function to load the gurt cog and start the bot."""
|
"""Main async function to load the gurt cog and start the bot."""
|
||||||
# Check for required environment variables
|
# Check for required environment variables
|
||||||
TOKEN = os.getenv('DISCORD_TOKEN_GURT')
|
TOKEN = os.getenv('DISCORD_TOKEN_GURT')
|
||||||
OPENROUTER_API_KEY = os.getenv('AI_API_KEY')
|
|
||||||
|
|
||||||
# If Discord token not found, try to use the main bot token
|
# If Discord token not found, try to use the main bot token
|
||||||
if not TOKEN:
|
if not TOKEN:
|
||||||
@ -48,10 +47,8 @@ async def main():
|
|||||||
if not TOKEN:
|
if not TOKEN:
|
||||||
raise ValueError("No Discord token found. Make sure to set DISCORD_TOKEN_GURT or DISCORD_TOKEN in your .env file.")
|
raise ValueError("No Discord token found. Make sure to set DISCORD_TOKEN_GURT or DISCORD_TOKEN in your .env file.")
|
||||||
|
|
||||||
if not OPENROUTER_API_KEY:
|
# Note: Vertex AI authentication is handled by the library using ADC or GOOGLE_APPLICATION_CREDENTIALS.
|
||||||
print("Warning: AI_API_KEY not found in environment variables. AI functionality will not work.")
|
# No explicit API key check is needed here. Ensure GCP_PROJECT_ID and GCP_LOCATION are set in .env
|
||||||
print("Please set the AI_API_KEY in your .env file.")
|
|
||||||
print("You can get an API key from https://openrouter.ai/keys")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
async with bot:
|
async with bot:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user