youngtsai commited on
Commit
e22a348
·
1 Parent(s): 0e1d843

generated_text = response.choices[0].message.content.strip()

Browse files
Files changed (1) hide show
  1. app.py +14 -2
app.py CHANGED
@@ -5,7 +5,7 @@ from openai import OpenAI
5
  import json
6
 
7
  # 設置 OpenAI API 客戶端
8
- IS_LOCAL = False
9
 
10
  if IS_LOCAL:
11
  local_json = json.load(open("local.json"))
@@ -46,6 +46,11 @@ def generate_new_article(lesson_words, original_article, original_word_count, ba
46
 
47
  while attempt < max_attempts:
48
  attempt += 1
 
 
 
 
 
49
  prompt = f"""
50
  Please write a new and original Chinese article tailored for first-grade students. Here's a summary of the key points that you should follow:
51
 
@@ -73,13 +78,20 @@ def generate_new_article(lesson_words, original_article, original_word_count, ba
73
  max_tokens=1000
74
  )
75
 
76
- generated_text = response.choices[0].text.strip()
77
  generated_article = extract_article_from_content(generated_text)
78
 
79
  not_every_new_word_is_used, word_out_of_range, word_count_error = validate_article(
80
  generated_article, lesson_words, base_chars, original_word_count)
 
 
 
 
 
 
81
 
82
  if not not_every_new_word_is_used and not word_out_of_range and not word_count_error:
 
83
  break
84
 
85
  return generated_article
 
5
  import json
6
 
7
  # 設置 OpenAI API 客戶端
8
+ IS_LOCAL = True
9
 
10
  if IS_LOCAL:
11
  local_json = json.load(open("local.json"))
 
46
 
47
  while attempt < max_attempts:
48
  attempt += 1
49
+
50
+ print("================Attempt=====================")
51
+ print(f"Attempt {attempt} to generate new article")
52
+ print("===========================================")
53
+
54
  prompt = f"""
55
  Please write a new and original Chinese article tailored for first-grade students. Here's a summary of the key points that you should follow:
56
 
 
78
  max_tokens=1000
79
  )
80
 
81
+ generated_text = response.choices[0].message.content.strip()
82
  generated_article = extract_article_from_content(generated_text)
83
 
84
  not_every_new_word_is_used, word_out_of_range, word_count_error = validate_article(
85
  generated_article, lesson_words, base_chars, original_word_count)
86
+
87
+ print("====validate_article====")
88
+ print(f"not_every_new_word_is_used: {not_every_new_word_is_used}")
89
+ print(f"word_out_of_range: {word_out_of_range}")
90
+ print(f"word_count_error: {word_count_error}")
91
+ print("=========================")
92
 
93
  if not not_every_new_word_is_used and not word_out_of_range and not word_count_error:
94
+ print("Generated article is valid")
95
  break
96
 
97
  return generated_article