locatr

package
v0.42.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const CHUNK_SIZE = 4000

CHUNK_SIZE is the maximum size of a html chunk

View Source
const DEFAULT_CACHE_PATH = ".locatr.cache"

Default cache path

View Source
const DEFAULT_LOCATR_RESULTS_PATH = "locatr_results.json"

Default file to write locatr results

View Source
const LOCATR_PROMPT = `` /* 1530-byte string literal not displayed */
View Source
const MAX_CHUNKS_EACH_RERANK_ITERATION = 4
View Source
const MAX_RETRIES_WITH_RERANK = 3

Variables

View Source
var (
	ErrUnableToMinifyHtmlDom            = errors.New("unable to minify HTML DOM")
	ErrUnableToExtractIdLocatorMap      = errors.New("unable to extract ID locator map")
	ErrUnableToLocateElementId          = errors.New("unable to locate element ID")
	ErrInvalidElementIdGenerated        = errors.New("invalid element ID generated")
	ErrUnableToFindValidLocator         = errors.New("unable to find valid locator")
	ErrFailedToWriteCache               = errors.New("failed to write cache")
	ErrFailedToMarshalJson              = errors.New("failed to marshal json")
	ErrLocatrCacheMiss                  = errors.New("cache miss")
	ErrLocatrRetrievalAttemptsExhausted = errors.New("failed to retrieve locatr after 3 attempts")
	ErrLocatrRetrievalFailed            = errors.New("failed to retieve locatr")
	ErrNoChunksToProcess                = errors.New("got no chunks to process after reranking")
	ErrFailedToRepariJson               = errors.New("failed to repair json")
)
View Source
var HTML_MINIFIER_JS_CONTENT string
View Source
var HTML_SEPARATORS = []string{
	"<body",
	"<div",
	"<p",
	"<br",
	"<li",
	"<h1",
	"<h2",
	"<h3",
	"<h4",
	"<h5",
	"<h6",
	"<span",
	"<table",
	"<tr",
	"<td",
	"<th",
	"<ul",
	"<ol",
	"<header",
	"<footer",
	"<nav",
	"<head",
	"<style",
	"<script",
	"<meta",
	"<title",
	"",
}

HTML_SEPARATORS used by html chunk splitter

Functions

This section is empty.

Types

type BaseLocatr

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

func NewBaseLocatr

func NewBaseLocatr(plugin PluginInterface, options BaseLocatrOptions) *BaseLocatr

NewBaseLocatr creates a new instance of BaseLocatr plugin: (playwright, puppeteer, etc) llmClient: struct that are returned by NewLlmClient options: All the options for the locatr package

func (*BaseLocatr) GetLocatorStr

func (l *BaseLocatr) GetLocatorStr(userReq string) (*LocatrOutput, error)

GetLocatorStr returns the locator string for the given user request

func (*BaseLocatr) GetLocatrResults

func (l *BaseLocatr) GetLocatrResults() []LocatrResult

func (*BaseLocatr) WriteLocatrResultsToFile

func (l *BaseLocatr) WriteLocatrResultsToFile()

type BaseLocatrOptions

type BaseLocatrOptions struct {
	// CachePath is the path to the cache file
	CachePath string
	// UseCache is a flag to enable/disable cache
	UseCache bool

	// LocatrResultsFilePath is the path to the file where the locatr results will be written
	// If not provided, the results will be written to DEFAULT_LOCATR_RESULTS_FILE
	ResultsFilePath string

	// LLmClient is the client to interact with LLM
	LlmClient llm.LlmClientInterface

	// ReRankClient is the client to interact with ReRank
	ReRankClient reranker.ReRankInterface
}

BaseLocatrOptions is a struct that holds all the options for the locatr package

type LocatrInterface

type LocatrInterface interface {
	WriteResultsToFile()
	GetLocatrResults() []LocatrResult
	GetLocatrStr(userReq string) (*LocatrOutput, error)
}

type LocatrOutput

type LocatrOutput struct {
	SelectorType SelectorType `json:"selector_type"`
	Selectors    []string     `json:"selector"`
}

type LocatrResult

type LocatrResult struct {
	LocatrDescription        string       `json:"locatr_description"`
	Url                      string       `json:"url"`
	CacheHit                 bool         `json:"cache_hit"`
	InputTokens              int          `json:"input_tokens"`
	OutputTokens             int          `json:"output_tokens"`
	TotalTokens              int          `json:"total_tokens"`
	LlmErrorMessage          string       `json:"llm_error_message"`
	ChatCompletionTimeTaken  int          `json:"llm_locatr_generation_time_taken"`
	AttemptNo                int          `json:"attempt_no"`
	LocatrRequestInitiatedAt time.Time    `json:"request_initiated_at"`
	LocatrRequestCompletedAt time.Time    `json:"request_completed_at"`
	AllLocatrs               []string     `json:"all_locatrs"`
	SelectorType             SelectorType `json:"selector_type"`
}

func (*LocatrResult) MarshalJSON

func (l *LocatrResult) MarshalJSON() ([]byte, error)

type PluginInterface

type PluginInterface interface {
	GetMinifiedDomAndLocatorMap() (
		*elementSpec.ElementSpec,
		*elementSpec.IdToLocatorMap,
		SelectorType,
		error,
	)
	GetCurrentContext() string
	IsValidLocator(locatr string) (bool, error)
}

type SelectorType

type SelectorType string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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