Class: LlmCassette::Interaction
- Inherits:
-
Object
- Object
- LlmCassette::Interaction
- Defined in:
- lib/llm_cassette/interaction.rb
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
- .from_hash(hash) ⇒ Object
- .from_recording(env:, response:, streaming:, chunks:, request_body:) ⇒ Object
Instance Method Summary collapse
-
#initialize(request:, response:) ⇒ Interaction
constructor
A new instance of Interaction.
- #streaming? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(request:, response:) ⇒ Interaction
Returns a new instance of Interaction.
9 10 11 12 |
# File 'lib/llm_cassette/interaction.rb', line 9 def initialize(request:, response:) @request = request @response = response end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
7 8 9 |
# File 'lib/llm_cassette/interaction.rb', line 7 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
7 8 9 |
# File 'lib/llm_cassette/interaction.rb', line 7 def response @response end |
Class Method Details
.from_hash(hash) ⇒ Object
26 27 28 |
# File 'lib/llm_cassette/interaction.rb', line 26 def self.from_hash(hash) new(request: hash["request"], response: hash["response"]) end |
.from_recording(env:, response:, streaming:, chunks:, request_body:) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/llm_cassette/interaction.rb', line 14 def self.from_recording(env:, response:, streaming:, chunks:, request_body:) req = { "method" => env.method.to_s.downcase, "uri" => env.url.to_s, "body" => request_body } res = build_response_hash(response, streaming, chunks) new(request: req, response: res) end |
Instance Method Details
#streaming? ⇒ Boolean
34 35 36 |
# File 'lib/llm_cassette/interaction.rb', line 34 def streaming? response["streaming"] == true end |
#to_h ⇒ Object
30 31 32 |
# File 'lib/llm_cassette/interaction.rb', line 30 def to_h { "request" => request, "response" => response } end |