Class: Mistri::Providers::Gemini
- Inherits:
-
Object
- Object
- Mistri::Providers::Gemini
- Defined in:
- lib/mistri/providers/gemini.rb,
lib/mistri/providers/gemini/assembler.rb,
lib/mistri/providers/gemini/serializer.rb
Overview
The Gemini API (v1beta generateContent), streamed over SSE and stateless: the full history replays every turn.
Thinking is deliberately unconstrained: no budget, no level, only includeThoughts so summaries stream for the UI. The model's own defaults decide how much to think, and a host override passes through verbatim. maxOutputTokens is omitted for the same reason: the API defaults to the model's ceiling.
Defined Under Namespace
Modules: Serializer Classes: Assembler
Constant Summary collapse
- DEFAULT_THINKING =
{ includeThoughts: true }.freeze
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(api_key:, model: "gemini-2.5-flash", origin: "https://generativelanguage.googleapis.com", thinking: DEFAULT_THINKING, **transport_options) ⇒ Gemini
constructor
A new instance of Gemini.
- #stream(messages:, system: nil, tools: [], signal: nil, **overrides, &emit) ⇒ Object
Constructor Details
#initialize(api_key:, model: "gemini-2.5-flash", origin: "https://generativelanguage.googleapis.com", thinking: DEFAULT_THINKING, **transport_options) ⇒ Gemini
Returns a new instance of Gemini.
16 17 18 19 20 21 22 23 |
# File 'lib/mistri/providers/gemini.rb', line 16 def initialize(api_key:, model: "gemini-2.5-flash", origin: "https://generativelanguage.googleapis.com", thinking: DEFAULT_THINKING, **) @api_key = api_key @model = model @thinking = thinking @transport = Transport.new(origin: origin, **) end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
25 26 27 |
# File 'lib/mistri/providers/gemini.rb', line 25 def model @model end |
Instance Method Details
#close ⇒ Object
42 |
# File 'lib/mistri/providers/gemini.rb', line 42 def close = @transport.close |
#stream(messages:, system: nil, tools: [], signal: nil, **overrides, &emit) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mistri/providers/gemini.rb', line 27 def stream(messages:, system: nil, tools: [], signal: nil, **overrides, &emit) model = overrides.fetch(:model, @model) assembler = Gemini::Assembler.new(model: model) body = build_body(, system, tools, overrides) path = "/v1beta/models/#{model}:streamGenerateContent?alt=sse" outcome = @transport.stream_post(path, body: body, headers: headers, signal: signal) do |record| assembler.feed(record, &emit) end outcome == :aborted ? assembler.abort(&emit) : assembler.finish(&emit) rescue Error => e assembler.fail_stream(e, &emit) end |