Class: VectorMCP::Sampling::Result
- Inherits:
-
Object
- Object
- VectorMCP::Sampling::Result
- Defined in:
- lib/vector_mcp/sampling/result.rb
Overview
Represents the result of a sampling request returned by an MCP client.
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#raw_result ⇒ Object
readonly
Returns the value of attribute raw_result.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
-
#stop_reason ⇒ Object
readonly
Returns the value of attribute stop_reason.
Instance Method Summary collapse
-
#image? ⇒ Boolean
True if the content type is 'image'.
-
#image_data ⇒ String?
The base64 encoded image data if type is 'image', otherwise nil.
-
#image_mime_type ⇒ String?
The mime type of the image if type is 'image', otherwise nil.
-
#initialize(result_hash) ⇒ Result
constructor
Initializes a new Sampling::Result.
-
#text? ⇒ Boolean
True if the content type is 'text'.
-
#text_content ⇒ String?
The text content if type is 'text', otherwise nil.
Constructor Details
#initialize(result_hash) ⇒ Result
Initializes a new Sampling::Result.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/vector_mcp/sampling/result.rb', line 21 def initialize(result_hash) @raw_result = result_hash.transform_keys { |k| k.to_s.gsub(/(.)([A-Z])/, '\1_\2').downcase.to_sym } @model = @raw_result[:model] @stop_reason = @raw_result[:stop_reason] @role = @raw_result[:role] @content = (@raw_result[:content] || {}).transform_keys(&:to_sym) validate! end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
7 8 9 |
# File 'lib/vector_mcp/sampling/result.rb', line 7 def content @content end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
7 8 9 |
# File 'lib/vector_mcp/sampling/result.rb', line 7 def model @model end |
#raw_result ⇒ Object (readonly)
Returns the value of attribute raw_result.
7 8 9 |
# File 'lib/vector_mcp/sampling/result.rb', line 7 def raw_result @raw_result end |
#role ⇒ Object (readonly)
Returns the value of attribute role.
7 8 9 |
# File 'lib/vector_mcp/sampling/result.rb', line 7 def role @role end |
#stop_reason ⇒ Object (readonly)
Returns the value of attribute stop_reason.
7 8 9 |
# File 'lib/vector_mcp/sampling/result.rb', line 7 def stop_reason @stop_reason end |
Instance Method Details
#image? ⇒ Boolean
Returns True if the content type is 'image'.
38 39 40 |
# File 'lib/vector_mcp/sampling/result.rb', line 38 def image? @content[:type] == "image" end |
#image_data ⇒ String?
Returns The base64 encoded image data if type is 'image', otherwise nil.
48 49 50 |
# File 'lib/vector_mcp/sampling/result.rb', line 48 def image_data image? ? @content[:data] : nil end |
#image_mime_type ⇒ String?
Returns The mime type of the image if type is 'image', otherwise nil.
53 54 55 |
# File 'lib/vector_mcp/sampling/result.rb', line 53 def image_mime_type image? ? @content[:mime_type] : nil end |
#text? ⇒ Boolean
Returns True if the content type is 'text'.
33 34 35 |
# File 'lib/vector_mcp/sampling/result.rb', line 33 def text? @content[:type] == "text" end |
#text_content ⇒ String?
Returns The text content if type is 'text', otherwise nil.
43 44 45 |
# File 'lib/vector_mcp/sampling/result.rb', line 43 def text_content text? ? @content[:text] : nil end |