-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add basic lms chat #398
Draft
asadali145
wants to merge
5
commits into
main
Choose a base branch
from
asad/basic-lms-chat-v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+282
−4
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/* General Reset */ | ||
* { | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
font-family: Arial, sans-serif; | ||
} | ||
|
||
/* Chat Button */ | ||
.chat-button { | ||
position: relative; | ||
bottom: 70px; | ||
left: 300px; | ||
margin-left: auto; | ||
width: fit-content; | ||
background-color: #A31F34; | ||
color: white; | ||
padding: 10px 15px; | ||
border-radius: 50px; | ||
cursor: pointer; | ||
font-size: 16px; | ||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); | ||
z-index: 1000; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
/* Chat Window */ | ||
.chat-window { | ||
position: relative; | ||
bottom: 450px; | ||
left: 300px; | ||
margin-left: auto; | ||
width: 300px; | ||
height: 400px; | ||
background-color: white; | ||
border-radius: 10px; | ||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); | ||
z-index: 1001; | ||
display: none; /* Initially hidden */ | ||
flex-direction: column; | ||
overflow: hidden; | ||
} | ||
|
||
/* Chat Header */ | ||
.chat-header { | ||
background-color: #A31F34; | ||
color: white; | ||
padding: 10px; | ||
font-size: 18px; | ||
font-weight: bold; | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
} | ||
|
||
/* Close Chat Button */ | ||
.close-chat { | ||
cursor: pointer; | ||
font-size: 20px; | ||
font-weight: bold; | ||
} | ||
|
||
/* Chat Body */ | ||
.chat-body { | ||
flex: 1; /* Ensures it takes up available space */ | ||
padding: 10px; | ||
overflow-y: auto; /* Enables vertical scrolling */ | ||
background-color: #f9f9f9; | ||
max-height: 300px; /* Limit the height of the chat body */ | ||
scrollbar-width: thin; /* Custom scrollbar for modern browsers */ | ||
scrollbar-color: #A31F34 #f9f9f9; | ||
} | ||
|
||
/* Optional: Styling for scrollbars in webkit browsers (Chrome, Safari) */ | ||
.chat-body::-webkit-scrollbar { | ||
width: 8px; /* Width of the scrollbar */ | ||
} | ||
|
||
.chat-body::-webkit-scrollbar-thumb { | ||
background-color: #A31F34; /* Color of the scrollbar thumb */ | ||
border-radius: 4px; /* Roundness of the scrollbar thumb */ | ||
} | ||
|
||
.chat-body::-webkit-scrollbar-track { | ||
background-color: #f9f9f9; /* Color of the scrollbar track */ | ||
} | ||
|
||
.bot-message { | ||
background-color: #e0e0e0; | ||
color: #333; | ||
padding: 10px; | ||
border-radius: 10px; | ||
margin: 5px 0; | ||
max-width: 80%; | ||
} | ||
|
||
.user-message { | ||
background-color: #A31F34; | ||
color: white; | ||
padding: 10px; | ||
border-radius: 10px; | ||
margin: 5px 0; | ||
max-width: 80%; | ||
align-self: flex-end; | ||
} | ||
|
||
/* Chat Footer */ | ||
.chat-footer { | ||
display: flex; | ||
border-top: 1px solid #ddd; | ||
position: absolute; | ||
bottom: 0; | ||
width: inherit; | ||
} | ||
|
||
.chat-input { | ||
flex: 1; | ||
border: none; | ||
padding: 10px; | ||
font-size: 14px; | ||
} | ||
|
||
.chat-input:focus { | ||
outline: none; | ||
} | ||
|
||
.send-button { | ||
background-color: #A31F34; | ||
color: white; | ||
border: none; | ||
padding: 10px 15px; | ||
cursor: pointer; | ||
font-size: 14px; | ||
} | ||
|
||
.send-button:hover { | ||
background-color: #A31F34; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,27 @@ | ||
<div> | ||
<button type="button" onclick="alert('Hello World!')">Hello World!</button> | ||
<!-- Chat Button --> | ||
<div class="chat-button" id="chat-button-{{ block_key }}" data-block-key="{{ block_key }}"> | ||
Help me with this problem | ||
</div> | ||
|
||
<!-- Chat Window --> | ||
<div class="chat-window" id="chat-window-{{ block_key }}" data-block-key="{{ block_key }}"> | ||
<div class="chat-header"> | ||
<span>MIT Teaching Assistant</span> | ||
<span class="close-chat" id="close-chat-{{ block_key }}" data-block-key="{{ block_key }}">×</span> | ||
</div> | ||
<div class="chat-body"> | ||
<p class="bot-message">Hi! How can I assist you today?</p> | ||
</div> | ||
<div class="chat-footer"> | ||
<input type="text" class="chat-input" placeholder="Type your message here..."> | ||
<button class="send-button">Send</button> | ||
</div> | ||
</div> | ||
</div> | ||
<script | ||
defer | ||
id="ze-snippet" | ||
type='application/javascript' | ||
src="https://static.zdassets.com/ekr/snippet.js?key=8ef9ef96-3317-40a9-8ef6-de0737503caa" | ||
></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
resources( | ||
name="ol_chat_js", | ||
sources=["src_js/*.js","lib/*.js"], | ||
sources=["*.js"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
function AiChatAsideView(runtime, element, block_element, init_args) { | ||
$('.chat-button').on('click', function () { | ||
const blockKey = $(this).data("block-key") | ||
const chatWindowSelector = '#chat-window-' + blockKey | ||
const chatButtonSelector = '#chat-button-' + blockKey | ||
$(chatWindowSelector).fadeIn(); | ||
$(chatButtonSelector).hide(); | ||
}); | ||
|
||
// Close chat window | ||
$('.close-chat').on('click', function () { | ||
const blockKey = $(this).data("block-key") | ||
const chatWindowSelector = '#chat-window-' + blockKey | ||
const chatButtonSelector = '#chat-button-' + blockKey | ||
$(chatWindowSelector).fadeOut(); | ||
$(chatButtonSelector).fadeIn(); | ||
}); | ||
|
||
// Send message | ||
function sendMessage() { | ||
const message = $('.chat-input').val().trim(); | ||
if (message !== '') { | ||
// Display user message | ||
const userMessage = $('<p>') | ||
.addClass('user-message') | ||
.text(message); | ||
$('.chat-body').append(userMessage); | ||
|
||
// Clear input field | ||
$('.chat-input').val(''); | ||
|
||
// Simulate bot response | ||
// setTimeout(() => { | ||
// const botMessage = $('<p>') | ||
// .addClass('bot-message') | ||
// .text('Thanks for reaching out! We will get back to you shortly.'); | ||
// $('.chat-body').append(botMessage); | ||
// | ||
// // Scroll to the bottom of the chat body | ||
// $('.chat-body').scrollTop($('.chat-body')[0].scrollHeight); | ||
// }, 1000); | ||
|
||
// Scroll to the bottom after user message | ||
$('.chat-body').scrollTop($('.chat-body')[0].scrollHeight); | ||
|
||
$.ajax({ | ||
type: "POST", | ||
url: runtime.handlerUrl(element, 'mock_handler'), | ||
data: JSON.stringify({"message": message}), | ||
success: function(resp) { | ||
console.log(resp.message) | ||
setTimeout(() => { | ||
const botMessage = $('<p>') | ||
.addClass('bot-message') | ||
.text(resp.message); | ||
$('.chat-body').append(botMessage); | ||
|
||
$('.chat-body').scrollTop($('.chat-body')[0].scrollHeight); | ||
}, 1000 | ||
); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
// Send message on button click | ||
$('.send-button').on('click', sendMessage); | ||
|
||
// Send message on pressing Enter | ||
$('.chat-input').on('keypress', function (event) { | ||
if (event.which === 13) { | ||
sendMessage(); | ||
} | ||
}); | ||
console.log(init_args) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Does tthis call the problem-specific
OLChatAside
mock_handler method? So the actual URL might be likeproblem/uuid-1234-xyz/
?And is this way, the chat API knows the context—which problem is it helping with?
Am I understanding that roughly correctly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, You are spot on.