Skip to content

Commit

Permalink
k1
Browse files Browse the repository at this point in the history
  • Loading branch information
= Enea_Gore committed Jan 23, 2025
1 parent be55918 commit 046c60b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 29 deletions.
24 changes: 14 additions & 10 deletions modules/text/module_text_llm/module_text_llm/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from module_text_llm.approach_controller import generate_suggestions
from module_text_llm.helpers.detect_suspicios_submission import hybrid_suspicion_score, llm_check
from module_text_llm.helpers.feedback_icl.store_feedback_icl import store_feedback_icl

from module_text_llm.few_shot_chain_of_thought_approach import FewShotChainOfThoughtConfig
#Test Demo
@submissions_consumer
def receive_submissions(exercise: Exercise, submissions: List[Submission]):
Expand Down Expand Up @@ -42,15 +42,19 @@ def process_incoming_feedback(exercise: Exercise, submission: Submission, feedba
async def suggest_feedback(exercise: Exercise, submission: Submission, is_graded: bool, module_config: Configuration) -> List[Feedback]:
logger.info("suggest_feedback: %s suggestions for submission %d of exercise %d were requested, with approach: %s",
"Graded" if is_graded else "Non-graded", submission.id, exercise.id, module_config.approach.__class__.__name__)
logger.info("suggest_feedback: %s suggestions for submission %d of exercise %d were requested",
"Graded" if is_graded else "Non-graded", submission.id, exercise.id)
is_sus, score = hybrid_suspicion_score(submission.text, threshold=0.8)
if is_sus:
logger.info("Suspicious submission detected with score %f", score)
is_suspicious,suspicios_text = await llm_check(submission.text)
if is_suspicious:
logger.info("Suspicious submission detected by LLM with text %s", suspicios_text)
return [Feedback(title="Instructors need to review this submission", description="This Submission potentially violates the content policy!", credits=-1.0, exercise_id=exercise.id, submission_id=submission.id, is_graded=is_graded)]

if not is_graded:
is_sus, score = hybrid_suspicion_score(submission.text, threshold=0.8)
if is_sus:
logger.info("Suspicious submission detected with score %f", score)
is_suspicious,suspicios_text = await llm_check(submission.text)
if is_suspicious:
logger.info("Suspicious submission detected by LLM with text %s", suspicios_text)
return [Feedback(title="Instructors need to review this submission", description="This Submission potentially violates the content policy!", credits=-1.0, exercise_id=exercise.id, submission_id=submission.id, is_graded=is_graded)]
module_config.approach = FewShotChainOfThoughtConfig()
return await generate_suggestions(exercise, submission, module_config.approach, module_config.debug, is_graded)


return await generate_suggestions(exercise, submission, module_config.approach, module_config.debug, is_graded)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,17 @@ def store_feedback_icl(submission: Submission, exercise: Exercise, feedbacks: Li

def save_embedding_with_metadata(embedding,submission, exercise_id, metadata):
embeddings_file = f"embeddings_{exercise_id}.npy"
full_return = []
print("inside reference")
print(type(metadata))
print(metadata.keys())
# print()
# print(metadata["feedbacks"])
# for data in metadata["feedbacks"]:
# if "index_start" in metadata.keys() and "index_end" in metadata.keys():
# print(metadata["index_start"])
# print(metadata["index_end"])


if metadata["index_start"] is not None and metadata["index_end"] is not None:
reference = submission.text[metadata["index_start"]:metadata["index_end"]]
metadata["text_reference"] = reference
# print(reference)
# full_return.append(metadata)
print(full_return)

try:
print("inside try")
if os.path.exists(embeddings_file):
# Load existing data
existing_data = np.load(embeddings_file, allow_pickle=True).item()
# Append the new embedding and metadata
existing_data['embeddings'] = np.vstack((existing_data['embeddings'], embedding))
existing_data['metadata'].append(metadata)
else:
# Create a new dictionary with embeddings and metadata
existing_data = {
'embeddings': np.array([embedding], dtype=np.float32),
'metadata': [metadata]
Expand Down Expand Up @@ -78,7 +62,7 @@ def save_embeddings_to_file(embeddings, filename="keyword_embeddings.npy"):
print(f"Embeddings saved to {filename}")


def query_embedding(query_embedding, exercise_id, k=5):
def query_embedding(query_embedding, exercise_id, k=1):
"""
Query the top-k most similar embeddings to the provided query_embedding
for a given exercise ID. Return the corresponding metadata for these embeddings.
Expand Down

0 comments on commit 046c60b

Please sign in to comment.