Compare commits
2 Commits
366bee2e43
...
8b14160028
| Author | SHA1 | Date | |
|---|---|---|---|
| 8b14160028 | |||
| 02686c3b96 |
@@ -1746,9 +1746,9 @@ def get_autonomous_stats():
|
|||||||
|
|
||||||
@app.get("/conversation/{user_id}")
|
@app.get("/conversation/{user_id}")
|
||||||
def get_conversation(user_id: str):
|
def get_conversation(user_id: str):
|
||||||
if user_id in globals.conversation_history:
|
"""Get conversation history for a user/channel (uses centralized ConversationHistory)."""
|
||||||
return {"conversation": list(globals.conversation_history[user_id])}
|
messages = conversation_history.get_recent_messages(user_id)
|
||||||
return {"conversation": []}
|
return {"conversation": [{"author": author, "content": content, "is_bot": is_bot} for author, content, is_bot in messages]}
|
||||||
|
|
||||||
# ========== Figurine DM Subscription APIs ==========
|
# ========== Figurine DM Subscription APIs ==========
|
||||||
@app.get("/figurines/subscribers")
|
@app.get("/figurines/subscribers")
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import asyncio
|
|||||||
import globals
|
import globals
|
||||||
from utils.moods import load_mood_description
|
from utils.moods import load_mood_description
|
||||||
from utils.scheduled import send_bedtime_reminder
|
from utils.scheduled import send_bedtime_reminder
|
||||||
|
from utils.conversation_history import conversation_history
|
||||||
from utils.logger import get_logger
|
from utils.logger import get_logger
|
||||||
|
|
||||||
logger = get_logger('commands')
|
logger = get_logger('commands')
|
||||||
@@ -32,7 +33,7 @@ def calm_miku() -> str:
|
|||||||
|
|
||||||
|
|
||||||
def reset_conversation(user_id):
|
def reset_conversation(user_id):
|
||||||
globals.conversation_history[str(user_id)].clear()
|
conversation_history.clear_channel(str(user_id))
|
||||||
|
|
||||||
|
|
||||||
async def force_sleep() -> str:
|
async def force_sleep() -> str:
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
# globals.py
|
# globals.py
|
||||||
import os
|
import os
|
||||||
from collections import defaultdict, deque
|
|
||||||
import discord
|
import discord
|
||||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||||
|
|
||||||
scheduler = AsyncIOScheduler()
|
scheduler = AsyncIOScheduler()
|
||||||
|
|
||||||
# Stores last 5 exchanges per user (as deque)
|
|
||||||
conversation_history = defaultdict(lambda: deque(maxlen=5))
|
|
||||||
|
|
||||||
DISCORD_BOT_TOKEN = os.getenv("DISCORD_BOT_TOKEN")
|
DISCORD_BOT_TOKEN = os.getenv("DISCORD_BOT_TOKEN")
|
||||||
|
|
||||||
# Autonomous V2 Debug Mode (set to True to see detailed decision logging)
|
# Autonomous V2 Debug Mode (set to True to see detailed decision logging)
|
||||||
@@ -26,6 +22,7 @@ VISION_MODEL = os.getenv("VISION_MODEL", "vision")
|
|||||||
EVIL_TEXT_MODEL = os.getenv("EVIL_TEXT_MODEL", "darkidol") # Uncensored model for evil mode
|
EVIL_TEXT_MODEL = os.getenv("EVIL_TEXT_MODEL", "darkidol") # Uncensored model for evil mode
|
||||||
JAPANESE_TEXT_MODEL = os.getenv("JAPANESE_TEXT_MODEL", "swallow") # Llama 3.1 Swallow model for Japanese
|
JAPANESE_TEXT_MODEL = os.getenv("JAPANESE_TEXT_MODEL", "swallow") # Llama 3.1 Swallow model for Japanese
|
||||||
OWNER_USER_ID = int(os.getenv("OWNER_USER_ID", "209381657369772032")) # Bot owner's Discord user ID for reports
|
OWNER_USER_ID = int(os.getenv("OWNER_USER_ID", "209381657369772032")) # Bot owner's Discord user ID for reports
|
||||||
|
PREFER_AMD_GPU = os.getenv("PREFER_AMD_GPU", "false").lower() == "true" # Runtime-overridable via config API
|
||||||
|
|
||||||
# Cheshire Cat AI integration (Phase 3)
|
# Cheshire Cat AI integration (Phase 3)
|
||||||
CHESHIRE_CAT_URL = os.getenv("CHESHIRE_CAT_URL", "http://cheshire-cat:80")
|
CHESHIRE_CAT_URL = os.getenv("CHESHIRE_CAT_URL", "http://cheshire-cat:80")
|
||||||
|
|||||||
@@ -1034,8 +1034,8 @@ async def run_argument(channel: discord.TextChannel, client, trigger_context: st
|
|||||||
|
|
||||||
# Clean up argument conversation history
|
# Clean up argument conversation history
|
||||||
try:
|
try:
|
||||||
conversation_history.clear_history(argument_user_id)
|
conversation_history.clear_channel(argument_user_id)
|
||||||
except:
|
except Exception:
|
||||||
pass # History cleanup is not critical
|
pass # History cleanup is not critical
|
||||||
|
|
||||||
end_argument(channel_id)
|
end_argument(channel_id)
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ from datetime import datetime
|
|||||||
from typing import List, Dict, Any, Tuple
|
from typing import List, Dict, Any, Tuple
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
import globals
|
|
||||||
|
|
||||||
|
from utils.conversation_history import conversation_history
|
||||||
from utils.twitter_fetcher import fetch_figurine_tweets_latest
|
from utils.twitter_fetcher import fetch_figurine_tweets_latest
|
||||||
from utils.image_handling import analyze_image_with_qwen, download_and_encode_image
|
from utils.image_handling import analyze_image_with_qwen, download_and_encode_image
|
||||||
from utils.llm import query_llama
|
from utils.llm import query_llama
|
||||||
@@ -204,15 +204,11 @@ async def send_figurine_dm_to_user(client: discord.Client, user_id: int, tweet:
|
|||||||
# Log the comment message
|
# Log the comment message
|
||||||
dm_logger.log_user_message(user, comment_message, is_bot_message=True)
|
dm_logger.log_user_message(user, comment_message, is_bot_message=True)
|
||||||
|
|
||||||
# IMPORTANT: Also add to globals.conversation_history for LLM context
|
# Add to conversation history for LLM context (uses centralized ConversationHistory)
|
||||||
user_id_str = str(user_id)
|
user_id_str = str(user_id)
|
||||||
|
|
||||||
# Add the tweet URL as a "system message" about what Miku just sent (use original URL for context)
|
|
||||||
tweet_context = f"[I just sent you this figurine tweet: {tweet_url}]"
|
tweet_context = f"[I just sent you this figurine tweet: {tweet_url}]"
|
||||||
|
conversation_history.add_message(channel_id=user_id_str, author_name="Miku", content=tweet_context, is_bot=True)
|
||||||
# Add the figurine comment to conversation history
|
conversation_history.add_message(channel_id=user_id_str, author_name="Miku", content=miku_comment, is_bot=True)
|
||||||
# Use empty user prompt since this was initiated by Miku
|
|
||||||
globals.conversation_history.setdefault(user_id_str, []).append((tweet_context, miku_comment))
|
|
||||||
|
|
||||||
logger.debug(f"Messages logged to both DM history and conversation context for user {user_id}")
|
logger.debug(f"Messages logged to both DM history and conversation context for user {user_id}")
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ MODEL_TO_GPU = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
PREFER_AMD_GPU = os.getenv("PREFER_AMD_GPU", "false").lower() == "true"
|
# PREFER_AMD_GPU lives in globals so the config API can update it at runtime.
|
||||||
|
# We read globals.PREFER_AMD_GPU in functions below instead of a frozen local.
|
||||||
AMD_MODELS_ENABLED = os.getenv("AMD_MODELS_ENABLED", "true").lower() == "true"
|
AMD_MODELS_ENABLED = os.getenv("AMD_MODELS_ENABLED", "true").lower() == "true"
|
||||||
|
|
||||||
|
|
||||||
@@ -101,7 +102,7 @@ def get_llama_url_with_load_balancing(
|
|||||||
return globals.LLAMA_URL, "llama3.1"
|
return globals.LLAMA_URL, "llama3.1"
|
||||||
|
|
||||||
# AMD enabled - implement load balancing
|
# AMD enabled - implement load balancing
|
||||||
use_amd = prefer_amd or PREFER_AMD_GPU or (random.random() < 0.5)
|
use_amd = prefer_amd or globals.PREFER_AMD_GPU or (random.random() < 0.5)
|
||||||
|
|
||||||
if task_type == "evil":
|
if task_type == "evil":
|
||||||
# Evil/uncensored models
|
# Evil/uncensored models
|
||||||
|
|||||||
@@ -475,10 +475,6 @@ Please respond in a way that reflects this emotional tone.{pfp_context}"""
|
|||||||
is_bot=True
|
is_bot=True
|
||||||
)
|
)
|
||||||
|
|
||||||
# Also save to legacy globals for backward compatibility (skip error messages)
|
|
||||||
if user_prompt and user_prompt.strip() and reply and reply.strip() and reply != "Someone tell Koko-nii there is a problem with my AI.":
|
|
||||||
globals.conversation_history[user_id].append((user_prompt, reply))
|
|
||||||
|
|
||||||
return reply
|
return reply
|
||||||
else:
|
else:
|
||||||
error_text = await response.text()
|
error_text = await response.text()
|
||||||
|
|||||||
Reference in New Issue
Block a user