parser

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ParseResult

type ParseResult struct {
	Type        string                 // "code", "action", "structured", "final_answer", "error"
	Thought     string                 // The reasoning/thought if present
	Content     string                 // The main content (code or action)
	Action      map[string]interface{} // Parsed action for tool calling
	Error       error                  // Any parsing error
	IsStreaming bool                   // Whether this is a streaming response
}

ParseResult represents the result of parsing an LLM response

type Parser

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

Parser handles parsing of LLM responses

func NewParser

func NewParser() *Parser

NewParser creates a new parser with default settings

func NewParserWithTags

func NewParserWithTags(openTag, closeTag string) *Parser

NewParserWithTags creates a new parser with custom code block tags

func (*Parser) ExtractAction

func (p *Parser) ExtractAction(text string) (map[string]interface{}, error)

ExtractAction extracts action JSON from text

func (*Parser) ExtractCode

func (p *Parser) ExtractCode(text string) string

ExtractCode extracts code from between code block tags

func (*Parser) ExtractError

func (p *Parser) ExtractError(text string) string

ExtractError extracts error message from text

func (*Parser) ExtractThought

func (p *Parser) ExtractThought(text string) string

ExtractThought extracts the thought/reasoning from text

func (*Parser) GetCodeBlockTags

func (p *Parser) GetCodeBlockTags() [2]string

GetCodeBlockTags returns the current code block tags

func (*Parser) IsFinalAnswer

func (p *Parser) IsFinalAnswer(result *ParseResult) bool

IsFinalAnswer checks if the parsed result is a final answer

func (*Parser) Parse

func (p *Parser) Parse(response string) *ParseResult

func (*Parser) ParseStructuredOutput

func (p *Parser) ParseStructuredOutput(text string) (map[string]interface{}, error)

ParseStructuredOutput parses a structured JSON response

type StreamParser

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

StreamParser handles parsing of streaming responses

func NewStreamParser

func NewStreamParser(parser *Parser) *StreamParser

NewStreamParser creates a new streaming parser

func (*StreamParser) ParseChunk

func (sp *StreamParser) ParseChunk(chunk string) *ParseResult

ParseChunk parses a streaming chunk

func (*StreamParser) Reset

func (sp *StreamParser) Reset()

Reset resets the stream parser

Jump to

Keyboard shortcuts

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