youngtsai commited on
Commit
67eb293
·
1 Parent(s): 8749812

def validate_article(generated_article, lesson_words, base_chars, original_word_count):

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -33,7 +33,7 @@ def extract_article_from_content(article_text):
33
 
34
  def validate_article(generated_article, lesson_words, base_chars, original_word_count):
35
  clean_article = "".join(char for char in generated_article if char not in "、,。!?;:「」『』()《》【】'\n'")
36
- not_every_new_word_is_used = not all(word in clean_article for word in lesson_words.split())
37
  word_out_of_range = not set(clean_article).issubset(set(lesson_words + base_chars))
38
  new_word_count = len(clean_article)
39
  word_count_error = not (0.9 * original_word_count <= new_word_count <= 1.1 * original_word_count)
@@ -104,6 +104,7 @@ def generate_new_article(lesson_words, original_article, original_word_count, ba
104
  not_every_new_word_is_used = validate_article_result['not_every_new_word_is_used']
105
  word_out_of_range = validate_article_result['word_out_of_range']
106
  word_count_error = validate_article_result['word_count_error']
 
107
 
108
  print("====validate_article====")
109
  print(f"not_every_new_word_is_used: {not_every_new_word_is_used}")
@@ -124,8 +125,15 @@ def generate_new_article(lesson_words, original_article, original_word_count, ba
124
  if word_count_error:
125
  error_messages.append(f"The word count of the new article deviates more than 10% from the original ({original_word_count}).")
126
 
127
- prompt += "\n".join(error_messages) + "\n" # Append the error messages to the prompt for the next attempt
128
-
 
 
 
 
 
 
 
129
 
130
  return generated_article, validate_article_result
131
 
 
33
 
34
  def validate_article(generated_article, lesson_words, base_chars, original_word_count):
35
  clean_article = "".join(char for char in generated_article if char not in "、,。!?;:「」『』()《》【】'\n'")
36
+ not_every_new_word_is_used = not all(word in clean_article for word in [char for char in lesson_words])
37
  word_out_of_range = not set(clean_article).issubset(set(lesson_words + base_chars))
38
  new_word_count = len(clean_article)
39
  word_count_error = not (0.9 * original_word_count <= new_word_count <= 1.1 * original_word_count)
 
104
  not_every_new_word_is_used = validate_article_result['not_every_new_word_is_used']
105
  word_out_of_range = validate_article_result['word_out_of_range']
106
  word_count_error = validate_article_result['word_count_error']
107
+ count_of_words_in_new_article = validate_article_result['count_of_words_in_new_article']
108
 
109
  print("====validate_article====")
110
  print(f"not_every_new_word_is_used: {not_every_new_word_is_used}")
 
125
  if word_count_error:
126
  error_messages.append(f"The word count of the new article deviates more than 10% from the original ({original_word_count}).")
127
 
128
+ error_messages_str = "\n".join(error_messages) + "\n" # Append the error messages to the prompt for the next attempt
129
+ prompt += f"""
130
+ The new article is {generated_article}.
131
+ word_count is {count_of_words_in_new_article}.
132
+ But the generated article is invalid. The following issues were found:
133
+ {error_messages_str}
134
+ please follow the summary of the key points and fix the errors to generate a new article.
135
+ """
136
+ print(f"Prompt for next attempt: {prompt}")
137
 
138
  return generated_article, validate_article_result
139