-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Multiple Selectable Approaches for Text (Chain of Thought with Prompt…
… Chaining) (#350) Co-authored-by: = Enea_Gore <[email protected]> Co-authored-by: Maximilian Sölch <[email protected]>
- Loading branch information
1 parent
2c2e4a1
commit 7cd213a
Showing
16 changed files
with
772 additions
and
440 deletions.
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
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
16 changes: 16 additions & 0 deletions
16
modules/text/module_text_llm/module_text_llm/approach_config.py
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,16 @@ | ||
from abc import ABC | ||
from pydantic import BaseModel, Field | ||
from llm_core.models import ModelConfigType, DefaultModelConfig | ||
from enum import Enum | ||
|
||
class ApproachType(str, Enum): | ||
basic = "BasicApproach" | ||
chain_of_thought = "ChainOfThought" | ||
|
||
class ApproachConfig(BaseModel, ABC): | ||
max_input_tokens: int = Field(default=3000, description="Maximum number of tokens in the input prompt.") | ||
model: ModelConfigType = Field(default=DefaultModelConfig()) | ||
type: str = Field(..., description="The type of approach config") | ||
|
||
class Config: | ||
use_enum_values = True |
16 changes: 16 additions & 0 deletions
16
modules/text/module_text_llm/module_text_llm/approach_controller.py
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,16 @@ | ||
|
||
from typing import List | ||
from athena.text import Exercise, Submission, Feedback | ||
from module_text_llm.basic_approach import BasicApproachConfig | ||
from module_text_llm.chain_of_thought_approach import ChainOfThoughtConfig | ||
from module_text_llm.approach_config import ApproachConfig | ||
|
||
from module_text_llm.basic_approach.generate_suggestions import generate_suggestions as generate_suggestions_basic | ||
from module_text_llm.chain_of_thought_approach.generate_suggestions import generate_suggestions as generate_cot_suggestions | ||
|
||
async def generate_suggestions(exercise: Exercise, submission: Submission, config: ApproachConfig, debug: bool) -> List[Feedback]: | ||
if(isinstance(config, BasicApproachConfig)): | ||
return await generate_suggestions_basic(exercise, submission, config, debug) | ||
elif(isinstance(config, ChainOfThoughtConfig)): | ||
return await generate_cot_suggestions(exercise, submission, config, debug) | ||
|
11 changes: 11 additions & 0 deletions
11
modules/text/module_text_llm/module_text_llm/basic_approach/__init__.py
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,11 @@ | ||
from module_text_llm.approach_config import ApproachConfig | ||
from pydantic import Field | ||
from typing import Literal | ||
|
||
|
||
from module_text_llm.basic_approach.prompt_generate_suggestions import GenerateSuggestionsPrompt | ||
|
||
class BasicApproachConfig(ApproachConfig): | ||
type: Literal['basic'] = 'basic' | ||
generate_suggestions_prompt: GenerateSuggestionsPrompt = Field(default=GenerateSuggestionsPrompt()) | ||
|
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
65 changes: 65 additions & 0 deletions
65
modules/text/module_text_llm/module_text_llm/basic_approach/prompt_generate_suggestions.py
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,65 @@ | ||
from pydantic import Field, BaseModel | ||
from typing import List, Optional | ||
from pydantic import BaseModel, Field | ||
|
||
system_message = """\ | ||
You are an AI tutor for text assessment at a prestigious university. | ||
# Task | ||
Create graded feedback suggestions for a student\'s text submission that a human tutor would accept. \ | ||
Meaning, the feedback you provide should be applicable to the submission with little to no modification. | ||
# Style | ||
1. Constructive, 2. Specific, 3. Balanced, 4. Clear and Concise, 5. Actionable, 6. Educational, 7. Contextual | ||
# Problem statement | ||
{problem_statement} | ||
# Example solution | ||
{example_solution} | ||
# Grading instructions | ||
{grading_instructions} | ||
Max points: {max_points}, bonus points: {bonus_points}\ | ||
Respond in json. | ||
""" | ||
|
||
human_message = """\ | ||
Student\'s submission to grade (with sentence numbers <number>: <sentence>): | ||
Respond in json. | ||
\"\"\" | ||
{submission} | ||
\"\"\"\ | ||
""" | ||
|
||
# Input Prompt | ||
class GenerateSuggestionsPrompt(BaseModel): | ||
"""\ | ||
Features available: **{problem_statement}**, **{example_solution}**, **{grading_instructions}**, **{max_points}**, **{bonus_points}**, **{submission}** | ||
_Note: **{problem_statement}**, **{example_solution}**, or **{grading_instructions}** might be omitted if the input is too long._\ | ||
""" | ||
system_message: str = Field(default=system_message, | ||
description="Message for priming AI behavior and instructing it what to do.") | ||
human_message: str = Field(default=human_message, | ||
description="Message from a human. The input on which the AI is supposed to act.") | ||
# Output Object | ||
class FeedbackModel(BaseModel): | ||
title: str = Field(description="Very short title, i.e. feedback category or similar", example="Logic Error") | ||
description: str = Field(description="Feedback description") | ||
line_start: Optional[int] = Field(description="Referenced line number start, or empty if unreferenced") | ||
line_end: Optional[int] = Field(description="Referenced line number end, or empty if unreferenced") | ||
credits: float = Field(0.0, description="Number of points received/deducted") | ||
grading_instruction_id: Optional[int] = Field( | ||
description="ID of the grading instruction that was used to generate this feedback, or empty if no grading instruction was used" | ||
) | ||
|
||
|
||
class AssessmentModel(BaseModel): | ||
"""Collection of feedbacks making up an assessment""" | ||
|
||
feedbacks: List[FeedbackModel] = Field(description="Assessment feedbacks") | ||
|
15 changes: 15 additions & 0 deletions
15
modules/text/module_text_llm/module_text_llm/chain_of_thought_approach/__init__.py
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,15 @@ | ||
from pydantic import BaseModel, Field | ||
from typing import Literal | ||
from llm_core.models import ModelConfigType, MiniModelConfig | ||
|
||
from module_text_llm.approach_config import ApproachConfig | ||
from module_text_llm.chain_of_thought_approach.prompt_generate_feedback import CoTGenerateSuggestionsPrompt | ||
from module_text_llm.chain_of_thought_approach.prompt_thinking import ThinkingPrompt | ||
|
||
class ChainOfThoughtConfig(ApproachConfig): | ||
# Defaults to the cheaper mini 4o model | ||
type: Literal['chain_of_thought'] = 'chain_of_thought' | ||
model: ModelConfigType = Field(default=MiniModelConfig) # type: ignore | ||
thikning_prompt: ThinkingPrompt = Field(default=ThinkingPrompt()) | ||
generate_suggestions_prompt: CoTGenerateSuggestionsPrompt = Field(default=CoTGenerateSuggestionsPrompt()) | ||
|
Oops, something went wrong.