hallucinator

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2025 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BackToStartString = "Back to start."
	ContinueString    = "Continue reading..."
	Dream404String    = "Error 404: Article not found."
	DreamString       = "We are sorry, but the requested article could be not found!"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Hallucination

type Hallucination struct {
	Text         string
	Prompt       string
	RequestCount int
}

Hallucination is a hallucination generated by the Hallucinator.

type Hallucinator

type Hallucinator struct {
	Interval time.Duration

	HTTPClient httpClient

	Logger *slog.Logger
	// contains filtered or unexported fields
}

Hallucinator is the structure for the Hallucinator.

func NewHallucinator

func NewHallucinator(ctx context.Context, logger *slog.Logger,
	interval time.Duration,
	hallucinationCacheSize int,
	hallucinatorPromptWordCount int,
	hallucinationRequestCount int,
	hallucinationMinimalLength int,
	hallucinationWordCount int,
	hallucinationLinkPercentage int,
	hallucinatorLinkMaxSubdirectories int,
	hallucinatorLinkHasVariablesProbability float64,
	hallucinatorLinkMaxVariables int,
	hallucinatorURL url.URL,
	ollamaAddress string,
	ollamaModel string,
	ollamaRequestTimeOut time.Duration,
	aiTemperature float64,
	aiSeed int,
	statistics *statistics.Statistics,
) *Hallucinator

NewHallucinator creates a new Hallucinator instance.

func (*Hallucinator) AppendHallucination added in v0.3.2

func (h *Hallucinator) AppendHallucination(ctx context.Context, hallucination Hallucination)

AppendHallucination appends a hallucination to the list of hallucinations.

func (*Hallucinator) CleanHallucinations added in v0.3.2

func (h *Hallucinator) CleanHallucinations(ctx context.Context)

CleanHallucinations cleans the list of hallucinations and removes hallucinations with requestCount 0.

func (*Hallucinator) DecreaseHallucinationRequestCount

func (h *Hallucinator) DecreaseHallucinationRequestCount(ctx context.Context, id int)

DecreaseHallucinationRequestCount decreases the request count of a hallucination by 1.

func (*Hallucinator) GenerateHallucination added in v0.3.2

func (h *Hallucinator) GenerateHallucination(ctx context.Context) (Hallucination, error)

GenerateHallucination generates a hallucination from the Ollama API.

func (*Hallucinator) GetHallucinationCount

func (h *Hallucinator) GetHallucinationCount(ctx context.Context) int

GetHallucinationCount returns the current hallucination count.

func (*Hallucinator) PopHallucination

func (h *Hallucinator) PopHallucination(ctx context.Context) string

PopHallucination withdraws the first hallucination from the list of hallucinations.

func (*Hallucinator) PopRandomHallucination

func (h *Hallucinator) PopRandomHallucination(ctx context.Context) string

PopRandomHallucination withdraws a random hallucination from the list of hallucinations.

func (*Hallucinator) Start

func (h *Hallucinator) Start(ctx context.Context) error

Start starts the Hallucinator.

type OllamaMessage

type OllamaMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

OllamaMessage is the message structure for the Ollama API.

type OllamaResponse

type OllamaResponse struct {
	Model           string        `json:"model"`
	CreatedAt       string        `json:"created_at"` //nolint: tagliatelle
	Message         OllamaMessage `json:"message"`
	Done            bool          `json:"done"`
	DoneReason      string        `json:"done_reason"`       //nolint: tagliatelle
	TotalDuration   int           `json:"total_duration"`    //nolint: tagliatelle
	LoadDuration    int           `json:"load_duration"`     //nolint: tagliatelle
	PromptEvalCount int           `json:"prompt_eval_count"` //nolint: tagliatelle
	EvalCount       int           `json:"eval_count"`        //nolint: tagliatelle
	EvalDuration    int           `json:"eval_duration"`     //nolint: tagliatelle
}

OllamaResponse is the response structure for the Ollama API.

Jump to

Keyboard shortcuts

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