Documentation
¶
Overview ¶
Package interactions is a streaming LLM service backed by Google's Gemini Interactions API. It consumes an LLMContextFrame and emits the response as LLM response frames, like every other jargo LLM service.
It takes the same settings as the Gemini service (package gemini), and the two read each other's thought signatures from the conversation, so a conversation can move between them.
Each request carries the full conversation with store set to false, so Google keeps no copy of it. Sending only the new turns, with previous_interaction_id, would need store set to true, which retains every interaction on Google's servers for days; the Interactions API has no connection-local alternative like the OpenAI Responses WebSocket mode.
The Vertex AI variant is vertex.NewInteractionsLLM.
Index ¶
- type Config
- type LLMSettings
- type RequestShaper
- type SafetySetting
- type Service
- func (s *Service) Generate(ctx context.Context, convo *frames.LLMContext, emit llm.Emit) error
- func (s *Service) GenerateWithTools(ctx context.Context, convo *frames.LLMContext, sink llm.Sink) error
- func (s *Service) LLMAdapter() llm.BuiltinToolHolder
- func (s *Service) MessagesForLogging(convo *frames.LLMContext) []map[string]any
- func (s *Service) ModelSupportsResponseSchema(string) bool
- func (s *Service) RunInference(ctx context.Context, convo *frames.LLMContext, opts llm.InferenceOptions) (string, error)
- func (s *Service) Settings() any
- func (s *Service) SupportsResponseSchema() bool
- func (s *Service) ToolsForLogging(schema frames.ToolsSchema) []any
- type ThinkingConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// APIKey is the Gemini API key. Required.
APIKey string `validate:"required"`
// Model is the model id; empty uses a low-latency flash default.
Model string
// MaxTokens caps the response length; 0 uses 4096.
MaxTokens int
// Temperature is the sampling temperature (0.0 to 2.0); nil omits it.
Temperature *float64
// TopP is the nucleus-sampling parameter (0.0 to 1.0); nil omits it.
TopP *float64
// TopK is accepted for parity with the Gemini service, and ignored with a
// warning: the Interactions API has no top-k.
TopK *int
// SafetySettings are the content-safety filters, one per harm category.
// Empty sends none, leaving every category at the API's default.
SafetySettings []SafetySetting `validate:"omitempty,dive"`
// Thinking controls the model's internal reasoning: Level and
// IncludeThoughts apply, and a Budget is ignored. If it is nil, the service
// sends the lowest thinking level Google documents for the model, for the
// fastest responses, and logs what it sent. Models it does not list, and
// every model when the use_provider_thinking_default setting is set, run at
// Google's default.
Thinking *ThinkingConfig `validate:"omitempty"`
// Seed makes sampling repeatable; nil omits it.
Seed *int
// Tools are offered to the model when the conversation advertises none, in
// Gemini's generateContent format ({"function_declarations": [...]},
// {"google_search": {}}) or the Interactions API's ({"type": ...}).
Tools []map[string]any
// ToolConfig configures tool use, in Gemini's generateContent format
// ({"function_calling_config": {"mode": "ANY", "allowed_function_names":
// [...]}}). It is sent as the Interactions API's tool_choice.
ToolConfig map[string]any
// StreamIdleTimeout bounds how long to wait for the next event of a
// streamed response before giving up on it. It bounds the wait when the API
// accepts a request and then stops producing without closing the stream.
// Nil uses 20 seconds and a zero value waits indefinitely.
StreamIdleTimeout *time.Duration
// RetryOnTimeout re-issues the request once when its first event does not
// arrive within RetryTimeout.
RetryOnTimeout bool
// RetryTimeout is how long the first event is waited for before the request
// is re-issued; 0 uses 5 seconds. It applies only with RetryOnTimeout.
RetryTimeout time.Duration `validate:"omitempty,min=0"`
// Extra sets additional request fields not modeled above, applied to every
// request. A generation_config entry holding an object is merged into the
// generation configuration field by field; any other entry replaces the
// request field of its name.
Extra map[string]any
}
Config configures the Interactions LLM service. It holds the same settings as the Gemini service's, so a service's settings carry over between the two. The Interactions API has no top-k, frequency penalty or presence penalty, and controls thinking by level only; a setting it has no field for is ignored with a warning.
type LLMSettings ¶
type LLMSettings = gemini.LLMSettings
LLMSettings is the part of the configuration that can change while the pipeline runs, through an LLMUpdateSettingsFrame. They are the Gemini service's settings, so a service's settings carry over between the two Gemini services. Every request is built from them, so an update reaches the next request.
type RequestShaper ¶
type RequestShaper interface {
// Endpoint returns the URL interactions are created at.
Endpoint() string
// Authorize sets the authorization headers on req. It takes a context
// because a scheme may have to mint or refresh a token to do so.
Authorize(ctx context.Context, req *http.Request) error
}
RequestShaper says where an Interactions request is sent and how it is authorized, so a deployment with a different URL layout or auth scheme (Vertex AI, which addresses the API per project and location and authorizes with an OAuth token) can reuse this implementation. The default shaper targets the Gemini API with an api-key header.
type SafetySetting ¶
type SafetySetting = gemini.SafetySetting
SafetySetting is one content-safety filter, in the Gemini service's form. It is sent in the Interactions API's: HARM_CATEGORY_HARASSMENT becomes harassment, BLOCK_ONLY_HIGH becomes block_only_high, and so on.
type Service ¶
Service is a streaming Gemini LLM processor using the Interactions API.
func NewShapedLLM ¶
func NewShapedLLM(name string, shaper RequestShaper, cfg Config) *Service
NewShapedLLM builds an Interactions LLM service whose requests are addressed and authorized by shaper. It is the base for deployments that do not use the Gemini API's own URL or api-key auth; name is the processor label.
func (*Service) Generate ¶
Generate streams a response to the conversation, emitting each text delta. The conversation advertises no tools, but the service's own may still be offered, and the calls the model makes to them are run.
func (*Service) GenerateWithTools ¶
func (s *Service) GenerateWithTools(ctx context.Context, convo *frames.LLMContext, sink llm.Sink) error
GenerateWithTools streams a tool-capable response, emitting text deltas to the sink as they arrive and reporting each function call the model made once the response is complete.
func (*Service) LLMAdapter ¶
func (s *Service) LLMAdapter() llm.BuiltinToolHolder
LLMAdapter returns the adapter this service converts through, so the base can add the tools it implements itself to what every request advertises. It implements llm.AdapterHolder.
func (*Service) MessagesForLogging ¶
func (s *Service) MessagesForLogging(convo *frames.LLMContext) []map[string]any
MessagesForLogging renders the conversation as this provider will see it, for the generation span. It implements llm.TraceRenderer.
func (*Service) ModelSupportsResponseSchema ¶
ModelSupportsResponseSchema implements llm.ResponseSchemaSupporter: every model the Interactions API serves can enforce a response schema.
func (*Service) RunInference ¶
func (s *Service) RunInference( ctx context.Context, convo *frames.LLMContext, opts llm.InferenceOptions, ) (string, error)
RunInference answers the conversation once, off to the side of the pipeline: no streaming, no frames, just the text. It implements llm.Inferencer.
func (*Service) Settings ¶
Settings returns the service's runtime-updatable settings, implementing llm.SettingsHolder.
func (*Service) SupportsResponseSchema ¶
SupportsResponseSchema implements llm.ResponseSchemaSupporter.
func (*Service) ToolsForLogging ¶
func (s *Service) ToolsForLogging(schema frames.ToolsSchema) []any
ToolsForLogging renders the toolset as this provider will see it, for the generation span. It implements llm.TraceRenderer.
type ThinkingConfig ¶
type ThinkingConfig = gemini.ThinkingConfig
ThinkingConfig controls the model's internal reasoning. The Interactions API controls thinking by level only: Level and IncludeThoughts apply, and a Budget is ignored with a warning.