Skip to content

Implement LLM-based coding task generation with complete function templates integrated with quiz workflow#20

Draft
Copilot wants to merge 6 commits into
mainfrom
copilot/fix-c35363ec-7792-4861-96f9-22a5bcefd94f
Draft

Implement LLM-based coding task generation with complete function templates integrated with quiz workflow#20
Copilot wants to merge 6 commits into
mainfrom
copilot/fix-c35363ec-7792-4861-96f9-22a5bcefd94f

Conversation

Copilot AI commented Sep 18, 2025

Copy link
Copy Markdown

This PR implements a comprehensive LLM-based coding task generation system that replaces the static placeholder tasks in QuizBank.codingTasks with dynamically generated practical programming exercises based on semantic hunks and guide content. The implementation integrates seamlessly with the existing quiz generation workflow through the "Check Your Knowledge" button and ensures generated tasks always include complete, compilable function templates.

Problem

The existing system used hardcoded TODO placeholders for coding tasks:

val codingTasks: List<CodingTask> = listOf(
    CodingTask(
        id = 1,
        title = "Implement BFS shortest path length",
        languageId = "kotlin",
        initialCode = """
            // TODO(1): Implement BFS to compute shortest path length in a grid
            // TODO(2): Create a queue and visited set
            // TODO(3): Push start, then BFS layer by layer; return steps when reaching goal
            return -1 // TODO: replace with result
        """.trimIndent()
    )
)

These static tasks were disconnected from the actual codebase changes and didn't provide relevant, context-aware programming exercises.

Solution

Following the same architectural patterns as the existing QuizGenerator and QuizService, this implementation creates:

Core Components

  1. CodingTaskGenerator (llm_pipeline/CodingTaskGenerator.kt)

    • Analyzes semantic hunks and guide content using LLM
    • Generates practical coding exercises related to actual code changes
    • Creates structured prompts focusing on algorithmic thinking and design patterns
    • Enhanced prompt engineering to ensure complete function templates with clear input/output specifications
  2. CodingTaskService (com/gitdiff/CodingTaskService.kt)

    • Project-level service for managing coding tasks
    • Delegates to GuideService for persistence (single source of truth)
    • Provides convenience methods for UI integration
  3. Enhanced Data Models (com/gitdiff/Models.kt)

    • Added CodingTask and CodingTaskList data structures
    • Integrated codingTasks field into existing Guide object
    • Maintains compatibility with existing static task structure

Integrated Workflow

The coding task generation is now fully integrated with the existing quiz workflow:

User clicks "Check Your Knowledge" → Both quiz and coding tasks generate in background thread
                                  ↓
UI remains responsive during generation → QuizPage refreshes with both sections when complete
                                       ↓
Generated tasks include complete function templates with clear input/output specifications

UI Integration

  • ChatPage: Modified to generate both quiz and coding tasks when "Check Your Knowledge" is clicked
  • QuizPage: Enhanced refresh logic to handle both quiz questions and coding tasks
  • TaskCard: Updated to work with new CodingTask type from gitdiff package
  • Background Threading: Both quiz and coding task generation run in separate threads to prevent UI blocking

Key Features

  • Unified Generation: Single "Check Your Knowledge" button generates both quiz and coding tasks
  • Non-blocking UI: Background threading ensures responsive user interface during generation
  • Context-Aware: Tasks are generated from actual semantic hunks and code changes
  • Complete Function Templates: Enhanced prompt engineering ensures tasks always include compilable function signatures with clear input/output documentation
  • Robust Parsing: Fallback code generation when LLM responses are incomplete
  • Graceful Fallback: Maintains backward compatibility with static tasks
  • Consistent Architecture: Uses proven patterns from existing LLM pipeline
  • Integrated User Experience: Seamless workflow matching existing quiz generation

Enhanced Template Generation

The system now generates complete function templates that include:

  • Complete function signatures with meaningful parameter names
  • Clear input/output documentation in comments
  • Specific TODO instructions for implementation steps
  • Compilable code that users can immediately work with
  • Fallback templates for cases where LLM doesn't provide proper code

Example Generated Task

Instead of generic TODOs, the system now generates context-specific exercises with complete templates:

// TODO: Implement BFS to find shortest path in a grid
// Input: grid (2D char array), start (Point), goal (Point)
// Output: shortest distance as Int, or -1 if unreachable

data class Point(val row: Int, val col: Int)

fun findShortestPath(grid: Array<CharArray>, start: Point, goal: Point): Int {
    // TODO: Create a queue for BFS and visited set
    // TODO: Add start point to queue with distance 0
    // TODO: While queue is not empty, process neighbors
    // TODO: Return distance when goal is found
    return -1 // TODO: replace with actual implementation
}

