Add multi-user support: update create_session to accept user_id parameter and use ahserver's get_user() in create_session.dspy

This commit is contained in:
yumoqing 2026-04-23 11:29:57 +08:00
parent 9494a235f2
commit fab7170954
4 changed files with 7 additions and 5 deletions

Binary file not shown.

View File

@ -134,7 +134,7 @@ def test_service_connection(url: str, apikey: str = "") -> Tuple[bool, str]:
return False, f"Error: {str(e)}" return False, f"Error: {str(e)}"
# Session management # Session management
def create_session(service_id: str, user_message: str = "") -> str: def create_session(service_id: str, user_id: str, user_message: str = "") -> str:
"""Create a new session with a Hermes service.""" """Create a new session with a Hermes service."""
try: try:
# Get service configuration # Get service configuration
@ -158,7 +158,7 @@ def create_session(service_id: str, user_message: str = "") -> str:
response = requests.post( response = requests.post(
f"{service_url.rstrip('/')}/api/v1/sessions", f"{service_url.rstrip('/')}/api/v1/sessions",
json={ json={
"user_id": "web-cli-user", # This could be made configurable "user_id": user_id,
"initial_message": user_message if user_message else None "initial_message": user_message if user_message else None
}, },
headers=headers, headers=headers,

Binary file not shown.

View File

@ -17,10 +17,12 @@ try:
# Redirect back to form with error # Redirect back to form with error
return {"redirect": "/hermes-web-cli/new_session.ui?error=Service+ID+is+required"} return {"redirect": "/hermes-web-cli/new_session.ui?error=Service+ID+is+required"}
# Get current user ID using ahserver's built-in get_user() function
user_id = await get_user()
# Use the function provided by the hermes-web-cli module # Use the function provided by the hermes-web-cli module
# This will call the remote hermes-service API # This will call the remote hermes-service API with user_id support
# Pass empty string as initial message since we don't collect it in the form session_result = create_session(service_id, user_id, "")
session_result = create_session(service_id, "")
if session_result: if session_result:
# Redirect to the new session's user interaction page # Redirect to the new session's user interaction page