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:
parent
9494a235f2
commit
fab7170954
BIN
hermes_web_cli/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
hermes_web_cli/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
@ -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.
@ -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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user