import pandas as pd from model_handler import ModelHandler from config import LING_1T from .agent_common_utils import format_df_to_string def fetch_paragraph_continuation_agent(prompt: str, editor_content: str, style: str, kb_df: pd.DataFrame, short_outline_df: pd.DataFrame, long_outline_df: pd.DataFrame): """ Agent for fetching a single paragraph continuation (Ribbon UI version). """ print("\n[Agent][fetch_paragraph_continuation_agent] === 推理类型:整段续写 (Single) ===") try: # 1. Format context style_context = f"### 整体章程\n{style}\n\n" kb_context = format_df_to_string(kb_df, "知识库") short_outline_context = format_df_to_string(short_outline_df, "当前章节大纲") long_outline_context = format_df_to_string(long_outline_df, "故事总纲") # 2. Build System Prompt system_prompt = ( "你是一个富有创意的长篇小说家。请根据提供的背景设定和当前文本,自然地续写一段高质量的剧情。\n" "请直接输出续写内容,不要包含任何解释、前缀或后缀。" ) # 3. Build User Prompt full_context = style_context + kb_context + long_outline_context + short_outline_context user_instruction = prompt if prompt else '请基于当前内容,自然地延续剧情,写一个完整的段落。' user_prompt = ( f"### 背景设定与大纲\n{full_context}\n" f"### 当前已写内容 (末尾部分)\n{editor_content[-2000:]}\n\n" f"### 用户指令\n{user_instruction}" ) # 4. Call LLM model_handler = ModelHandler() response_generator = model_handler.generate_code( system_prompt=system_prompt, user_prompt=user_prompt, model_choice=LING_1T ) full_response = "".join(chunk for chunk in response_generator) return full_response.strip() except Exception as e: print(f"[Agent] Error fetching paragraph continuation: {e}") return f"获取续写时出错: {e}"