brain

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEchoServer added in v0.2.0

func NewEchoServer(t *testing.T, expectedModel, expectedToken string) *httptest.Server

NewEchoServer creates a test server that echoes back the user message

func NewErrorServer added in v0.2.0

func NewErrorServer(t *testing.T) *httptest.Server

NewErrorServer creates a test server that returns an error response

Types

type Brain

type Brain interface {
	Ask(question string) (string, error)
}

Brain represents an interface for asking questions and receiving answers.

func New

func New(provider, url, token, model, system string, playbook ...string) (Brain, error)

New creates a new instance of Brain based on the provided provider and optional playbook strings.

func NewCustom added in v0.3.5

func NewCustom(token, url, model, system string) (Brain, error)

func NewDeepSeek

func NewDeepSeek(apiKey, _ string) Brain

NewDeepSeek creates a new deepSeek instance with the provided API key.

func NewMetricBrain added in v0.2.0

func NewMetricBrain(brain Brain, s *stats.Stats) Brain

NewMetricBrain creates a new MetricBrain instance wrapping the given Brain and using the provided stats for writing statistics.

func NewMock

func NewMock(playbooks ...string) Brain

NewMock creates a new instance of MockBrain with the provided playbooks. If no playbooks are provided, a default echo playbook will be used.

func NewOllama added in v0.3.4

func NewOllama(address, model, token, system string) Brain

NewOllama creates a new instance of the Brain implementation using the Ollama API.

Parameters:

  • address (string): The base URL of the Ollama API.
  • model (string): The AI model to use for chat interactions.
  • token (string): The authentication token for accessing the API.
  • system (string): The initial system prompt or context for the AI model.

Returns:

  • Brain: An instance of the Brain interface configured to use the Ollama API.

func NewOpenAI added in v0.2.0

func NewOpenAI(token, url, model, system string) (Brain, error)

NewOpenAI creates a new OpenAI instance with the provided settings

func NewOpenAIDefault added in v0.3.5

func NewOpenAIDefault(token, system string) (Brain, error)

NewOpenAIDefault creates a new OpenAI instance with default settings

type EchoPlaybook added in v0.2.0

type EchoPlaybook struct{}

EchoPlaybook represents a playbook that echoes back the question asked.

func NewEchoPlaybook added in v0.2.0

func NewEchoPlaybook() *EchoPlaybook

NewEchoPlaybook creates a new instance of EchoPlaybook.

func (*EchoPlaybook) Ask added in v0.2.0

func (e *EchoPlaybook) Ask(question string) string

Ask echoes back the provided question.

type MetricBrain added in v0.2.0

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

MetricBrain is a wrapper around a Brain with added functionality to track metrics such as the duration of each question asked.

func (*MetricBrain) Ask added in v0.2.0

func (b *MetricBrain) Ask(question string) (string, error)

Ask sends a question to the underlying Brain and tracks the time taken to process the question.

type Playbook added in v0.2.0

type Playbook interface {
	Ask(question string) string
}

Playbook defines the interface for a playbook that can ask questions and return answers. It is used in tests mostly.

type YAMLPlaybook added in v0.2.0

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

YAMLPlaybook represents a playbook loaded from a YAML file.

func NewYAMLPlaybook added in v0.2.0

func NewYAMLPlaybook(filePath string) (*YAMLPlaybook, error)

NewYAMLPlaybook loads a YAML playbook from the specified file path and returns a YAMLPlaybook instance.

func (*YAMLPlaybook) Ask added in v0.2.0

func (p *YAMLPlaybook) Ask(question string) string

Ask retrieves the answer to a given question from the playbook. If the question is not found, it returns a default "not found" message.

Jump to

Keyboard shortcuts

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