The repository implements maragu.dev/gai, a Go library that standardises interactions with foundational and large language models. Core packages cover chat completions (chat_complete.go), embedding helpers (embed.go), reusable tools (tools/), and an evaluation harness (eval/). Example programs live under internal/examples to illustrate end-to-end usage with different backends.
- Top-level Go files expose the public API; keep additional exports minimal.
clients/holds provider integrations (openai,google,anthropic) that implementgai.ChatCompleter(all three) andgai.Embedder[T](openai, google); each subpackage has its own README.tools/packages convenience tools (time, exec, fetch, memory, file) with matching tests and JSON schemas.eval/provides the evaluation runner (run.go) that writes JSONL reports toevals.jsonl, plus built-in scorers ineval.gofor lexical similarity (Levenshtein, exact match, contains) and semantic similarity (cosine);eval/internal/evalsis an internal sample eval used to exercise the runner.robust/wrapsgai.ChatCompleterandgai.Embedder[T]with retry-and-fallback behaviour across multiple underlying implementations.internal/examples/contains runnable samples (evals,robust,robust_embed,tools,tools_custom) demonstrating library integration.docs/stores the static site (index.html,template.html); update it when the public API changes.docker-compose.yamlstarts a localllama32-1binference server on port 8090 for smoke testing chat flows.
- Default test command:
go test -shuffle on ./...ormake test(also updatescover.outforgo tool cover). - Use the
maragu.dev/isassertion helpers (is.NotError,is.Equal, etc.) and favour subtests with descriptive names. - Evaluations run via
go test -shuffle on -run TestEval ./...ormake evaluate; logs accumulate inevals.jsonl. - Benchmarks live alongside tests and run with
make benchmark. - Lint with
golangci-lint runormake lint; address warnings immediately to avoid CI regressions. - Client model constants are hand-curated (stable, generally-available, current and recent generations); the live
TestModelConformancein each client package enforces the set in both directions against its package-private ignore list.
- Stick to dependency injection through small private interfaces close to the consumer (see chat completer tools).
- Add tests for new behaviours; prefer integration-style tests when real dependencies are available.
- For tools, always provide schemas with
gai.GenerateToolSchemaand implement bothSummarizeandExecute. - Document exported identifiers in GoDoc style: start with the identifier name and write a full sentence.
- Avoid introducing new global exports without a clear need; favour package-private helpers inside existing packages.
- Public docs publish from
docs/index.html; rungo testbefore updating to ensure examples remain accurate. - Runnable samples live under
internal/examples/; reuse the subdir closest in shape (e.g.tools*,evals,robust*) as scaffolding for new samples. - When adding new make targets or scripts, update both
Makefileand this guide so future agents stay aligned.