Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrProviderNotFound = errors.New("provider not found")
ErrProviderNotFound indicates missing provider registration.
Functions ¶
func Complete ¶
func Complete(goCtx context.Context, model ai.Model, ctx ai.Context, opts ai.CompleteOptions, providers ProviderGetter) (ai.AssistantMessage, error)
Complete consumes a full stream and assembles an assistant message.
Types ¶
type AssistantEventStream ¶
type AssistantEventStream interface {
Events() <-chan ai.AssistantEvent
Close() error
Wait() error
}
AssistantEventStream provides ordered assistant events.
func Stream ¶
func Stream(goCtx context.Context, model ai.Model, ctx ai.Context, opts ai.StreamOptions, providers ProviderGetter) (AssistantEventStream, error)
Stream dispatches request to the registered API provider.
func StreamSimple ¶
func StreamSimple(goCtx context.Context, model ai.Model, ctx ai.Context, opts ai.SimpleStreamOptions, providers ProviderGetter) (AssistantEventStream, error)
StreamSimple dispatches simplified streaming to provider.
type ChannelEventStream ¶
type ChannelEventStream struct {
// contains filtered or unexported fields
}
ChannelEventStream is a channel-backed AssistantEventStream.
Producers call Emit to send events, then Finish to close the stream and record any terminal error. Consumers range over Events() and then call Wait() to retrieve the terminal error.
Close vs Finish: Finish is the normal shutdown path — it stores the error and closes the channel. Close is for consumer-side cancellation — it closes the channel without storing an error. If Close races with Finish, the first caller wins (via sync.Once) and Wait() returns whatever error was stored before the channel closed.
func NewChannelEventStream ¶
func NewChannelEventStream(buffer int) *ChannelEventStream
NewChannelEventStream returns a writable channel stream.
func (*ChannelEventStream) Close ¶
func (s *ChannelEventStream) Close() error
Close closes the event stream from the consumer side without recording an error. After Close, any pending Emit calls will panic (closed channel). If Finish was called first, Close is a no-op. If Close is called first, Finish still records the error for Wait() but does not re-close the channel.
func (*ChannelEventStream) Emit ¶
func (s *ChannelEventStream) Emit(event ai.AssistantEvent)
Emit sends one event to subscribers.
func (*ChannelEventStream) Events ¶
func (s *ChannelEventStream) Events() <-chan ai.AssistantEvent
Events returns read-only event channel.
func (*ChannelEventStream) Finish ¶
func (s *ChannelEventStream) Finish(err error)
Finish closes the event stream and records the terminal error. After Finish, Wait() returns err and Events() is drained. Safe to call concurrently with Close — first caller wins the channel close.
func (*ChannelEventStream) Wait ¶
func (s *ChannelEventStream) Wait() error
Wait returns terminal stream error.
type ModelLister ¶
ModelLister is an optional interface providers can implement to list available models.
type ProviderAdapter ¶
type ProviderAdapter interface {
API() string
Stream(goCtx context.Context, model ai.Model, ctx ai.Context, opts ai.StreamOptions) (AssistantEventStream, error)
StreamSimple(goCtx context.Context, model ai.Model, ctx ai.Context, opts ai.SimpleStreamOptions) (AssistantEventStream, error)
}
ProviderAdapter defines the provider adapter contract.
type ProviderGetter ¶
type ProviderGetter interface {
Get(api string) (ProviderAdapter, bool)
}
ProviderGetter provides provider lookup.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry stores providers by API name.
func DefaultRegistry ¶
func DefaultRegistry() *Registry
DefaultRegistry returns the process-wide provider registry singleton.
func (*Registry) Get ¶
func (r *Registry) Get(api string) (ProviderAdapter, bool)
Get resolves a provider by API key.
func (*Registry) Register ¶
func (r *Registry) Register(provider ProviderAdapter)
Register stores a provider by API key.