refactor:重构智能角色/组织引入机制,从先预测后确认模式改为大纲后自动校验补全模式
This commit is contained in:
+328
-711
File diff suppressed because it is too large
Load Diff
@@ -4,71 +4,6 @@ from typing import Optional, List, Dict, Any
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
# 角色预测相关Schema
|
||||
class CharacterPredictionRequest(BaseModel):
|
||||
"""角色预测请求"""
|
||||
project_id: str
|
||||
start_chapter: int
|
||||
chapter_count: int = 3
|
||||
plot_stage: str = "development"
|
||||
story_direction: Optional[str] = "自然延续"
|
||||
enable_mcp: bool = True
|
||||
|
||||
|
||||
class PredictedCharacter(BaseModel):
|
||||
"""预测的角色信息"""
|
||||
name: Optional[str] = None
|
||||
role_description: str
|
||||
suggested_role_type: str
|
||||
importance: str
|
||||
appearance_chapter: int
|
||||
key_abilities: List[str] = []
|
||||
plot_function: str
|
||||
relationship_suggestions: List[Dict[str, str]] = []
|
||||
|
||||
|
||||
class CharacterPredictionResponse(BaseModel):
|
||||
"""角色预测响应"""
|
||||
needs_new_characters: bool
|
||||
reason: str
|
||||
character_count: int
|
||||
predicted_characters: List[PredictedCharacter]
|
||||
|
||||
|
||||
# 组织预测相关Schema
|
||||
class OrganizationPredictionRequest(BaseModel):
|
||||
"""组织预测请求"""
|
||||
project_id: str
|
||||
start_chapter: int
|
||||
chapter_count: int = 3
|
||||
plot_stage: str = "development"
|
||||
story_direction: Optional[str] = "自然延续"
|
||||
enable_mcp: bool = True
|
||||
|
||||
|
||||
class PredictedOrganization(BaseModel):
|
||||
"""预测的组织信息"""
|
||||
name: Optional[str] = None
|
||||
organization_description: str
|
||||
organization_type: str
|
||||
importance: str
|
||||
appearance_chapter: int
|
||||
power_level: int = 50
|
||||
plot_function: str
|
||||
location: Optional[str] = None
|
||||
motto: Optional[str] = None
|
||||
initial_members: List[Dict[str, Any]] = []
|
||||
relationship_suggestions: List[Dict[str, str]] = []
|
||||
|
||||
|
||||
class OrganizationPredictionResponse(BaseModel):
|
||||
"""组织预测响应"""
|
||||
needs_new_organizations: bool
|
||||
reason: str
|
||||
organization_count: int
|
||||
predicted_organizations: List[PredictedOrganization]
|
||||
|
||||
|
||||
class OutlineBase(BaseModel):
|
||||
"""大纲基础模型"""
|
||||
title: str = Field(..., description="章节标题")
|
||||
@@ -127,16 +62,6 @@ class OutlineGenerateRequest(BaseModel):
|
||||
keep_existing: bool = Field(False, description="是否保留现有大纲(续写时)")
|
||||
enable_mcp: bool = Field(True, description="是否启用MCP工具增强(搜索情节设计参考)")
|
||||
|
||||
# 自动角色引入相关参数
|
||||
enable_auto_characters: bool = Field(True, description="是否启用自动角色引入(根据剧情推进自动创建新角色)")
|
||||
require_character_confirmation: bool = Field(True, description="是否需要用户确认新角色(False则AI预测的角色直接创建)")
|
||||
confirmed_characters: Optional[List[Dict[str, Any]]] = Field(None, description="用户确认的角色列表(跳过预测直接创建)")
|
||||
|
||||
# 自动组织引入相关参数
|
||||
enable_auto_organizations: bool = Field(True, description="是否启用自动组织引入(根据剧情推进自动创建新组织)")
|
||||
require_organization_confirmation: bool = Field(True, description="是否需要用户确认新组织(False则AI预测的组织直接创建)")
|
||||
confirmed_organizations: Optional[List[Dict[str, Any]]] = Field(None, description="用户确认的组织列表(跳过预测直接创建)")
|
||||
|
||||
|
||||
class ChapterOutlineGenerateRequest(BaseModel):
|
||||
"""为单个章节生成大纲的请求模型"""
|
||||
|
||||
+150
-773
File diff suppressed because it is too large
Load Diff
@@ -383,35 +383,6 @@ export const outlineApi = {
|
||||
generateOutline: (data: GenerateOutlineRequest) =>
|
||||
api.post<unknown, { total: number; items: Outline[] }>('/outlines/generate', data).then(res => res.items),
|
||||
|
||||
// 预测续写所需角色
|
||||
predictCharacters: (data: {
|
||||
project_id: string;
|
||||
start_chapter: number;
|
||||
chapter_count: number;
|
||||
plot_stage: string;
|
||||
story_direction?: string;
|
||||
enable_mcp: boolean;
|
||||
}) =>
|
||||
api.post<unknown, {
|
||||
needs_new_characters: boolean;
|
||||
reason: string;
|
||||
character_count: number;
|
||||
predicted_characters: Array<{
|
||||
name: string | null;
|
||||
role_description: string;
|
||||
suggested_role_type: string;
|
||||
importance: string;
|
||||
appearance_chapter: number;
|
||||
key_abilities: string[];
|
||||
plot_function: string;
|
||||
relationship_suggestions: Array<{
|
||||
target_character_name: string;
|
||||
relationship_type: string;
|
||||
description?: string;
|
||||
}>;
|
||||
}>;
|
||||
}>('/outlines/predict-characters', data),
|
||||
|
||||
// 获取大纲关联的章节
|
||||
getOutlineChapters: (outlineId: string) =>
|
||||
api.get<unknown, {
|
||||
|
||||
@@ -18,8 +18,6 @@ export interface SSEClientOptions {
|
||||
onError?: (error: string, code?: number) => void;
|
||||
onComplete?: () => void;
|
||||
onConnectionError?: (error: Event) => void;
|
||||
onCharacterConfirmation?: (data: any) => void; // 新增:角色确认回调
|
||||
onOrganizationConfirmation?: (data: any) => void; // 新增:组织确认回调
|
||||
}
|
||||
|
||||
export class SSEClient {
|
||||
@@ -169,8 +167,6 @@ export class SSEPostClient {
|
||||
}
|
||||
|
||||
let buffer = '';
|
||||
let currentEvent = ''; // 跟踪当前事件类型
|
||||
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
|
||||
@@ -189,38 +185,14 @@ export class SSEPostClient {
|
||||
}
|
||||
|
||||
try {
|
||||
// 检查是否有事件类型
|
||||
const eventMatch = line.match(/^event: (.+)$/m);
|
||||
if (eventMatch) {
|
||||
currentEvent = eventMatch[1];
|
||||
}
|
||||
|
||||
// 解析数据
|
||||
const dataMatch = line.match(/^data: (.+)$/m);
|
||||
if (dataMatch) {
|
||||
const data = JSON.parse(dataMatch[1]);
|
||||
|
||||
// 根据事件类型处理
|
||||
if (currentEvent === 'character_confirmation_required') {
|
||||
// 处理角色确认事件
|
||||
if (this.options.onCharacterConfirmation) {
|
||||
this.options.onCharacterConfirmation(data);
|
||||
}
|
||||
currentEvent = ''; // 重置事件类型
|
||||
return; // 暂停流程,等待用户确认
|
||||
} else if (currentEvent === 'organization_confirmation_required') {
|
||||
// 处理组织确认事件
|
||||
if (this.options.onOrganizationConfirmation) {
|
||||
this.options.onOrganizationConfirmation(data);
|
||||
}
|
||||
currentEvent = ''; // 重置事件类型
|
||||
return; // 暂停流程,等待用户确认
|
||||
} else {
|
||||
// 标准消息处理
|
||||
const message: SSEMessage = data;
|
||||
await this.handleMessage(message, resolve, reject);
|
||||
currentEvent = ''; // 重置事件类型
|
||||
}
|
||||
// 标准消息处理
|
||||
const message: SSEMessage = data;
|
||||
await this.handleMessage(message, resolve, reject);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('解析SSE消息失败:', error, line);
|
||||
|
||||
Reference in New Issue
Block a user