Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeText ¶
DecodeText 将字节数据解码为 UTF-8 字符串,支持 GB18030 回退。
Types ¶
type GenerateTextFunc ¶
type GenerateTextFunc func(ctx context.Context, providerName string, messages []map[string]any, model string) (string, error)
GenerateTextFunc 是调用 LLM 生成文本的函数签名。 import 包通过此接口解耦对 llm 包的直接依赖。
type ImportResult ¶
type ImportResult struct {
NovelID int64 `json:"novel_id"`
Title string `json:"title"`
ChapterCount int `json:"chapter_count"`
SkippedCount int `json:"skipped_count"`
SkippedChapters []SkippedChapter `json:"skipped_chapters"`
NeedsLLM bool `json:"needs_llm"` // 正则分割结果不合理,提示前端可调用 LLM 分析
FilePath string `json:"file_path,omitempty"` // NeedsLLM 时回传文件路径,供前端调 ImportWithLLM
}
ImportResult 是完整导入流程的结果。
func Import ¶
func Import(ctx context.Context, logger *slog.Logger, db *gorm.DB, filePath string, gitName, gitEmail string, onProgress ProgressCallback) (*ImportResult, error)
Import 执行完整的小说导入流程:解析文件 → 创建 Novel → 写入章节 → git 提交。
func ImportWithResult ¶
func ImportWithResult(ctx context.Context, logger *slog.Logger, db *gorm.DB, result *Result, filePath string, gitName, gitEmail string, onProgress ProgressCallback) (*ImportResult, error)
ImportWithResult 使用已有的解析结果执行完整导入流程。 用于 LLM 兜底场景:先 AnalyzeWithLLM → ImportWithResult。
type ProgressCallback ¶
ProgressCallback 是进度回调函数,app 层用它来推送前端事件。
type Result ¶
type Result struct {
Title string
Chapters []Chapter
SkippedChapters []SkippedChapter
NeedsLLM bool // 当正则无法正确分割时设为 true,提示前端可调用 LLM 分析
}
Result 是导入解析的结果。
func AnalyzeWithLLM ¶
func AnalyzeWithLLM(ctx context.Context, filePath string, providerName string, modelID string, generateFn GenerateTextFunc) (*Result, error)
AnalyzeWithLLM 使用 LLM 分析小说文件的章节格式。 读取文件前 150 行,让 LLM 生成正则,编译后全文匹配分割。 ctx 用于取消 LLM 调用(如用户关闭窗口)。
type SkippedChapter ¶
SkippedChapter 记录解析时跳过的章节。
Click to show internal directories.
Click to hide internal directories.