Skip to content

Commit

Permalink
feat: remove extra ai assistant config fields
Browse files Browse the repository at this point in the history
  • Loading branch information
asadali145 committed Feb 28, 2025
1 parent 1343211 commit 940962c
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 75 deletions.
42 changes: 2 additions & 40 deletions src/ol_openedx_chat/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from web_fragments.fragment import Fragment
from webob.response import Response
from xblock.core import XBlock, XBlockAside
from xblock.fields import Boolean, Scope, String
from xblock.fields import Boolean, Scope
from xmodule.x_module import AUTHOR_VIEW, STUDENT_VIEW

from .compat import get_ol_openedx_chat_enabled_flag
Expand Down Expand Up @@ -48,30 +48,6 @@ class OLChatAside(XBlockAside):
scope=Scope.settings,
help=_("Indicates whether or not Open Learning chat is enabled for a block"),
)
chat_prompts = String(
display_name=_("Open Learning Chat Prompt text"),
default="",
scope=Scope.settings,
help=_("Prompt hint text for chat in a block"),
)
additional_solution = String(
display_name=_("Additional solution for problem"),
default="",
scope=Scope.settings,
help=_("Additional solution for the problem in context of chat"),
)
llm_model = String(
display_name=_("Open Learning Chat selected LLM model"),
default="",
scope=Scope.settings,
help=_("Selected LLM model to be used for a block"),
)
ask_tim_drawer_title = String(
display_name=_("Open Learning Drawer Title"),
default="",
scope=Scope.settings,
help=_("Drawer title displayed in the chat drawer"),
)

@XBlockAside.aside_for(STUDENT_VIEW)
def student_view_aside(self, block, context=None):
Expand Down Expand Up @@ -102,8 +78,7 @@ def student_view_aside(self, block, context=None):
fragment.add_css(get_resource_bytes("static/css/ai_chat.css"))
fragment.add_javascript(get_resource_bytes("static/js/ai_chat.js"))
extra_context = {
"starters": self.chat_prompts.split("\n") if self.chat_prompts else [],
"ask_tim_drawer_title": self.ask_tim_drawer_title,
"ask_tim_drawer_title": f"about {block.display_name}",
"block_usage_key": self.scope_ids.usage_id.usage_key.block_id,
"user_id": self.runtime.user_id,
"learn_ai_api_url": settings.LEARN_AI_API_URL,
Expand All @@ -124,15 +99,6 @@ def author_view_aside(self, block, context=None): # noqa: ARG002
"static/html/studio_view.html",
{
"is_enabled": self.ol_chat_enabled,
"chat_prompts": self.chat_prompts,
"ask_tim_drawer_title": self.ask_tim_drawer_title
if self.ask_tim_drawer_title
else f"about {block.display_name}",
"selected_llm_model": self.llm_model,
"additional_solution": self.additional_solution,
"llm_models_list": list(
settings.OL_CHAT_SETTINGS
), # Converting dict keys into a list
"block_id": block.location.block_id, # Passing this along as a unique key for checkboxes # noqa: E501
},
)
Expand Down Expand Up @@ -166,9 +132,5 @@ def update_chat_config(self, request, suffix=""): # noqa: ARG002
"Invalid request body", status=api_status.HTTP_400_BAD_REQUEST
)

self.chat_prompts = posted_data.get("chat_prompts", "")
self.ask_tim_drawer_title = posted_data.get("ask_tim_drawer_title", "")
self.llm_model = posted_data.get("selected_llm_model", "")
self.ol_chat_enabled = posted_data.get("is_enabled", False)
self.additional_solution = posted_data.get("additional_solution", "")
return Response()
26 changes: 1 addition & 25 deletions src/ol_openedx_chat/static/html/studio_view.html
Original file line number Diff line number Diff line change
@@ -1,33 +1,9 @@
<div class="form-container">
<form id="ol-chat-form" data-block-id="{{ block_id }}">
<!-- Text Fields -->
<label for="chat-prompts">Enter Prompts to assist students</label>
<textarea id="chat-prompts" name="chat-prompts" placeholder="Where can I find more information on Large Language Models?" required>{{ chat_prompts }}</textarea>
<label class="sub-label">Learners will see these prompts when using the chatbot feature</label>
<!-- Text Fields -->
<label for="ask-tim-drawer-title">Enter the Chat Drawer title</label>
<input type="text" id="ask-tim-drawer-title" name="ask-tim-drawer-title" value="{{ ask_tim_drawer_title }}" required>
<label class="sub-label">Learners will see this as the title of the Chat Drawer.</label>
<!-- Dropdown -->
<label for="llm-model-dropdown">Choose the Large Language Model (LLM) to use for this question</label>
<select class="llm-dropdown" id="llm-model-dropdown" name="llm-model-dropdown" value="{{ llm_model }}" required>
<option>-- Select an LLM Model --</option>
{% for llm_model in llm_models_list %}
<option {% if selected_llm_model == llm_model %} selected {% endif %}>{{ llm_model }}</option>
{% endfor %}
</select>
<label class="sub-label">Set this so that AI instructions can be more formal, instructive, conversational, technical based on your choice</label>

<!-- Text Fields -->
<label for="additional-solution">Enter the solution</label>
<textarea type="text" id="additional-solution" name="additional-solution" placeholder="Add additional solution">{{ additional_solution }}</textarea>

<label class="sub-label">The more you add here, the more helpful it will be to Learners. We will train our Model to understand the solution, understand potential mistakes learners might make, and assist the Learner without giving direct answers. Links can also be used here to assist Learners find the content from previous course pages or websites. </label>

<!-- Checkbox -->
<div class="checkbox-container">
<input class="enabled-check" type="checkbox" id="is-enabled-{{ block_id }}" name="is-enabled" {% if is_enabled %} checked {% endif %}/>
<label class="enabled-label" for="is-enabled-{{ block_id }}">Enable</label>
<label class="enabled-label" for="is-enabled-{{ block_id }}">Enable AI Chat Assistant</label>
</div>

<!-- Save Button -->
Expand Down
5 changes: 1 addition & 4 deletions src/ol_openedx_chat/static/js/ai_chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
role: "assistant",
},
];
$(`#chat-button-${init_args.block_usage_key}`).on("click", { starters: init_args.starters, askTimTitle: init_args.ask_tim_drawer_title }, function (event) {
const starters = event.data.starters.map(message => ({ content: message }));
$(`#chat-button-${init_args.block_usage_key}`).on("click", { askTimTitle: init_args.ask_tim_drawer_title }, function (event) {
const blockKey = $(this).data("block-key");

window.parent.postMessage(
{
type: "smoot-design::chat-open",
Expand All @@ -20,7 +18,6 @@
askTimTitle: event.data.askTimTitle,
apiUrl: init_args.learn_ai_api_url,
initialMessages: INITIAL_MESSAGES,
conversationStarters: starters,
},
},
init_args.learning_mfe_base_url, // Ensure correct parent origin
Expand Down
7 changes: 1 addition & 6 deletions src/ol_openedx_chat/static/js/studio.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,11 @@
chatForm.addEventListener("submit", function(event) {
event.preventDefault();
var studioRuntime = new window.StudioRuntime.v1();

const chatPromptsField = element.querySelector("#chat-prompts");
const askTIMTitleField = element.querySelector("#ask-tim-drawer-title");
const llmModelDropdown = element.querySelector("#llm-model-dropdown");
const additionalSolutionField = element.querySelector("#additional-solution");
const enabledCheck = element.querySelector("#is-enabled-"+chatForm.dataset.blockId);

// Get the handler URL
const handlerUrl = studioRuntime.handlerUrl(element, 'update_chat_config');
var dataToPost = {"chat_prompts": chatPromptsField.value, "ask_tim_drawer_title": askTIMTitleField.value, "selected_llm_model": llmModelDropdown.value, "is_enabled": enabledCheck.checked, "additional_solution": additionalSolutionField.value};
var dataToPost = {"is_enabled": enabledCheck.checked};

$.ajax({
url: handlerUrl,
Expand Down

0 comments on commit 940962c

Please sign in to comment.