Commit c6e6f92b authored by Your Name's avatar Your Name

feat: implement user-specific prompts database storage and resolution

- Add user_id parameter to ContextManager
- Check database for user-specific prompts before filesystem
- Pass user_id from RequestHandler to ContextManager
- Update autoselect prompt loading to respect user-specific prompts
- All authenticated requests get user-specific prompts when available
- Global tokens skip database lookup entirely
parent b92c6b3d
......@@ -35,7 +35,7 @@ class ContextManager:
Manages context size and performs condensation when needed.
"""
def __init__(self, model_config: Dict, provider_handler=None, condensation_config=None):
def __init__(self, model_config: Dict, provider_handler=None, condensation_config=None, user_id=None):
"""
Initialize the context manager.
......@@ -43,12 +43,14 @@ class ContextManager:
model_config: Model configuration dictionary containing context_size, condense_context, condense_method
provider_handler: Optional provider handler for making summarization requests (fallback)
condensation_config: Optional condensation configuration for dedicated provider/model/rotation
user_id: Optional user ID for user-specific prompt overrides
"""
self.context_size = model_config.get('context_size')
self.condense_context = model_config.get('condense_context', 0)
self.condense_method = model_config.get('condense_method')
self.provider_handler = provider_handler
self.condensation_config = condensation_config or config.get_condensation()
self.user_id = user_id
# Initialize condensation provider handler if configured
self.condensation_handler = None
......@@ -458,6 +460,15 @@ class ContextManager:
def _load_system_prompt(self, method: str) -> str:
"""Load system prompt from markdown file"""
from pathlib import Path
from .database import get_database
# Check for user-specific prompt first if user_id is present
if self.user_id is not None:
db = get_database()
prompt_key = f'condensation_{method}'
user_prompt = db.get_user_prompt(self.user_id, prompt_key)
if user_prompt is not None:
return user_prompt
# Try installed locations first
installed_dirs = [
......
......@@ -436,7 +436,7 @@ class RequestHandler:
# Apply context condensation if needed
if context_config.get('condense_context', 0) > 0:
context_manager = ContextManager(context_config, handler, self.config.get_condensation())
context_manager = ContextManager(context_config, handler, self.config.get_condensation(), self.user_id)
if context_manager.should_condense(messages, model):
logger.info("Context condensation triggered")
messages = await context_manager.condense_context(messages, model)
......@@ -2798,7 +2798,7 @@ class RotationHandler:
# Apply context condensation if needed
if context_config.get('condense_context', 0) > 0:
context_manager = ContextManager(context_config, handler, self.config.get_condensation())
context_manager = ContextManager(context_config, handler, self.config.get_condensation(), self.user_id)
if context_manager.should_condense(messages, model_name):
logger.info("Context condensation triggered")
messages = await context_manager.condense_context(messages, model_name)
......@@ -3894,6 +3894,15 @@ class AutoselectHandler:
def _get_skill_file_content(self) -> str:
"""Load the autoselect.md skill file content"""
if self._skill_file_content is None:
# Check for user-specific prompt first if user_id is present
if self.user_id is not None:
from .database import get_database
db = get_database()
user_prompt = db.get_user_prompt(self.user_id, 'autoselect')
if user_prompt is not None:
self._skill_file_content = user_prompt
return self._skill_file_content
# Try installed locations first
installed_dirs = [
Path('/usr/share/aisbf'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment