From be8639406c882b05711c379689e8196b91c5fc2c Mon Sep 17 00:00:00 2001 From: jinye_huang Date: Tue, 22 Apr 2025 15:19:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E9=80=BB=E8=BE=91=EF=BC=8C=E5=8E=9F=E5=A7=8B?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E4=B8=8B=E6=8E=A8=E6=96=87=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ utils/tweet_generator.py | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..312ba94 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/result/ +*.zip diff --git a/utils/tweet_generator.py b/utils/tweet_generator.py index 35c73d6..41bd9da 100644 --- a/utils/tweet_generator.py +++ b/utils/tweet_generator.py @@ -171,12 +171,24 @@ def generate_single_content(ai_agent, system_prompt, user_prompt, item, output_d print(f"生成完成,tokens: {tokens}, 耗时: {time_cost}s") - # 保存到单独文件 + # --- Correct directory structure --- + # Define the full path to the run-specific directory + run_specific_output_dir = os.path.join(output_dir, run_id) # e.g., result/2025-04-22... + + # Define the directory for this specific article variant *under* the run directory + variant_result_dir = os.path.join(run_specific_output_dir, f"{article_index}_{variant_index}") # e.g., result/2025-04-22.../1_1 + os.makedirs(variant_result_dir, exist_ok=True) # Ensure the variant directory exists + + # Create the tweetContent object (output_dir param might be irrelevant for saving) tweet_content = tweetContent(result, user_prompt, output_dir, run_id, article_index, variant_index) - result_dir = os.path.join(output_dir, f"{article_index}_{variant_index}") - os.makedirs(result_dir, exist_ok=True) - tweet_content.save_content(os.path.join(result_dir, "article.json")) - tweet_content.save_prompt(os.path.join(result_dir, "tweet_prompt.txt")) + + # Save content and prompt to the correct variant directory + content_save_path = os.path.join(variant_result_dir, "article.json") + prompt_save_path = os.path.join(variant_result_dir, "tweet_prompt.txt") + tweet_content.save_content(content_save_path) + tweet_content.save_prompt(prompt_save_path) + print(f" Saved article content to: {content_save_path}") # Add log for confirmation + # --- End directory structure correction --- return tweet_content, result except Exception as e: