gochains

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseChain

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

BaseChain provides common functionality for all chains.

func NewBaseChain

func NewBaseChain(templateText string, paramDefinition []string, formatInstructions string, maxTokens int, temperature float64, provider llmmodels.Provider, model string) (*BaseChain, error)

NewBaseChain creates a standard BaseChain.

func NewStructuredChain

func NewStructuredChain(
	templateText string,
	paramDefinition []string,
	responseSchemas []outputparser.ResponseSchema,
	formatInstrLLMWithNoJSONSupport string,
	maxTokens int,
	temperature float64,
	provider llmmodels.Provider,
	model string,
) (*BaseChain, error)

NewStructuredChain creates a BaseChain with structured or custom JSON output parsing.

func (*BaseChain) CreatePromptTemplate

func (bc *BaseChain) CreatePromptTemplate() *prompts.PromptTemplate

CreatePromptTemplate creates the appropriate prompt template based on chain type.

func (*BaseChain) GetChainType

func (bc *BaseChain) GetChainType() ChainType

func (*BaseChain) GetFormatInstructions

func (bc *BaseChain) GetFormatInstructions() string

GetFormatInstructions returns the format instructions for the chain.

func (*BaseChain) GetMaxTokens

func (bc *BaseChain) GetMaxTokens() int

func (*BaseChain) GetModel

func (bc *BaseChain) GetModel() llms.Model

func (*BaseChain) GetOptimalTemperature

func (bc *BaseChain) GetOptimalTemperature() float64

GetOptimalTemperature returns the optimal temperature for the chain type.

func (*BaseChain) GetOutputParser

func (bc *BaseChain) GetOutputParser() schema.OutputParser[any]

func (*BaseChain) GetParamDefinition

func (bc *BaseChain) GetParamDefinition() []string

func (*BaseChain) GetResponseSchemas

func (bc *BaseChain) GetResponseSchemas() []outputparser.ResponseSchema

func (*BaseChain) GetTemperature

func (bc *BaseChain) GetTemperature() float64

func (*BaseChain) GetTemplateText

func (bc *BaseChain) GetTemplateText() string

Getters

func (*BaseChain) IsStructured

func (bc *BaseChain) IsStructured() bool

func (*BaseChain) NewLLMChain

func (bc *BaseChain) NewLLMChain(llm llms.Model, memory schema.Memory) chains.LLMChain

NewLLMChain creates a new LLMChain with common configuration.

func (*BaseChain) SetChainType

func (bc *BaseChain) SetChainType(chainType ChainType)

func (*BaseChain) ValidateStructuredResponse

func (bc *BaseChain) ValidateStructuredResponse(response map[string]any) error

ValidateStructuredResponse validates that the response contains expected keys.

type BaseOutputParser

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

BaseOutputParser provides common functionality for all parsers

func (*BaseOutputParser) GetFormat

func (p *BaseOutputParser) GetFormat() string

func (*BaseOutputParser) GetFormatInstructions

func (p *BaseOutputParser) GetFormatInstructions() string

func (*BaseOutputParser) Parse

func (p *BaseOutputParser) Parse(text string) (any, error)

func (*BaseOutputParser) ParseWithPrompt

func (p *BaseOutputParser) ParseWithPrompt(text string, _ llms.PromptValue) (any, error)

func (*BaseOutputParser) Type

func (p *BaseOutputParser) Type() string

type ChainBuilder

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

ChainBuilder provides a fluent interface for building chains.

func NewChainBuilder

func NewChainBuilder() *ChainBuilder

NewChainBuilder creates a new chain builder.

func (*ChainBuilder) Build

func (cb *ChainBuilder) Build() (*BaseChain, error)

func (*ChainBuilder) WithCustomJSONFormat

func (cb *ChainBuilder) WithCustomJSONFormat() *ChainBuilder

func (*ChainBuilder) WithJSON

func (cb *ChainBuilder) WithJSON(isJson bool) *ChainBuilder

func (*ChainBuilder) WithMaxTokens

func (cb *ChainBuilder) WithMaxTokens(tokens int) *ChainBuilder

func (*ChainBuilder) WithModel

func (cb *ChainBuilder) WithModel(provider llmmodels.Provider, model string) *ChainBuilder

func (*ChainBuilder) WithParams

func (cb *ChainBuilder) WithParams(params []string) *ChainBuilder

func (*ChainBuilder) WithStructuredOutput

func (cb *ChainBuilder) WithStructuredOutput(schemas []outputparser.ResponseSchema) *ChainBuilder

func (*ChainBuilder) WithTemperature

func (cb *ChainBuilder) WithTemperature(temp float64) *ChainBuilder

func (*ChainBuilder) WithTemplate

func (cb *ChainBuilder) WithTemplate(template string) *ChainBuilder

type ChainFactory

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

ChainFactory creates different types of chains

func NewChainFactory

func NewChainFactory(memory schema.Memory) *ChainFactory

type ChainType

type ChainType string

ChainType defines the type of chain and output parsing.

const (
	ChainTypeDefault    ChainType = "default"
	ChainTypeStructured ChainType = "structured"
)

type OutputParserConfig

type OutputParserConfig struct {
	FormatInstructions string
}

type RawStringParser

type RawStringParser struct{}

RawStringParser is an output parser that returns the input text as-is.

func NewRawStringParser

func NewRawStringParser() *RawStringParser

NewRawStringParser creates a new RawStringParser.

func (*RawStringParser) GetFormatInstructions

func (p *RawStringParser) GetFormatInstructions() string

GetFormatInstructions returns an empty string.

func (*RawStringParser) Parse

func (p *RawStringParser) Parse(text string) (any, error)

Parse returns the input text.

func (*RawStringParser) ParseWithPrompt

func (p *RawStringParser) ParseWithPrompt(text string, prompt llms.PromptValue) (any, error)

ParseWithPrompt returns the input text.

func (*RawStringParser) Type

func (p *RawStringParser) Type() string

Type returns the type of the parser.

Jump to

Keyboard shortcuts

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