This commit is contained in:
2025-09-04 15:30:56 +08:00
parent ac194e2962
commit eea9b3b0aa
6 changed files with 102 additions and 53 deletions

View File

@@ -52,8 +52,8 @@ class LLMClient:
yield f"处理请求时发生异常: {str(e)}"
async def save_lesson_plan(content_chunks, output_file):
"""异步保存导学案内容到文件"""
async def save_lesson_plan(content_chunks, output_file, stream_print=False):
"""异步保存案内容到文件,支持实时打印"""
try:
output_dir = os.path.dirname(output_file)
if output_dir and not os.path.exists(output_dir):
@@ -66,12 +66,15 @@ async def save_lesson_plan(content_chunks, output_file):
full_content.append(chunk)
await f.write(chunk)
await f.flush()
# 实时打印输出内容
if stream_print:
print(chunk, end='', flush=True)
logger.info(f"导学案已保存到: {os.path.abspath(output_file)}")
logger.info(f"案已保存到: {os.path.abspath(output_file)}")
return ''.join(full_content), True
except Exception as e:
logger.error(f"保存导学案失败: {str(e)}")
logger.error(f"保存案失败: {str(e)}")
return None, False