Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Attributes ¶
type Client ¶
type Client interface {
// GetLLMResponse prompts the LLM and gets its text response, hopefully (not certainly) with the given schema.
GetLLMResponse(systemPrompt string, userPrompt string, schema map[string]any) (string, LLMUsage, error)
}
Client is a wrapper around an LLM with schema capabilities.
func NewOpenAIClient ¶
NewOpenAIClient creates a new client that communicates with the OpenAI API.
type Entity ¶
type Entity interface {
PureData
Attr() *Attributes
// contains filtered or unexported methods
}
type LLMType ¶
type LLMType interface {
Parse(value string) (Entity, error)
Instructions() LLMTypeInstructions
}
Type describes an object capable of parsing a response to a Question into an Entity.
type LLMTypeInstructions ¶
TypeInstructions define how to respond with a [Type] for the LLM.
type Protocol ¶
type Protocol interface {
// Schema creates a jsonschema given a set of keyed questions.
Schema(qs map[string]Question) map[string]any
// SystemPrompt builds a system prompt for the given set of [Question]s.
SystemPrompt(qs map[string]Question) string
// ParseResponse takes a raw LLM response and parses it into lists of [Entity], keyed by question key.
ParseResponse(resp string) (map[string][]Entity, error)
}
Protocol defines a method of communication to and from the LLM.
func NewBasicProtocol ¶
func NewBasicProtocol(roleAndTask RoleAndTask, types map[string]LLMType) Protocol
type Question ¶
type Question struct {
// Question is the one-liner, for example `Who is the author of this document?`.
Question string `json:"question"`
// Details provides extra details, examples, and instructions on how to answer this question, as bullet points.
Details []string `json:"details"`
// AllowedTypeKeys lists all the keys of the types which the LLM may respond with.
AllowedTypeKeys []string `json:"allowed_type_keys"`
}
Question defines a sepcific question to send to the LLM.
type Range ¶
Range defines a range of characters from the source document.
type RoleAndTask ¶
RoleAndTask defines a role and a task for the LLM, both of which should be short (~ 1 sentence).
func GetDefaultRoleAndTask ¶
func GetDefaultRoleAndTask() RoleAndTask
GetDefaultRoleAndTask builds a RoleAndTask for a generic document information extraction task.
type ValueEntity ¶
type ValueEntity[T Value] struct { Attributes Attributes Value T }
func NewValueEntity ¶
func NewValueEntity[T Value](v T) *ValueEntity[T]
func (*ValueEntity[T]) Attr ¶
func (e *ValueEntity[T]) Attr() *Attributes
func (*ValueEntity[T]) Clone ¶
func (e *ValueEntity[T]) Clone() PureData
func (*ValueEntity[T]) Eq ¶
func (e *ValueEntity[T]) Eq(other PureData) bool
Eq implements PureData.
func (*ValueEntity[T]) String ¶
func (e *ValueEntity[T]) String() string
func (*ValueEntity[T]) Validate ¶
func (e *ValueEntity[T]) Validate() error