Documentation
¶
Index ¶
- Constants
- func IsValidRole(role string) bool
- func OutputSummaryContent(output StreamReader, contentbuf *strings.Builder, delta string)
- func OutputSummaryError(output StreamReader, contentbuf *strings.Builder, status LLMStatus, ...)
- type Action
- type Agent
- func (a *Agent) Action(doAct *DoAction) *Agent
- func (a *Agent) AskLLM(llm LLM, stream bool) *Agent
- func (a *Agent) AskReflection(reflection string) *Agent
- func (a *Agent) GetLongHistory() []ChatMessage
- func (a *Agent) GetShortHistory() []ChatMessage
- func (a *Agent) Prompt(prompts ...*PromptItem) *Agent
- func (a *Agent) ReadQuestion(cxt context.Context, input *Input, output *Output) *Agent
- func (a *Agent) Reflection(doRef *DoReflection, retry int) *Agent
- func (a *Agent) StreamDelta(contentbuf *strings.Builder, delta string)
- func (a *Agent) StreamEnd(contentbuf *strings.Builder)
- func (a *Agent) StreamError(contentbuf *strings.Builder, status LLMStatus, errstr string)
- func (a *Agent) StreamStart() *strings.Builder
- func (a *Agent) Summarize(cxt context.Context, summary *PromptItem, prefix *PromptItem, force bool) *Agent
- func (a *Agent) WaitResponse(cxt context.Context) *Agent
- type AgentStage
- type ChatMessage
- type Chunk
- type Database
- type DoAction
- type DoReflection
- type Embedding
- type EmbeddingModel
- type EmbeddingStage
- type Input
- type LLM
- type LLMStatus
- type Output
- type ParserFunction
- type PromptItem
- type Rag
- func (r *Rag) Embeddings(cxt context.Context, stage EmbeddingStage, texts []string) ([]Embedding, error)
- func (r *Rag) Indexing(cxt context.Context, path string, payload interface{}, splitter Splitter, ...) error
- func (r *Rag) Retrieval(cxt context.Context, path string, queries []string, topk int) ([]ScoredChunks, error)
- type ScoredChunk
- type ScoredChunks
- type Splitter
- type StreamReader
- type StreamStage
- type Summary
- func (s *Summary) AskLLM(msgs []ChatMessage) (LLMStatus, ChatMessage)
- func (s *Summary) InitSummary() error
- func (s *Summary) Summarize(longHistory []ChatMessage, shortHistory []ChatMessage, force bool) (LLMStatus, []ChatMessage)
- func (s *Summary) SummarizeOnce(msgs []ChatMessage) (LLMStatus, []ChatMessage)
- func (s *Summary) SummarizeSplit(force bool, msgs []ChatMessage, depth int) (LLMStatus, []ChatMessage)
- func (s *Summary) TokenizeMessages(messages []ChatMessage) ([]TokenizedMessage, int)
- type TokenizedMessage
Constants ¶
View Source
const ( VerboseNone int = iota VerboseShowSending VerboseShowReceiving )
View Source
const ( ROLE_SYSTEM string = "system" ROLE_USER string = "user" ROLE_ASSISTANT string = "assistant" )
View Source
const (
DOCUMENT_PATH_NONE = ""
)
Variables ¶
This section is empty.
Functions ¶
func IsValidRole ¶
func OutputSummaryContent ¶
func OutputSummaryContent(output StreamReader, contentbuf *strings.Builder, delta string)
func OutputSummaryError ¶
func OutputSummaryError(output StreamReader, contentbuf *strings.Builder, status LLMStatus, errstr string)
Types ¶
type Agent ¶
type Agent struct {
Prompts []*PromptItem
Request string
Context context.Context
Input *Input
Output *Output
LongHistoryMessages []ChatMessage
ShortHistoryMessages []ChatMessage
PromptMessages []ChatMessage
LLM LLM
Stream bool
ResponseStatus LLMStatus
ResponseMessage ChatMessage
ReflectionContent string
AgentStage AgentStage
CanDoAction bool
DoAction *DoAction
CanDoReflection bool
DoReflection *DoReflection
}
func (*Agent) AskReflection ¶
func (*Agent) GetLongHistory ¶
func (a *Agent) GetLongHistory() []ChatMessage
func (*Agent) GetShortHistory ¶
func (a *Agent) GetShortHistory() []ChatMessage
func (*Agent) Prompt ¶
func (a *Agent) Prompt(prompts ...*PromptItem) *Agent
func (*Agent) ReadQuestion ¶
func (*Agent) Reflection ¶
func (a *Agent) Reflection(doRef *DoReflection, retry int) *Agent
func (*Agent) StreamDelta ¶ added in v0.0.12
func (*Agent) StreamError ¶ added in v0.0.12
func (*Agent) StreamStart ¶ added in v0.0.12
func (*Agent) Summarize ¶
func (a *Agent) Summarize(cxt context.Context, summary *PromptItem, prefix *PromptItem, force bool) *Agent
type AgentStage ¶
type AgentStage int
const ( AsReadQuestion AgentStage = iota AsAskLLM AsAskReflection AsWaitResponse AsAction AsReflection AsSummarize )
type ChatMessage ¶
func (*ChatMessage) String ¶
func (cm *ChatMessage) String() string
type Chunk ¶
type Chunk interface {
GetIndex() int
SetIndex(index int)
GetPath() string
SetPath(path string)
GetQuery() string
SetQuery(query string)
GetByteStart() int
SetByteStart(i int)
GetByteEnd() int
SetByteEnd(i int)
GetContent() string
SetContent(content string)
GetPayload() interface{}
SetPayload(payload interface{})
GetEmbedding() Embedding
SetEmbedding(embed Embedding)
}
type DoReflection ¶
type EmbeddingModel ¶
type EmbeddingStage ¶ added in v0.0.10
type EmbeddingStage int
const ( EmbeddingStageIndexing EmbeddingStage = iota EmbeddingStageRetrieval )
type LLM ¶
type LLM interface {
InitLLM() error
CalcTokens(cxt context.Context, content string) int
SendMessages(cxt context.Context, msgs []ChatMessage) (LLMStatus, ChatMessage)
SendMessagesStream(cxt context.Context, msgs []ChatMessage, reader StreamReader) (LLMStatus, ChatMessage)
CalcTokensByWeakModel(cxt context.Context, content string) int
SendMessagesByWeakModel(cxt context.Context, msgs []ChatMessage) (LLMStatus, ChatMessage)
SendMessagesStreamByWeakModel(cxt context.Context, msgs []ChatMessage, reader StreamReader) (LLMStatus, ChatMessage)
}
type Output ¶
type Output struct {
WriteContent func(stage AgentStage, stream StreamStage, buf *strings.Builder, str string)
}
type ParserFunction ¶
type PromptItem ¶
type Rag ¶
type Rag struct {
Database Database
EmbeddingModel EmbeddingModel
EmbeddingBatch int
EmbeddingRoutines int
EmbeddingDimensions int
EmbeddingCallback func(stage EmbeddingStage, texts []string, embeds []Embedding, i, j int, finished, tried int, err error) bool
}
func (*Rag) Embeddings ¶
type ScoredChunk ¶
type ScoredChunks ¶
type ScoredChunks []*ScoredChunk
type Splitter ¶
type Splitter interface {
GetParser() ParserFunction
}
type StreamReader ¶
type StreamStage ¶ added in v0.0.12
type StreamStage int
const ( StreamStageStart StreamStage = iota StreamStageDelta StreamStageError StreamStageEnd )
type Summary ¶
type Summary struct {
Cxt context.Context
StreamReader StreamReader
StreamBuffer *strings.Builder
LLM LLM
PromptSummary string
PromptPrefix string
DisableStream bool
MinSummaryTokens int
MinSplit int
MaxDepth int
}
func (*Summary) AskLLM ¶
func (s *Summary) AskLLM(msgs []ChatMessage) (LLMStatus, ChatMessage)
func (*Summary) InitSummary ¶
func (*Summary) Summarize ¶
func (s *Summary) Summarize(longHistory []ChatMessage, shortHistory []ChatMessage, force bool) (LLMStatus, []ChatMessage)
func (*Summary) SummarizeOnce ¶
func (s *Summary) SummarizeOnce(msgs []ChatMessage) (LLMStatus, []ChatMessage)
func (*Summary) SummarizeSplit ¶
func (s *Summary) SummarizeSplit(force bool, msgs []ChatMessage, depth int) (LLMStatus, []ChatMessage)
func (*Summary) TokenizeMessages ¶
func (s *Summary) TokenizeMessages(messages []ChatMessage) ([]TokenizedMessage, int)
type TokenizedMessage ¶
type TokenizedMessage struct {
Tokens int
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.