Filter topics and words on exercises.

This commit is contained in:
Cristiano Ferreira
2024-02-08 23:42:02 +00:00
parent 9149e4b197
commit d532f7deb4
4 changed files with 59 additions and 21 deletions

View File

@@ -5,7 +5,7 @@ import re
from dotenv import load_dotenv
from helper.constants import GPT_3_5_TURBO_INSTRUCT
from helper.constants import GPT_3_5_TURBO_INSTRUCT, BLACKLISTED_WORDS
from helper.token_counter import count_tokens
load_dotenv()
@@ -15,7 +15,7 @@ MAX_TOKENS = 4097
TOP_P = 0.9
FREQUENCY_PENALTY = 0.5
TRY_LIMIT = 1
TRY_LIMIT = 2
try_count = 0
@@ -167,6 +167,12 @@ def make_openai_instruct_call(model, message: str, token_count, fields_to_check,
temperature=0.7
)["choices"][0]["text"]
if has_blacklisted_words(response) and try_count < TRY_LIMIT:
try_count = try_count + 1
return make_openai_instruct_call(model, message, token_count, fields_to_check, temperature)
elif has_blacklisted_words(response) and try_count >= TRY_LIMIT:
return ""
if fields_to_check is None:
return response.replace("\n\n", " ").strip()
@@ -264,3 +270,8 @@ def get_speaking_corrections(text):
token_count = count_tokens(message)["n_tokens"]
response = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, message, token_count, ["fixed_text"], 0.2)
return response["fixed_text"]
def has_blacklisted_words(text: str):
text_lower = text.lower()
return any(word in text_lower for word in BLACKLISTED_WORDS)