Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""


Expand Down Expand Up @@ -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()
Original file line number Diff line number Diff line change
@@ -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'],
Expand Down Expand Up @@ -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";
}
}
}
}
Expand Down Expand Up @@ -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);

Expand All @@ -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");
}
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Loading