completion

package
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package completion provides the typed runtime contract for service-owned direct assistant completions. Generated completion packages expose typed specs that this package uses to request provider-enforced structured output and decode the final assistant response through generated codecs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeChunk

func DecodeChunk[T any](chunk model.Chunk, spec Spec[T]) (T, bool, error)

DecodeChunk decodes the canonical final completion chunk from a typed completion stream. Non-completion chunks are ignored and return ok=false.

func DecodeResponse

func DecodeResponse[T any](resp *model.Response, spec Spec[T]) (T, error)

DecodeResponse decodes the structured assistant response with the generated typed codec from the completion spec.

func Stream

func Stream[T any](ctx context.Context, client model.Client, req *model.Request, spec Spec[T]) (model.Streamer, error)

Stream starts a typed completion stream using the provided generated spec.

Streaming completions reuse the provider-neutral model.Streamer contract. The final typed value is decoded from the canonical ChunkTypeCompletion payload; completion deltas are preview-only and may be ignored.

Types

type Ident

type Ident string

Ident is the stable identifier for a generated completion contract.

type Response

type Response[T any] struct {
	// Value is the decoded typed completion result.
	Value T
	// Raw is the original provider-agnostic model response.
	Raw *model.Response
}

Response contains the raw model response plus the decoded typed value.

func Complete

func Complete[T any](ctx context.Context, client model.Client, req *model.Request, spec Spec[T]) (*Response[T], error)

Complete runs a unary typed completion using the provided generated spec.

type Spec

type Spec[T any] struct {
	// Name is the stable completion identifier declared in the DSL.
	Name Ident
	// Description provides human-readable context about the completion.
	Description string
	// Result describes the generated result schema and generic codec.
	Result tools.TypeSpec
	// Codec is the generated typed codec for the completion result.
	Codec tools.JSONCodec[T]
}

Spec describes one generated typed completion contract.

Jump to

Keyboard shortcuts

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