Class: Mistri::Providers::OpenAI
- Inherits:
-
Object
- Object
- Mistri::Providers::OpenAI
- Defined in:
- lib/mistri/providers/openai.rb,
lib/mistri/providers/openai/assembler.rb,
lib/mistri/providers/openai/serializer.rb
Overview
The OpenAI Responses API, streamed and stateless: store is always false, the full history replays every turn, and encrypted reasoning items round trip through the signature slots so nothing depends on server-side state. Reasoning summaries stream as thinking. max_output_tokens is deliberately omitted: the API defaults to the model's own ceiling.
Provider failures fold into the stream as an error turn rather than raising, matching the Anthropic provider's contract.
Defined Under Namespace
Modules: Serializer Classes: Assembler
Constant Summary collapse
- DEFAULT_REASONING =
{ summary: "auto" }.freeze
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(api_key:, model: "gpt-5.5", origin: "https://api.openai.com", reasoning: DEFAULT_REASONING, **transport_options) ⇒ OpenAI
constructor
A new instance of OpenAI.
- #stream(messages:, system: nil, tools: [], signal: nil, **overrides, &emit) ⇒ Object
Constructor Details
#initialize(api_key:, model: "gpt-5.5", origin: "https://api.openai.com", reasoning: DEFAULT_REASONING, **transport_options) ⇒ OpenAI
Returns a new instance of OpenAI.
16 17 18 19 20 21 22 |
# File 'lib/mistri/providers/openai.rb', line 16 def initialize(api_key:, model: "gpt-5.5", origin: "https://api.openai.com", reasoning: DEFAULT_REASONING, **) @api_key = api_key @model = model @reasoning = reasoning @transport = Transport.new(origin: origin, **) end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
24 25 26 |
# File 'lib/mistri/providers/openai.rb', line 24 def model @model end |
Instance Method Details
#close ⇒ Object
41 |
# File 'lib/mistri/providers/openai.rb', line 41 def close = @transport.close |
#stream(messages:, system: nil, tools: [], signal: nil, **overrides, &emit) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mistri/providers/openai.rb', line 26 def stream(messages:, system: nil, tools: [], signal: nil, **overrides, &emit) model = overrides.fetch(:model, @model) assembler = OpenAI::Assembler.new(model: model) body = build_body(model, , system, tools, overrides) outcome = @transport.stream_post("/v1/responses", 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 |