diff --git a/bases/rsptx/web2py_server/applications/runestone/controllers/peer.py b/bases/rsptx/web2py_server/applications/runestone/controllers/peer.py index 9f2de3a3..2212a873 100644 --- a/bases/rsptx/web2py_server/applications/runestone/controllers/peer.py +++ b/bases/rsptx/web2py_server/applications/runestone/controllers/peer.py @@ -1049,15 +1049,38 @@ def _llm_enabled(): return bool(_get_course_openai_key()) #fetch the course-wide openai API key used to enable LLM-based async peer discussion (only works for openai currently) +# def _get_course_openai_key(): +# try: +# token_record = asyncio.get_event_loop().run_until_complete( +# fetch_api_token(course_id=auth.user.course_id, provider="openai") +# ) +# if token_record and token_record.token: +# return token_record.token.strip() +# except Exception: +# logger.exception("Failed to fetch course-wide OpenAI token for peer LLM") +# return "" def _get_course_openai_key(): try: + course = db( + db.courses.course_name == auth.user.course_name + ).select().first() + + if not course: + logger.warning("PEER LLM: no course row found") + return "" + logger.warning(f"PEER LLM course_name={auth.user.course_name}") + logger.warning(f"PEER LLM auth.user.course_id={auth.user.course_id}") + logger.warning(f"PEER LLM resolved course.id={course.id if course else None}") token_record = asyncio.get_event_loop().run_until_complete( - fetch_api_token(course_id=auth.user.course_id, provider="openai") + fetch_api_token(course_id=course.id, provider="openai") ) + if token_record and token_record.token: return token_record.token.strip() + except Exception: logger.exception("Failed to fetch course-wide OpenAI token for peer LLM") + return "" @@ -1088,4 +1111,4 @@ def _call_openai(messages): logger.warning(f"PEER LLM CALL | provider=openai-course-token | model={model}") resp.raise_for_status() data = resp.json() - return data["choices"][0]["message"]["content"].strip() + return data["choices"][0]["message"]["content"].strip() \ No newline at end of file diff --git a/bases/rsptx/web2py_server/applications/runestone/static/js/peer.js b/bases/rsptx/web2py_server/applications/runestone/static/js/peer.js index 6bb3872e..4d7a5153 100644 --- a/bases/rsptx/web2py_server/applications/runestone/static/js/peer.js +++ b/bases/rsptx/web2py_server/applications/runestone/static/js/peer.js @@ -1,4 +1,5 @@ // Configuration for the PI steps and helper functions to handle step progression in the instructor's interface +console.log("PEER JS VERSION TEST 12345"); const STEP_CONFIG = { vote1: { next: ['makep', 'facechat', 'makeabgroups'], @@ -485,15 +486,17 @@ async function sendMessage(event) { input.value = ""; input.focus(); - // Disable the send button after sending a message - sendButton.classList.add("disabled"); - llmMessageCount += 1; - console.log("LLM message count:", llmMessageCount); + // Only apply LLM restrictions in async mode + if (window.PI_LLM_MODE === true) { + sendButton.classList.add("disabled"); + llmMessageCount += 1; + console.log("LLM message count:", llmMessageCount); - if (llmMessageCount >= REQUIRED_LLM_MESSAGES) { - const btn = document.getElementById("readyVote2Btn"); - if (btn) { - btn.style.display = "inline-block"; + if (llmMessageCount >= REQUIRED_LLM_MESSAGES) { + const btn = document.getElementById("readyVote2Btn"); + if (btn) { + btn.style.display = "inline-block"; + } } } } @@ -857,6 +860,11 @@ function insertReadyVote2Button() { if (!container) return; + const btn = document.createElement("button"); + btn.id = "readyVote2Btn"; + btn.className = "btn btn-info"; + btn.style.display = "none"; + btn.innerText = "Ready for Vote 2"; btn.addEventListener("click", enableSecondVoteAsync); @@ -868,11 +876,16 @@ $(function () { let tinput = document.getElementById("messageText"); let sendButton = document.getElementById("sendpeermsg"); - if (tinput && sendButton) { + if (window.PI_LLM_MODE !== true && sendButton) { + sendButton.classList.remove("disabled"); + } + + if (tinput && sendButton && window.PI_LLM_MODE === true) { tinput.addEventListener("input", function () { let message = this.value.trim(); - if (message !== "") { + if (window.PI_LLM_MODE !== true && sendButton) { sendButton.classList.remove("disabled"); + sendButton.disabled = false; } else { sendButton.classList.add("disabled"); } diff --git a/docker-compose.yml b/docker-compose.yml index da752afc..41161440 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -183,6 +183,7 @@ services: - DBURL=${DC_DBURL:-$DBURL}?ssl=disable - LOAD_BALANCER_HOST=${LOAD_BALANCER_HOST} - JWT_SECRET=${JWT_SECRET} + - FERNET_SECRET=${FERNET_SECRET} - WEB2PY_PRIVATE_KEY=${WEB2PY_PRIVATE_KEY} - ACADEMY_MODE=True - USE_MASTER_AUTHOR=${USE_MASTER_AUTHOR:-False}