All tested except grading speaking.

This commit is contained in:
Cristiano Ferreira
2024-05-22 21:07:48 +01:00
parent fe753fe72c
commit b7c18517de
4 changed files with 494 additions and 321 deletions

View File

@@ -1,5 +1,6 @@
import json
import os
import re
from openai import OpenAI
from dotenv import load_dotenv
@@ -63,10 +64,15 @@ def make_openai_call(model, messages, token_count, fields_to_check, temperature)
response_format={"type": "json_object"}
)
result = result.choices[0].message.content
if has_blacklisted_words(result) and try_count < TRY_LIMIT:
found_blacklisted_word = get_found_blacklisted_words(result)
if found_blacklisted_word is not None and try_count < TRY_LIMIT:
from app import app
app.logger.warning("Result contains blacklisted words: " + str(found_blacklisted_word))
try_count = try_count + 1
return make_openai_call(model, messages, token_count, fields_to_check, temperature)
elif has_blacklisted_words(result) and try_count >= TRY_LIMIT:
elif found_blacklisted_word is not None and try_count >= TRY_LIMIT:
return ""
if fields_to_check is None:
@@ -83,11 +89,6 @@ def make_openai_call(model, messages, token_count, fields_to_check, temperature)
return json.loads(result)
def make_openai_instruct_call(model, message: str, token_count, fields_to_check, temperature):
global try_count
return ""
# GRADING SUMMARY
def calculate_grading_summary(body):
extracted_sections = extract_existing_sections_from_body(body, section_keys)
@@ -210,6 +211,12 @@ def has_blacklisted_words(text: str):
text_lower = text.lower()
return any(word in text_lower for word in BLACKLISTED_WORDS)
def get_found_blacklisted_words(text: str):
text_lower = text.lower()
for word in BLACKLISTED_WORDS:
if re.search(r'\b' + re.escape(word) + r'\b', text_lower):
return word
return None
def remove_special_characters_from_beginning(string):
cleaned_string = string.lstrip('\n')