Class: Legion::LLM::Pipeline::Response
- Inherits:
-
Data
- Object
- Data
- Legion::LLM::Pipeline::Response
- Defined in:
- lib/legion/llm/pipeline/response.rb
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#audit ⇒ Object
readonly
Returns the value of attribute audit.
-
#billing ⇒ Object
readonly
Returns the value of attribute billing.
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#caller ⇒ Object
readonly
Returns the value of attribute caller.
-
#classification ⇒ Object
readonly
Returns the value of attribute classification.
-
#conversation_id ⇒ Object
readonly
Returns the value of attribute conversation_id.
-
#cost ⇒ Object
readonly
Returns the value of attribute cost.
-
#deprecation ⇒ Object
readonly
Returns the value of attribute deprecation.
-
#enrichments ⇒ Object
readonly
Returns the value of attribute enrichments.
-
#features ⇒ Object
readonly
Returns the value of attribute features.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#participants ⇒ Object
readonly
Returns the value of attribute participants.
-
#predictions ⇒ Object
readonly
Returns the value of attribute predictions.
-
#quality ⇒ Object
readonly
Returns the value of attribute quality.
-
#rate_limit ⇒ Object
readonly
Returns the value of attribute rate_limit.
-
#request_id ⇒ Object
readonly
Returns the value of attribute request_id.
-
#retry ⇒ Object
readonly
Returns the value of attribute retry.
-
#routing ⇒ Object
readonly
Returns the value of attribute routing.
-
#safety ⇒ Object
readonly
Returns the value of attribute safety.
-
#schema_version ⇒ Object
readonly
Returns the value of attribute schema_version.
-
#stop ⇒ Object
readonly
Returns the value of attribute stop.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
-
#test ⇒ Object
readonly
Returns the value of attribute test.
-
#thinking ⇒ Object
readonly
Returns the value of attribute thinking.
-
#timeline ⇒ Object
readonly
Returns the value of attribute timeline.
-
#timestamps ⇒ Object
readonly
Returns the value of attribute timestamps.
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
-
#tools ⇒ Object
readonly
Returns the value of attribute tools.
-
#tracing ⇒ Object
readonly
Returns the value of attribute tracing.
-
#validation ⇒ Object
readonly
Returns the value of attribute validation.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
-
#wire ⇒ Object
readonly
Returns the value of attribute wire.
Class Method Summary collapse
- .build(**kwargs) ⇒ Object
- .from_ruby_llm(msg, request_id:, conversation_id:, provider: nil, model: nil, **extra) ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def agent @agent end |
#audit ⇒ Object (readonly)
Returns the value of attribute audit
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def audit @audit end |
#billing ⇒ Object (readonly)
Returns the value of attribute billing
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def billing @billing end |
#cache ⇒ Object (readonly)
Returns the value of attribute cache
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def cache @cache end |
#caller ⇒ Object (readonly)
Returns the value of attribute caller
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def caller @caller end |
#classification ⇒ Object (readonly)
Returns the value of attribute classification
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def classification @classification end |
#conversation_id ⇒ Object (readonly)
Returns the value of attribute conversation_id
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def conversation_id @conversation_id end |
#cost ⇒ Object (readonly)
Returns the value of attribute cost
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def cost @cost end |
#deprecation ⇒ Object (readonly)
Returns the value of attribute deprecation
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def deprecation @deprecation end |
#enrichments ⇒ Object (readonly)
Returns the value of attribute enrichments
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def enrichments @enrichments end |
#features ⇒ Object (readonly)
Returns the value of attribute features
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def features @features end |
#id ⇒ Object (readonly)
Returns the value of attribute id
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def id @id end |
#message ⇒ Object (readonly)
Returns the value of attribute message
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def @message end |
#participants ⇒ Object (readonly)
Returns the value of attribute participants
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def participants @participants end |
#predictions ⇒ Object (readonly)
Returns the value of attribute predictions
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def predictions @predictions end |
#quality ⇒ Object (readonly)
Returns the value of attribute quality
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def quality @quality end |
#rate_limit ⇒ Object (readonly)
Returns the value of attribute rate_limit
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def rate_limit @rate_limit end |
#request_id ⇒ Object (readonly)
Returns the value of attribute request_id
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def request_id @request_id end |
#retry ⇒ Object (readonly)
Returns the value of attribute retry
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def retry @retry end |
#routing ⇒ Object (readonly)
Returns the value of attribute routing
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def routing @routing end |
#safety ⇒ Object (readonly)
Returns the value of attribute safety
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def safety @safety end |
#schema_version ⇒ Object (readonly)
Returns the value of attribute schema_version
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def schema_version @schema_version end |
#stop ⇒ Object (readonly)
Returns the value of attribute stop
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def stop @stop end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def stream @stream end |
#test ⇒ Object (readonly)
Returns the value of attribute test
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def test @test end |
#thinking ⇒ Object (readonly)
Returns the value of attribute thinking
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def thinking @thinking end |
#timeline ⇒ Object (readonly)
Returns the value of attribute timeline
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def timeline @timeline end |
#timestamps ⇒ Object (readonly)
Returns the value of attribute timestamps
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def @timestamps end |
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def tokens @tokens end |
#tools ⇒ Object (readonly)
Returns the value of attribute tools
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def tools @tools end |
#tracing ⇒ Object (readonly)
Returns the value of attribute tracing
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def tracing @tracing end |
#validation ⇒ Object (readonly)
Returns the value of attribute validation
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def validation @validation end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def warnings @warnings end |
#wire ⇒ Object (readonly)
Returns the value of attribute wire
6 7 8 |
# File 'lib/legion/llm/pipeline/response.rb', line 6 def wire @wire end |
Class Method Details
.build(**kwargs) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/legion/llm/pipeline/response.rb', line 15 def self.build(**kwargs) new( id: kwargs.fetch(:id) { "resp_#{SecureRandom.hex(12)}" }, request_id: kwargs.fetch(:request_id), conversation_id: kwargs.fetch(:conversation_id), schema_version: kwargs.fetch(:schema_version, '1.0.0'), message: kwargs.fetch(:message), routing: kwargs.fetch(:routing, {}), tokens: kwargs.fetch(:tokens, {}), thinking: kwargs[:thinking], stop: kwargs.fetch(:stop, {}), tools: kwargs.fetch(:tools, []), stream: kwargs.fetch(:stream, false), cache: kwargs.fetch(:cache, {}), retry: kwargs[:retry], timestamps: kwargs.fetch(:timestamps, {}), cost: kwargs.fetch(:cost, {}), quality: kwargs[:quality], validation: kwargs[:validation], safety: kwargs[:safety], rate_limit: kwargs[:rate_limit], features: kwargs[:features], deprecation: kwargs[:deprecation], enrichments: kwargs.fetch(:enrichments, {}), predictions: kwargs.fetch(:predictions, {}), audit: kwargs.fetch(:audit, {}), timeline: kwargs.fetch(:timeline, []), participants: kwargs.fetch(:participants, []), warnings: kwargs.fetch(:warnings, []), wire: kwargs[:wire], tracing: kwargs[:tracing], caller: kwargs[:caller], classification: kwargs[:classification], agent: kwargs[:agent], billing: kwargs[:billing], test: kwargs[:test] ) end |
.from_ruby_llm(msg, request_id:, conversation_id:, provider: nil, model: nil, **extra) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/legion/llm/pipeline/response.rb', line 54 def self.from_ruby_llm(msg, request_id:, conversation_id:, provider: nil, model: nil, **extra) input = msg.respond_to?(:input_tokens) ? msg.input_tokens.to_i : 0 output = msg.respond_to?(:output_tokens) ? msg.output_tokens.to_i : 0 stop_reason = if msg.respond_to?(:stop_reason) msg.stop_reason&.to_sym || :end_turn elsif msg.respond_to?(:tool_calls) && msg.tool_calls&.any? :tool_use else :end_turn end build( request_id: request_id, conversation_id: conversation_id, message: { role: :assistant, content: msg.content }, routing: { provider: provider, model: model || (msg.respond_to?(:model_id) ? msg.model_id : nil) }, tokens: { input: input, output: output, total: input + output }, stop: { reason: stop_reason }, **extra ) end |
Instance Method Details
#with(**updates) ⇒ Object
77 78 79 |
# File 'lib/legion/llm/pipeline/response.rb', line 77 def with(**updates) self.class.build(**to_h, **updates) end |