chat

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 13 Imported by: 0

README

Chat (go-tool-base adapter)

This package is go-tool-base's thin adapter over the standalone multi-provider AI chat client, gitlab.com/phpboyscout/go/chat.

The client itself — the ChatClient API, ReAct tool-calling loop, streaming, cross-provider fallback, persistence, and multimodal input — lives in the module and its per-provider modules (chat-anthropic, chat-openai, chat-gemini). Full docs: chat.go.phpboyscout.uk.

This adapter adds go-tool-base's framework integration:

  • SettingsFromProps / NewFromProps / NewWithFallbackFromProps — map a Props instance and GTB's Viper config into the module's typed Settings.
  • the GTB config-key schema (ConfigKeyClaudeKey, ConfigKeyAIProvider, …) and the credential-resolution precedence.
  • the hardened pkg/http transport and pkg/credentials keychain lookup, injected into the module via its seams.
  • blank-imports of all three provider modules, so every provider is registered.

It also re-exports the module's public types/constructors (chat.Config, chat.New, chat.Tool, …) so existing GTB call sites reference them from this package unchanged. See docs/explanation/components/chat/index.md and the migration note at docs/reference/migration/v0.x-chat-extracted.md.

Documentation

Overview

Package chat is go-tool-base's framework-integration layer over the standalone multi-provider chat client gitlab.com/phpboyscout/go/chat.

It maps GTB's Props/Viper configuration into the module's typed Settings (see config_adapter.go via SettingsFromProps, NewFromProps and NewWithFallbackFromProps), owns the GTB config-key schema (see constants.go), and blank-imports every provider module (see providers.go) so each provider registers itself. The adapter names go/chat types (chat.Config, chat.New, …) directly; they are no longer re-exported from this package.

Code that wants the pure chat client API without the GTB config container imports gitlab.com/phpboyscout/go/chat directly.

Index

Constants

View Source
const (
	ConfigKeyOpenAIKey      = configRootOpenAI + ".key"
	ConfigKeyOpenAIEnv      = configRootOpenAI + ".env"
	ConfigKeyOpenAIKeychain = configRootOpenAI + ".keychain"
	EnvOpenAIKey            = "OPENAI_API_KEY"

	ConfigKeyClaudeKey      = configRootClaude + ".key"
	ConfigKeyClaudeEnv      = configRootClaude + ".env"
	ConfigKeyClaudeKeychain = configRootClaude + ".keychain"
	EnvClaudeKey            = "ANTHROPIC_API_KEY"

	ConfigKeyGeminiKey      = configRootGemini + ".key"
	ConfigKeyGeminiEnv      = configRootGemini + ".env"
	ConfigKeyGeminiKeychain = configRootGemini + ".keychain"
	EnvGeminiKey            = "GEMINI_API_KEY"
)

Per-provider credential config keys.

  • ConfigKey<Provider>Key — full config path for the literal API key.
  • ConfigKey<Provider>Env — full config path for an env-var reference (the value stored is the NAME of an env var holding the secret).
  • ConfigKey<Provider>Keychain — full config path for an OS-keychain reference.
  • Env<Provider>Key — well-known unprefixed environment variable used as the ecosystem fallback when no config is present.
View Source
const ConfigKeyAIProvider = "ai.provider"

ConfigKeyAIProvider is the config key for the AI provider.

View Source
const ConfigKeyAIRequestTimeout = "ai.request_timeout"

ConfigKeyAIRequestTimeout is the config key for the per-request AI timeout (a duration like "8m"). Overrides DefaultChatRequestTimeout.

View Source
const EnvAIProvider = "AI_PROVIDER"

EnvAIProvider is the environment variable for overriding the AI provider.

Variables

This section is empty.

Functions

func NewFromProps added in v0.30.0

func NewFromProps(ctx context.Context, p *props.Props, cfg gochat.Config) (gochat.ChatClient, error)

NewFromProps adapts GTB props into typed chat settings, then constructs a provider client with the reusable package constructor.

func NewWithFallback added in v0.22.0

func NewWithFallback(ctx context.Context, p *props.Props, cfg gochat.Config, opts ...gochat.FallbackOption) (gochat.ChatClient, error)

NewWithFallback adapts GTB props and framework config before constructing a chat client with optional provider failover.

func NewWithFallbackFromProps added in v0.30.0

func NewWithFallbackFromProps(ctx context.Context, p *props.Props, cfg gochat.Config, opts ...gochat.FallbackOption) (gochat.ChatClient, error)

NewWithFallbackFromProps adapts GTB props into package-owned chat settings, then constructs either a single provider client or a fallback composite.

func SettingsFromProps added in v0.30.0

func SettingsFromProps(p *props.Props, cfg gochat.Config) (gochat.Settings, error)

SettingsFromProps adapts GTB props and framework config into package-owned chat settings while preserving the existing config key layout and precedence.

Types

This section is empty.

Jump to

Keyboard shortcuts

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