Documentation
¶
Index ¶
- Constants
- func CombineFragments(fragments []PromptFragment) string
- func MockLLM(ctx Context, prompt string, userQuery string) string
- type Context
- type Middleware
- type MiddlewarePipeline
- func (p *MiddlewarePipeline) ExecuteParsePhase(context Context, llmResponse string) (Context, string)
- func (p *MiddlewarePipeline) ExecutePromptPhase(initialContext Context, initialFragments []PromptFragment) (Context, []PromptFragment, string)
- func (p *MiddlewarePipeline) Middlewares() []Middleware
- func (p *MiddlewarePipeline) Use(middleware Middleware) *MiddlewarePipeline
- type PromptFragment
- type PromptFragmentMetadata
- type SystemInstructionMiddleware
- func (m *SystemInstructionMiddleware) Description() string
- func (m *SystemInstructionMiddleware) ID() string
- func (m *SystemInstructionMiddleware) Name() string
- func (m *SystemInstructionMiddleware) Parse(ctx Context, response string) (Context, string)
- func (m *SystemInstructionMiddleware) Prompt(ctx Context, fragments []PromptFragment) (Context, []PromptFragment)
- type ThinkingModeMiddleware
- func (m *ThinkingModeMiddleware) Description() string
- func (m *ThinkingModeMiddleware) ID() string
- func (m *ThinkingModeMiddleware) Name() string
- func (m *ThinkingModeMiddleware) Parse(ctx Context, response string) (Context, string)
- func (m *ThinkingModeMiddleware) Prompt(ctx Context, fragments []PromptFragment) (Context, []PromptFragment)
- type TokenCounterMiddleware
- func (m *TokenCounterMiddleware) Description() string
- func (m *TokenCounterMiddleware) ID() string
- func (m *TokenCounterMiddleware) Name() string
- func (m *TokenCounterMiddleware) Parse(ctx Context, response string) (Context, string)
- func (m *TokenCounterMiddleware) Prompt(ctx Context, fragments []PromptFragment) (Context, []PromptFragment)
Constants ¶
const ExtractedThinkingContextKey = "extractedThinking"
const PromptTokensContextKey = "promptTokens"
const ResponseTokensContextKey = "responseTokens"
const ThinkingModeContextKey = "thinkingMode"
const TotalTokensContextKey = "totalTokens"
Variables ¶
This section is empty.
Functions ¶
func CombineFragments ¶
func CombineFragments(fragments []PromptFragment) string
CombineFragments joins the content of sorted PromptFragments into a single string.
Types ¶
type Context ¶
type Context = *orderedmap.OrderedMap[string, interface{}]
Context is a flexible, extensible state object that flows through the middleware pipeline, preserving insertion order of keys.
func CloneContext ¶
CloneContext creates a deep copy of the context map itself, but a shallow copy of the values.
type Middleware ¶
type Middleware interface {
// Prompt transforms context and prompt fragments before sending to an LLM.
// It returns the potentially modified context and the new list of fragments.
Prompt(ctx Context, fragments []PromptFragment) (Context, []PromptFragment)
// Parse processes the LLM response and updates the context.
// It returns the potentially modified context and the processed response string.
Parse(ctx Context, response string) (Context, string)
// ID returns a unique identifier for the middleware.
ID() string
// Name returns a human-readable name for the middleware.
Name() string
// Description returns a short description of the middleware's purpose.
Description() string
}
Middleware defines the interface for components in the processing pipeline.
type MiddlewarePipeline ¶
type MiddlewarePipeline struct {
// contains filtered or unexported fields
}
MiddlewarePipeline manages the execution of a sequence of middlewares.
func NewMiddlewarePipeline ¶
func NewMiddlewarePipeline() *MiddlewarePipeline
NewMiddlewarePipeline creates a new, empty middleware pipeline.
func (*MiddlewarePipeline) ExecuteParsePhase ¶
func (p *MiddlewarePipeline) ExecuteParsePhase( context Context, llmResponse string, ) (Context, string)
ExecuteParsePhase runs the response parsing phase of the pipeline.
func (*MiddlewarePipeline) ExecutePromptPhase ¶
func (p *MiddlewarePipeline) ExecutePromptPhase( initialContext Context, initialFragments []PromptFragment, ) (Context, []PromptFragment, string)
ExecutePromptPhase runs the prompt transformation phase of the pipeline.
func (*MiddlewarePipeline) Middlewares ¶
func (p *MiddlewarePipeline) Middlewares() []Middleware
Middlewares returns the list of middlewares currently in the pipeline.
func (*MiddlewarePipeline) Use ¶
func (p *MiddlewarePipeline) Use(middleware Middleware) *MiddlewarePipeline
Use adds a middleware to the pipeline.
type PromptFragment ¶
type PromptFragment struct {
Content string `json:"content"`
Metadata PromptFragmentMetadata `json:"metadata"`
}
PromptFragment represents a structured piece of the prompt with associated metadata.
func SortFragments ¶
func SortFragments(fragments []PromptFragment) []PromptFragment
SortFragments sorts prompt fragments based on position ('start', 'middle', 'end') and then by priority (descending).
type PromptFragmentMetadata ¶
type PromptFragmentMetadata struct {
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Position string `json:"position,omitempty"` // "start", "middle", "end"
Priority int `json:"priority,omitempty"`
Tags []string `json:"tags,omitempty"`
}
PromptFragmentMetadata holds metadata associated with a PromptFragment.
type SystemInstructionMiddleware ¶
type SystemInstructionMiddleware struct {
Instructions string
}
func NewSystemInstructionMiddleware ¶
func NewSystemInstructionMiddleware(instructions string) *SystemInstructionMiddleware
NewSystemInstructionMiddleware creates a middleware that adds a system instruction.
func (*SystemInstructionMiddleware) Description ¶
func (m *SystemInstructionMiddleware) Description() string
func (*SystemInstructionMiddleware) ID ¶
func (m *SystemInstructionMiddleware) ID() string
func (*SystemInstructionMiddleware) Name ¶
func (m *SystemInstructionMiddleware) Name() string
func (*SystemInstructionMiddleware) Parse ¶
func (m *SystemInstructionMiddleware) Parse(ctx Context, response string) (Context, string)
func (*SystemInstructionMiddleware) Prompt ¶
func (m *SystemInstructionMiddleware) Prompt(ctx Context, fragments []PromptFragment) (Context, []PromptFragment)
type ThinkingModeMiddleware ¶
type ThinkingModeMiddleware struct{}
func NewThinkingModeMiddleware ¶
func NewThinkingModeMiddleware() *ThinkingModeMiddleware
NewThinkingModeMiddleware creates a middleware that handles <thinking> tags.
func (*ThinkingModeMiddleware) Description ¶
func (m *ThinkingModeMiddleware) Description() string
func (*ThinkingModeMiddleware) ID ¶
func (m *ThinkingModeMiddleware) ID() string
func (*ThinkingModeMiddleware) Name ¶
func (m *ThinkingModeMiddleware) Name() string
func (*ThinkingModeMiddleware) Parse ¶
func (m *ThinkingModeMiddleware) Parse(ctx Context, response string) (Context, string)
func (*ThinkingModeMiddleware) Prompt ¶
func (m *ThinkingModeMiddleware) Prompt(ctx Context, fragments []PromptFragment) (Context, []PromptFragment)
type TokenCounterMiddleware ¶
type TokenCounterMiddleware struct{}
func NewTokenCounterMiddleware ¶
func NewTokenCounterMiddleware() *TokenCounterMiddleware
NewTokenCounterMiddleware creates a middleware that estimates token counts.
func (*TokenCounterMiddleware) Description ¶
func (m *TokenCounterMiddleware) Description() string
func (*TokenCounterMiddleware) ID ¶
func (m *TokenCounterMiddleware) ID() string
func (*TokenCounterMiddleware) Name ¶
func (m *TokenCounterMiddleware) Name() string
func (*TokenCounterMiddleware) Parse ¶
func (m *TokenCounterMiddleware) Parse(ctx Context, response string) (Context, string)
func (*TokenCounterMiddleware) Prompt ¶
func (m *TokenCounterMiddleware) Prompt(ctx Context, fragments []PromptFragment) (Context, []PromptFragment)