Coding Tasks Demo

The generated tasks directly relate to the code changes analyzed in the semantic hunks, making them relevant and educational for understanding the actual codebase evolution. The enhanced prompt engineering ensures users always see meaningful, compilable function templates with clear specifications.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits September 18, 2025 01:08
Co-authored-by: Anton15K <54205422+Anton15K@users.noreply.github.com>
Co-authored-by: Anton15K <54205422+Anton15K@users.noreply.github.com>
Copilot AI changed the title [WIP] I need to create the second variant of practical tasks like quizes via generation. Now, The QuizBank.codingTasks placeholders in data/Models.kt logically replaced LLM query for their creation. Change them as it's done for QuizBank.questions, which were... Implement LLM-based coding task generation to replace static placeholders Sep 18, 2025
Copilot AI requested a review from Anton15K September 18, 2025 01:12
@Anton15K

Copy link
Copy Markdown
Collaborator

@copilot well done! Although, I want to make some change. I want the tasks to be created when user clicks on testmyKnowledge Button, as it was done for the quiz. You might also put this process (both quiz and taks generation) to a sepparate thread so that UI is not blocked

…nd background threading

Co-authored-by: Anton15K <54205422+Anton15K@users.noreply.github.com>

Copilot AI commented Sep 18, 2025

Copy link
Copy Markdown
Author

@copilot well done! Although, I want to make some change. I want the tasks to be created when user clicks on testmyKnowledge Button, as it was done for the quiz. You might also put this process (both ...

I've implemented your requested changes! The coding tasks are now generated when the user clicks the "Check Your Knowledge" button, alongside the quiz generation. Both quiz and coding task generation now run in a background thread to prevent UI blocking.

Key changes made in commit d0c3a5c:

  1. Integrated Generation: Modified ChatPage.generateQuiz() to generate both quiz and coding tasks when "Check Your Knowledge" is clicked
  2. Background Threading: Both generations run in a separate thread using Thread { ... }.start()
  3. UI Refresh: Enhanced QuizPage.refreshQuizContent() to refresh both quiz questions and coding tasks
  4. Cleaner UX: Removed the standalone "Generate Coding Tasks" action from Tools menu

The workflow is now:

  • User clicks "Check Your Knowledge" → Both quiz and coding tasks generate in background → UI refreshes with both sections when complete

The UI remains responsive during generation, and users get both quiz questions and practical coding exercises from a single action.

Copilot AI changed the title Implement LLM-based coding task generation to replace static placeholders Implement LLM-based coding task generation integrated with quiz workflow Sep 18, 2025
@Anton15K

Copy link
Copy Markdown
Collaborator

@copilot Perfect, it generates the tests. But, the problem is, that in the window the code space is empty. We need some function to be there, that we understand what is input and output should be for the test case. Maybe you should add to prompt that it need to generate this template function, so it can be filled by the user in that window. Also make sure you use DARK THEME so that your IDE looks good.

… with clear input/output

Co-authored-by: Anton15K <54205422+Anton15K@users.noreply.github.com>

Copilot AI commented Sep 18, 2025

Copy link
Copy Markdown
Author

@copilot Perfect, it generates the tests. But, the problem is, that in the window the code space is empty. We need some function to be there, that we understand what is input and output should be for ...

Fixed the empty code space issue! The problem was that the LLM prompt wasn't specific enough about generating complete function templates. I've enhanced the prompt and parsing to ensure coding tasks always have meaningful code with clear input/output specifications.

Changes made in commit a84fbf6:

  1. Enhanced Prompt Engineering: Now requires complete function templates with clear input/output documentation
  2. Concrete Examples: Added detailed example showing exactly what a good task should look like
  3. Fallback Code Generation: If LLM doesn't provide proper code, automatically generates basic function templates
  4. Robust Parsing: Enhanced parsing to handle edge cases and ensure code is never empty

The generated tasks now include:

  • Complete function signatures with meaningful parameter names
  • Clear input/output documentation in comments
  • Specific TODO instructions for implementation steps
  • Compilable code that users can immediately work with

Here's how the improved coding tasks look in dark theme:

Coding Tasks Demo

Each task now provides a complete function template that clearly shows what inputs are expected and what output should be returned, making it much easier for users to understand what they need to implement.

Copilot AI changed the title Implement LLM-based coding task generation integrated with quiz workflow Implement LLM-based coding task generation with complete function templates integrated with quiz workflow Sep 18, 2025
…loadCodingTasks` and `refreshQuizContent`. Update default model configuration in `GlobalConfig`. Fix `setCancelButtonText` value in `CodingTaskAction`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants