Class: Tama::Agentic::Service
- Inherits:
-
Object
- Object
- Tama::Agentic::Service
- Defined in:
- lib/tama/agentic/service.rb
Instance Method Summary collapse
- #create_message(attributes = nil, stream: false, callback: nil, headers: {}, timeout: nil, **attribute_keywords, &block) ⇒ Object
-
#initialize(http) ⇒ Service
constructor
A new instance of Service.
Constructor Details
#initialize(http) ⇒ Service
Returns a new instance of Service.
6 7 8 |
# File 'lib/tama/agentic/service.rb', line 6 def initialize(http) @http = http end |
Instance Method Details
#create_message(attributes = nil, stream: false, callback: nil, headers: {}, timeout: nil, **attribute_keywords, &block) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/tama/agentic/service.rb', line 10 def (attributes = nil, stream: false, callback: nil, headers: {}, timeout: nil, **attribute_keywords, &block) @http.validate_namespace!("agentic") attributes ||= attribute_keywords params = attributes.is_a?(MessageParams) ? attributes : MessageParams.parse(attributes) handler = callback || block if stream raise Error::ValidationError, "A callback or block is required when streaming" unless handler.respond_to?(:call) create_stream(params, handler, headers:, timeout:) else response = @http.request( :post, "messages", body: {"stream" => false, "message" => params.to_h}, headers:, timeout: ) @http.parse_body(response, Message) end end |