修改了结果保存逻辑,原始状态下推文保存位置错误

This commit is contained in:
jinye_huang 2025-04-22 15:19:08 +08:00
parent 096c78c513
commit be8639406c
2 changed files with 19 additions and 5 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/result/
*.zip

View File

@ -171,12 +171,24 @@ def generate_single_content(ai_agent, system_prompt, user_prompt, item, output_d
print(f"生成完成tokens: {tokens}, 耗时: {time_cost}s") 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) 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) # Save content and prompt to the correct variant directory
tweet_content.save_content(os.path.join(result_dir, "article.json")) content_save_path = os.path.join(variant_result_dir, "article.json")
tweet_content.save_prompt(os.path.join(result_dir, "tweet_prompt.txt")) 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 return tweet_content, result
except Exception as e: except Exception as e: