openedx_ai_extensions.processors package#

Subpackages#

Module contents#

Processors module - handles data extraction and AI processing

class openedx_ai_extensions.processors.ContentLibraryProcessor(library_key: str, user, config=None)#

Bases: object

Helper class for content library operations

create_block(data)#

Create a library block.

create_collection(title, description='') None#

Create a collection in the library.

create_collection_and_add_items(items, title, description='') str#

Create a collection and add items to it.

delete_block(usage_key)#

Delete a library block.

modify_block_olx(usage_key, data)#

Modify the OLX of a library block.

update_library_collection_items(collection_key, item_keys) None#

Modifies the list of items in a collection.

class openedx_ai_extensions.processors.EducatorAssistantProcessor(user=None, context=None, **kwargs)#

Bases: LitellmProcessor

Handles AI/LLM processing operations

generate_quiz_questions(input_data)#

Generate quiz questions based on the content provided

process(*args, **kwargs)#

Process based on configured function

refine_quiz_question(input_data)#

Refine an existing quiz question instead of generating a new one.

class openedx_ai_extensions.processors.LLMProcessor(config=None, user_session=None, extra_params=None)#

Bases: LitellmProcessor

Handles AI processing using LiteLLM with support for threaded conversations.

This processor accepts an optional extra_params argument in its constructor, which is passed directly to the LitellmProcessor base class. This allows you to configure advanced LiteLLM parameters such as:

  • model: str (e.g., ‘openai/gpt-4’)

  • temperature: float (e.g., 0.7)

  • max_tokens: int (e.g., 150)

  • api_key: str

  • response_format: dict

  • and any other parameters supported by the underlying LiteLLM client

answer_question()#

Answer a specific question based on the provided content

call_with_custom_prompt()#

Call LLM with a completely custom prompt provided in custom_prompt config.

chat_with_context()#

Chat with context given from OpenEdx course content. Either initializes a new thread or continues an existing one.

Parameters:
  • context – Course content context

  • input_data – Optional input data to continue conversation

Returns:

Response from the API

Return type:

dict

explain_like_five()#

Explain content in very simple terms, like explaining to a 5-year-old Short, simple language that anyone can understand

fetch_remote_thread(response_id)#

Fetch the full remote conversation thread by walking the previous_response_id chain via LiteLLM.

Uses provider credentials from self.extra_params resolved during __init__.

Parameters:

response_id – The LiteLLM-wrapped response ID.

Returns:

Chronologically ordered list of response dicts, each containing

id, created_at, model, tokens, input messages, and output messages.

Return type:

list

generate_flashcards()#

Example method showing how to generate flashcards from content.

greet_from_llm()#

Simple test to greet from the LLM and mention which model is being used.

process(*args, **kwargs)#

Process based on configured function

summarize_content()#

Summarize content using LiteLLM

class openedx_ai_extensions.processors.OpenEdXProcessor(processor_config=None, location_id=None, course_id=None, user=None)#

Bases: object

Handles Open edX content extraction

static define_category(category)#

Define a category processor

get_context()#

Get the context of a given Open edX location.

get_course_info(course_id=None, fields=None)#

Retrieve metadata for a specific course.

Parameters:
  • course_id (str, optional) – The unique identifier for the course.

  • fields (list, optional) – List of specific fields to return. Overrides the workflow configuration if provided.

Returns:

A dictionary containing the requested course fields.

Return type:

dict

Configuration:

The returned fields can be filtered via processor_config in the workflow profile JSON.

Example:

"processor_config": {
    "OpenEdXProcessor": {
        "function": "get_course_info",
        "fields": ["title", "short_description"]
    }
}
Available Fields:
  • title: Course display name.

  • subtitle: Course subtitle.

  • short_description: Brief summary of the course.

  • description: Full-length course description.

  • overview: Course overview content (HTML).

  • syllabus: Course syllabus content.

  • duration: Estimated time to complete the course.

  • outline: Hierarchical course structure (JSON). Not included by default.

get_course_outline(course_id=None, user=None)#

Retrieve course outline structure (Sections > Subsections > Units).

get_location_content(location_id=None, retrieval_mode=None)#

Extract unit or sequence content from Open edX modulestore based on configuration

Helper to get the URL of a given location ID

no_context(*args, **kwargs)#

Return default message when no context is provided.

process(*args, **kwargs)#

Process based on configured function

class openedx_ai_extensions.processors.SubmissionProcessor(config=None, user_session=None)#

Bases: object

Handles OpenEdX submission operations for chat history and persistence

get_chat_history(_context, _user_query=None)#

Retrieve initial chat history for the user session. Returns the most recent messages up to max_context_messages.

get_full_message_history(filters=frozenset({'non_string_content', 'system'}))#

Retrieve the full message history for the current submission.

Parameters:

filters – Set of FILTER_* constants passed through to _process_messages. Default behaviour (FILTER_SYSTEM + FILTER_NON_STRING_CONTENT) returns only user/assistant messages with plain string content, which is what the LLM input path requires. Pass frozenset() to retrieve everything stored (system messages, function calls, block-format content) for debug/admin views.

get_full_thread()#

Retrieve the full message history with timestamps for debugging.

Uses the submission’s own student_item to ensure the lookup key matches what was used at creation time, even if the session’s fields have changed.

Returns:

All messages in chronological order with role, content, and timestamp,

or None if no submission exists.

Return type:

list

get_previous_messages(current_messages_count=0)#

Retrieve previous messages for lazy loading older chat history. Takes the count of current messages from frontend and returns the next batch of older messages.

Parameters:

current_messages_count – Number of messages currently displayed in the frontend

Returns:

Contains ‘response’ (JSON string of new messages) and ‘metadata’ (has_more flag)

Return type:

dict

get_submission()#

Retrieve the current submission associated with the user session.

process(context, input_data=None)#

Process based on configured function

update_chat_submission(messages)#

Create a new immutable Submission record for this interaction.

Each call stores the provided messages (prompt + AI response) as a new Submission. History is tracked implicitly via attempt_number, which the Submissions API auto-increments for the same student_item.

update_submission(data)#

Create a new Submission record with the provided data.

attempt_number is intentionally omitted so the Submissions API auto-increments it for the given student_item.