Help us shape the future of Go! Take the 2026 Go Developer Survey

style

package
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const PreviewMaxRunes = 120

Variables

This section is empty.

Functions

func TruncatePreview

func TruncatePreview(content string) string

TruncatePreview 截取前 PreviewMaxRunes 个字符作为预览文本。

Types

type ExtractResult

type ExtractResult struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	RawContent  string `json:"raw_content"`
	FilePath    string `json:"file_path"`
}

ExtractResult 是风格提取的返回值。

func Extract

func Extract(ctx context.Context, llmClient *llm.Client,
	samples []Sample, providerName, modelID, reasoningEffort string) (*ExtractResult, error)

Extract 分析样本文字的写作风格,生成仿写 skill。 取消由调用方(app 层)通过 ctx 管理。

type ListOptions

type ListOptions struct {
	PageParams storage.PageParams
	NovelID    int64  // 0=仅全局,N=全局+该小说专属
	Search     string // 空字符串=不过滤,按 name LIKE 匹配
}

ListOptions 是 List 方法的可选过滤条件。零值表示不过滤。

type Sample

type Sample struct {
	ID        int64       `gorm:"column:id;primaryKey;autoIncrement"    json:"id"`
	NovelID   int64       `gorm:"column:novel_id;not null"               json:"novel_id"`
	IsGlobal  bool        `gorm:"column:is_global;not null"              json:"is_global"`
	Name      string      `gorm:"column:name;not null"                   json:"name"`
	Content   string      `gorm:"column:content;not null"                json:"content"`
	Preview   string      `gorm:"column:preview;not null"                json:"preview"`
	Tags      StringSlice `gorm:"column:tags;type:text;not null"         json:"tags"`
	WordCount int         `gorm:"column:word_count;not null"             json:"word_count"`
	CreatedAt time.Time   `gorm:"column:created_at;autoCreateTime"       json:"created_at"`
	UpdatedAt time.Time   `gorm:"column:updated_at;autoUpdateTime"       json:"updated_at"`
}

Sample 是一条风格素材的 GORM model。

func (Sample) TableName

func (Sample) TableName() string

type Stats

type Stats struct {
	TotalChars      int     `json:"total_chars"`
	TotalWords      int     `json:"total_words"`
	SentenceCount   int     `json:"sentence_count"`
	ShortSentPct    float64 `json:"short_sent_pct"` // <15 字
	MidSentPct      float64 `json:"mid_sent_pct"`   // 15-30 字
	LongSentPct     float64 `json:"long_sent_pct"`  // >30 字
	AvgSentLen      float64 `json:"avg_sent_len"`
	SentLenStdDev   float64 `json:"sent_len_std_dev"` // 句长标准差
	CommaDensity    float64 `json:"comma_density"`    // 逗号占比
	PeriodDensity   float64 `json:"period_density"`   // 句号占比
	ExclaimDensity  float64 `json:"exclaim_density"`  // 感叹号占比
	QuestionDensity float64 `json:"question_density"` // 问号占比
	QuoteDensity    float64 `json:"quote_density"`    // 引号占比
	ParagraphCount  int     `json:"paragraph_count"`
	AvgParaLen      float64 `json:"avg_para_len"`
}

Stats 是代码计算的确定性文本统计,不依赖 LLM。

func ComputeStats

func ComputeStats(samples []Sample) Stats

ComputeStats 对多段素材文本进行确定性统计。

type Store

type Store struct {
	DB *gorm.DB
	// contains filtered or unexported fields
}

Store 管理 Sample 持久化。

func NewStore

func NewStore(db *gorm.DB, logger *slog.Logger) *Store

NewStore 创建 style 存储。

func (*Store) GetByIDs

func (s *Store) GetByIDs(ctx context.Context, ids []int64) ([]Sample, error)

GetByIDs 批量按 ID 获取素材,用于 ComputeStats 和 ExtractStyle。

func (*Store) List

func (s *Store) List(ctx context.Context, opts ListOptions) (*storage.PageResult[Sample], error)

List 分页列出风格素材。 当 NovelID > 0 时,返回全局素材 + 该小说专属素材(is_global = true OR novel_id = ?); 当 NovelID == 0 时,仅返回全局素材(is_global = true)。 List 只查摘要字段,不读大 content。

type StringSlice

type StringSlice []string

StringSlice 是 []string 的 DB 适配类型,存储为 JSON TEXT。

func (*StringSlice) Scan

func (s *StringSlice) Scan(value any) error

Scan 实现 sql.Scanner,从 DB 读取 JSON TEXT → []string。

func (StringSlice) Value

func (s StringSlice) Value() (driver.Value, error)

Value 实现 driver.Valuer,从 []string → JSON TEXT 写入 DB。

type StyleSkillOutput

type StyleSkillOutput struct {
	Name        string `json:"name" jsonschema:"required,description=风格名称(中文)"`
	Description string `json:"description" jsonschema:"required,description=一句话描述适合什么写作场景,什么时候调用"`
	Content     string `` /* 251-byte string literal not displayed */
}

StyleSkillOutput 是风格提取 toolcall 的结构化输出,由 LLM 调用 output_style_skill 工具填充。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL