Improve spellchecking for writing
This commit is contained in:
@@ -5,6 +5,9 @@ import re
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
from helper.constants import GPT_3_5_TURBO_INSTRUCT
|
||||
from helper.token_counter import count_tokens
|
||||
|
||||
load_dotenv()
|
||||
openai.api_key = os.getenv("OPENAI_API_KEY")
|
||||
|
||||
@@ -229,3 +232,14 @@ def extract_existing_sections_from_body(my_dict, keys_to_extract):
|
||||
return list(filter(
|
||||
lambda item: 'code' in item and item['code'] in keys_to_extract and 'grade' in item and 'name' in item,
|
||||
my_dict['sections']))
|
||||
|
||||
|
||||
def get_misspelled_pairs(text):
|
||||
message = ('From the given text, extract the misspelled words and put them in the json with the correct word that '
|
||||
'should be on the text instead. Sample JSON: '
|
||||
'{"misspelled_words":[{"misspelled": "piza", "correction": "pizza"}] \n The text: "' + text + '"')
|
||||
token_count = count_tokens(message)["n_tokens"]
|
||||
response = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, message, token_count, ["misspelled_words"], 0.2)
|
||||
# Filter out items with the same value for misspelled and correction
|
||||
filtered_data = [item for item in response["misspelled_words"] if item['misspelled'] != item['correction']]
|
||||
return filtered_data
|
||||
|
||||
Reference in New Issue
Block a user