Class: Protege::Inference::Provider::Request
- Inherits:
-
Data
- Object
- Data
- Protege::Inference::Provider::Request
- Defined in:
- lib/protege/inference/provider/request.rb
Overview
One normalized generation request handed to a provider's #generate method — the conversation
only: the ordered messages plus the tool schemas to expose. Model, sampling, and credentials are
not carried here; each provider reads those from its own config.providers slice.
messages is the complete ordered message array for this
generation call — resolver context messages (role: :system,
:user, :assistant) prepended by the harness, followed by the
current inbound as a :user message. Providers handle
role: :system messages according to their API requirements
(OpenRouter normalises for all underlying models; a direct
Anthropic provider would extract system messages into its
top-level system: parameter).
Wire serialization
#to_wire renders the request into the standard (OpenAI-compatible) { messages:, tools: }
body. This lives here — not on each provider — because it is the same serialization the API
call needs and a trace needs: OpenRouterProvider#generate builds its payload by merging
model/sampling onto to_wire, and the tracing subscriber snapshots to_wire directly. Keeping
it in one place means a trace records the exact conversation that was sent, never a re-derivation.
Instance Attribute Summary collapse
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
-
#tools ⇒ Object
readonly
Returns the value of attribute tools.
Instance Method Summary collapse
-
#initialize(messages:, tools: []) ⇒ Request
constructor
A new instance of Request.
-
#to_wire ⇒ Hash
Render this request as the standard chat-completions body: the serialized message array and the function-tool schemas.
Constructor Details
#initialize(messages:, tools: []) ⇒ Request
Returns a new instance of Request.
32 33 34 |
# File 'lib/protege/inference/provider/request.rb', line 32 def initialize(messages:, tools: []) super end |
Instance Attribute Details
#messages ⇒ Object (readonly)
Returns the value of attribute messages
26 27 28 |
# File 'lib/protege/inference/provider/request.rb', line 26 def @messages end |
#tools ⇒ Object (readonly)
Returns the value of attribute tools
26 27 28 |
# File 'lib/protege/inference/provider/request.rb', line 26 def tools @tools end |
Instance Method Details
#to_wire ⇒ Hash
Render this request as the standard chat-completions body: the serialized message array and the function-tool schemas. Model, sampling, and credentials are the provider's to add.
40 41 42 43 44 45 |
# File 'lib/protege/inference/provider/request.rb', line 40 def to_wire { messages: .map { || () }, tools: tools.presence&.map { |tool| wire_tool(tool) } }.compact end |