chat

package
v0.41.2 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 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 ProviderModule added in v0.41.0

func ProviderModule(provider gochat.Provider) (string, bool)

ProviderModule returns the module path whose blank import registers the provider, and reports whether the provider is one this adapter knows.

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

type ProviderModuleEntry added in v0.41.0

type ProviderModuleEntry struct {
	Provider gochat.Provider
	Module   string
}

ProviderModuleEntry pairs a chat provider with the module whose blank import registers it.

func ProviderModules added in v0.41.0

func ProviderModules() []ProviderModuleEntry

ProviderModules returns every provider this adapter knows with its module, in a stable order.

Jump to

Keyboard shortcuts

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