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_ORIGIN =
"https://api.openai.com"- 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: DEFAULT_ORIGIN, reasoning: DEFAULT_REASONING, service_tier: nil, catalog_pricing: nil, **transport_options) ⇒ OpenAI
constructor
A new instance of OpenAI.
- #native_output_schema(schema) ⇒ Object
- #prices_usage? ⇒ Boolean
- #stream(messages:, system: nil, tools: [], signal: nil, **overrides, &emit) ⇒ Object
Constructor Details
#initialize(api_key:, model: "gpt-5.5", origin: DEFAULT_ORIGIN, reasoning: DEFAULT_REASONING, service_tier: nil, catalog_pricing: nil, **transport_options) ⇒ OpenAI
Returns a new instance of OpenAI.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mistri/providers/openai.rb', line 19 def initialize(api_key:, model: "gpt-5.5", origin: DEFAULT_ORIGIN, reasoning: DEFAULT_REASONING, service_tier: nil, catalog_pricing: nil, **) @api_key = api_key @model = model @reasoning = reasoning @service_tier = service_tier @catalog_pricing = catalog_pricing.nil? ? official_origin?(origin) : catalog_pricing @transport = Transport.new(origin: origin, **) end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
30 31 32 |
# File 'lib/mistri/providers/openai.rb', line 30 def model @model end |
Instance Method Details
#close ⇒ Object
61 |
# File 'lib/mistri/providers/openai.rb', line 61 def close = @transport.close |
#native_output_schema(schema) ⇒ Object
36 37 38 39 40 |
# File 'lib/mistri/providers/openai.rb', line 36 def native_output_schema(schema) return unless Models.find(model)&.provider == :openai SchemaCapabilities.derive(schema, :openai) end |
#prices_usage? ⇒ Boolean
32 33 34 |
# File 'lib/mistri/providers/openai.rb', line 32 def prices_usage? @catalog_pricing && Models.priced?(model) && @service_tier.to_s == "default" end |
#stream(messages:, system: nil, tools: [], signal: nil, **overrides, &emit) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/mistri/providers/openai.rb', line 42 def stream(messages:, system: nil, tools: [], signal: nil, **overrides, &emit) delivery = EventDelivery.wrap(emit) model = overrides.fetch(:model, @model) assembler = OpenAI::Assembler.new(model: model, catalog_pricing: @catalog_pricing) assembler.start(&delivery) body = build_body(model, , system, tools, overrides) outcome = @transport.stream_post("/v1/responses", body: body, headers: headers, signal: signal) do |record| assembler.feed( record, &delivery ) end outcome == :aborted ? assembler.abort(&delivery) : assembler.finish(&delivery) rescue EventDelivery::Failure => e raise EventDelivery.unwrap(e, delivery) rescue Error => e assembler.fail_stream(e, &emit) end |