Documentation
¶
Overview ¶
Package chattest provides a scripted Client for testing users of chat.Client, plus a stream contract checker.
Index ¶
- Constants
- func CheckFileInput(t *testing.T, client FileClient)
- func CheckMediaInput(t *testing.T, client chat.Client)
- func CheckStream(events []chat.Event) error
- func EnvKey(t testing.TB, envVar, yamlKey string) string
- func LookupKey(envVar, yamlKey string) string
- func Record(events iter.Seq[chat.Event]) []chat.Event
- func TextPDF(line string) []byte
- type Client
- type FileClient
- type Script
Constants ¶
const SampleImageURL = "https://raw.githubusercontent.com/github/explore/main/topics/go/go.png"
SampleImageURL is a public image (the Go logo) for testing URL media input. Whether a provider can fetch it is up to the provider: some sites reject them via robots.txt or access rules, so verify every provider when changing it.
Variables ¶
This section is empty.
Functions ¶
func CheckFileInput ¶ added in v0.2.1
func CheckFileInput(t *testing.T, client FileClient)
CheckFileInput uploads a PDF, has the model read it by reference, and deletes it.
func CheckMediaInput ¶
CheckMediaInput tests media input against a real model: a URL image and an inline PDF go in with the user message, then a tool result returns another PDF. Both answers are logged and checked.
func CheckStream ¶
CheckStream checks that an event sequence honors the chat.Client stream contract, for provider contract tests.
func EnvKey ¶
EnvKey reads a key for integration tests: first the environment variable envVar, then yamlKey in an env.yaml found in the current or a parent directory. It skips the test when neither exists. env.yaml is a local file ignored by git.
func LookupKey ¶
LookupKey finds a key with the same rules as EnvKey, returning an empty string when not found.
Types ¶
type Client ¶
type Client struct {
Model chat.ModelInfo
Scripts []Script
// contains filtered or unexported fields
}
Client is a chat.Client that runs scripts in order and records the requests it receives.
func NewClient ¶
NewClient creates a Client that runs scripts in order. Once the scripts run out, later calls produce an empty reply.
type FileClient ¶ added in v0.2.1
type FileClient interface {
chat.Client
UploadFile(ctx context.Context, name, mimeType string, r io.Reader, ttl time.Duration) (chat.ContentBlock, error)
DeleteFile(ctx context.Context, id string) error
}
FileClient is a chat.Client with a file store, as the providers implement it.
type Script ¶
Script describes what one model call produces. If the script returns without a terminal event, Done is emitted.