completion

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 7 Imported by: 0

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