Class: CleoQualityReview::LlmProviders::OpenAi::HttpRequest

Inherits:
Struct
  • Object
show all
Defined in:
lib/cleo_quality_review/llm_providers/open_ai.rb

Overview

Value object for a JSON POST request to OpenAI.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyObject

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



33
34
35
# File 'lib/cleo_quality_review/llm_providers/open_ai.rb', line 33

def body
  @body
end

#headersObject

Returns the value of attribute headers

Returns:

  • (Object)

    the current value of headers



33
34
35
# File 'lib/cleo_quality_review/llm_providers/open_ai.rb', line 33

def headers
  @headers
end

#timeout_secondsObject

Returns the value of attribute timeout_seconds

Returns:

  • (Object)

    the current value of timeout_seconds



33
34
35
# File 'lib/cleo_quality_review/llm_providers/open_ai.rb', line 33

def timeout_seconds
  @timeout_seconds
end

#uriObject

Returns the value of attribute uri

Returns:

  • (Object)

    the current value of uri



33
34
35
# File 'lib/cleo_quality_review/llm_providers/open_ai.rb', line 33

def uri
  @uri
end

Instance Method Details

#execute(http_request) {|Net::HTTP| ... } ⇒ Object

Execute the HTTP request.

Parameters:

  • http_request (Net::HTTP::Post)

    prepared request

Yields:

  • (Net::HTTP)

    yields configured HTTP connection

Returns:

  • (Object)

    result of the block



39
40
41
42
43
44
45
46
# File 'lib/cleo_quality_review/llm_providers/open_ai.rb', line 39

def execute(http_request)
  Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
    http.open_timeout = timeout_seconds
    http.read_timeout = timeout_seconds
    http.write_timeout = timeout_seconds
    http.request(http_request)
  end
end