bootstrap

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultConfigPath

func DefaultConfigPath() string

DefaultConfigPath 返回全局配置文件路径 ~/.ainovel/config.json。

func NeedsSetup

func NeedsSetup(flagPath string) bool

NeedsSetup 检查是否需要首次引导(配置文件不存在时触发)。

func SaveConfig

func SaveConfig(path string, cfg Config) error

SaveConfig 将配置写入指定路径(JSON 格式,缩进美化)。

Types

type Config

type Config struct {
	// 运行时字段(不序列化到 JSON)
	Prompt    string `json:"-"` // 用户的小说需求
	NovelName string `json:"-"` // 小说名(用作输出目录名)
	OutputDir string `json:"-"` // 输出根目录

	// 默认 LLM 配置
	Provider  string `json:"provider"` // 默认 provider(Providers map 中的 key)
	ModelName string `json:"model"`    // 默认模型名

	// Provider 凭证库
	Providers map[string]ProviderConfig `json:"providers,omitempty"`

	// 角色级模型覆盖
	Roles map[string]RoleConfig `json:"roles,omitempty"`

	// 创作参数
	Style         string `json:"style,omitempty"`
	ContextWindow int    `json:"context_window,omitempty"`
}

Config 小说应用配置。

func LoadConfig

func LoadConfig(flagPath string) (Config, error)

LoadConfig 按优先级加载并合并配置:

  1. ~/.ainovel/config.json(全局)
  2. ./ainovel.json(项目级覆盖)
  3. flagPath 指定的路径(最高优先级)

func RunSetup

func RunSetup() (Config, error)

RunSetup 运行首次引导,返回生成的配置。

func (*Config) DefaultProviderConfig

func (c *Config) DefaultProviderConfig() ProviderConfig

DefaultProviderConfig 返回默认 provider 的凭证配置。

func (*Config) FillDefaults

func (c *Config) FillDefaults()

FillDefaults 填充默认值。

func (*Config) Validate

func (c *Config) Validate() error

Validate 校验配置(CLI 模式,要求 Prompt 非空)。

func (*Config) ValidateBase

func (c *Config) ValidateBase() error

ValidateBase 校验基础配置。

type ModelSet

type ModelSet struct {
	Default agentcore.ChatModel
	// contains filtered or unexported fields
}

ModelSet 持有按角色分配的模型实例,未配置的角色回退到默认模型。

func NewModelSet

func NewModelSet(cfg Config) (*ModelSet, error)

NewModelSet 根据配置创建多模型集合。 相同 provider+model 组合复用同一个实例。

func (*ModelSet) ForRole

func (ms *ModelSet) ForRole(role string) agentcore.ChatModel

ForRole 返回指定角色的模型,未配置时返回默认模型。

func (*ModelSet) Summary

func (ms *ModelSet) Summary() string

Summary 返回模型分配摘要(供日志使用)。

type ProviderConfig

type ProviderConfig struct {
	Type    string `json:"type,omitempty"`     // API 协议类型(openai/anthropic/gemini),自定义代理时指定
	APIKey  string `json:"api_key,omitempty"`  // API Key
	BaseURL string `json:"base_url,omitempty"` // API Base URL
}

ProviderConfig 定义单个 LLM 提供商的凭证。

func (ProviderConfig) ProviderType

func (pc ProviderConfig) ProviderType(name string) string

ProviderType 返回有效的 API 协议类型。 优先使用显式 Type,否则从 provider 名称推断,最终回退到 openai。

func (ProviderConfig) RequiresAPIKey

func (pc ProviderConfig) RequiresAPIKey(name string) bool

RequiresAPIKey 返回该 provider 是否必须显式配置 api_key。 约定: 1. ollama / bedrock 允许无 key; 2. 显式指定 Type 的配置视为自定义代理,允许无 key; 3. 其他 provider 默认要求 key,保持对官方托管接口的保守校验。

type RoleConfig

type RoleConfig struct {
	Provider string `json:"provider"` // provider 名称(Providers map 中的 key)
	Model    string `json:"model"`    // 模型名(原样透传,不做任何解析)
}

RoleConfig 定义单个角色的模型覆盖。

Jump to

Keyboard shortcuts

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