reasoning

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chain

type Chain struct {
	ID        string    `json:"id"`
	Steps     []Step    `json:"steps"`
	MinSteps  int       `json:"min_steps"`
	MaxSteps  int       `json:"max_steps"`
	Current   int       `json:"current"`
	Status    string    `json:"status"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

Chain 推理链

func FromJSON

func FromJSON(data string) (*Chain, error)

FromJSON 从 JSON 解析

func NewChain

func NewChain(config ChainConfig) *Chain

NewChain 创建推理链

func (*Chain) AddStep

func (c *Chain) AddStep(step Step) error

AddStep 添加推理步骤

func (*Chain) Complete

func (c *Chain) Complete()

Complete 完成推理链

func (*Chain) GetCurrentStep

func (c *Chain) GetCurrentStep() *Step

GetCurrentStep 获取当前步骤

func (*Chain) ShouldContinue

func (c *Chain) ShouldContinue() bool

ShouldContinue 判断是否应该继续推理

func (*Chain) Summary

func (c *Chain) Summary() string

Summary 生成推理链摘要

func (*Chain) ToJSON

func (c *Chain) ToJSON() (string, error)

ToJSON 转换为 JSON

func (*Chain) UpdateStep

func (c *Chain) UpdateStep(stepID string, updates map[string]any) error

UpdateStep 更新推理步骤

type ChainConfig

type ChainConfig struct {
	MinSteps      int     // 最小推理步数
	MaxSteps      int     // 最大推理步数
	MinConfidence float64 // 最小置信度阈值
}

ChainConfig 推理链配置

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine 推理引擎

func NewEngine

func NewEngine(provider provider.Provider, config EngineConfig) *Engine

NewEngine 创建推理引擎

func (*Engine) Reason

func (e *Engine) Reason(ctx context.Context, query string, systemPrompt string) (*Chain, error)

Reason 执行推理

type EngineConfig

type EngineConfig struct {
	MinSteps      int     // 最小推理步数
	MaxSteps      int     // 最大推理步数
	MinConfidence float64 // 最小置信度
	UseJSON       bool    // 是否使用 JSON 格式
	Temperature   float64 // 温度参数
}

EngineConfig 推理引擎配置

type JSONParser

type JSONParser struct{}

JSONParser JSON 格式推理解析器

func NewJSONParser

func NewJSONParser() *JSONParser

NewJSONParser 创建 JSON 解析器

func (*JSONParser) Parse

func (p *JSONParser) Parse(ctx context.Context, text string) ([]Step, error)

Parse 解析推理步骤

type NextAction

type NextAction string

NextAction 下一步行动

const (
	NextActionContinue NextAction = "continue" // 继续推理
	NextActionComplete NextAction = "complete" // 完成推理
	NextActionRetry    NextAction = "retry"    // 重试当前步骤
)

type Parser

type Parser interface {
	Parse(ctx context.Context, text string) ([]Step, error)
}

Parser 推理步骤解析器

type Step

type Step struct {
	ID         string     `json:"id"`
	Title      string     `json:"title"`
	Action     string     `json:"action"`
	Result     string     `json:"result"`
	Reasoning  string     `json:"reasoning"`
	Confidence float64    `json:"confidence"` // 0.0-1.0
	Status     StepStatus `json:"status"`
	NextAction NextAction `json:"next_action"`
	CreatedAt  time.Time  `json:"created_at"`
	UpdatedAt  time.Time  `json:"updated_at"`
}

Step 推理步骤

type StepStatus

type StepStatus string

StepStatus 推理步骤状态

const (
	StepStatusPending   StepStatus = "pending"
	StepStatusRunning   StepStatus = "running"
	StepStatusCompleted StepStatus = "completed"
	StepStatusFailed    StepStatus = "failed"
)

Jump to

Keyboard shortcuts

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