Class: LLM::Transport::PersistentHTTP Private
- Inherits:
-
LLM::Transport
- Object
- LLM::Transport
- LLM::Transport::PersistentHTTP
- Includes:
- NetHTTPAdapter
- Defined in:
- lib/llm/transport/persistent_http.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
The LLM::Transport::PersistentHTTP transport is the built-in adapter for Net::HTTP::Persistent. It manages pooled HTTP connections, tracks active requests by owner, and interrupts in-flight requests when needed.
Defined Under Namespace
Classes: ActiveRequest
Constant Summary collapse
- INTERRUPT_ERRORS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[::IOError, ::EOFError, Errno::EBADF].freeze
Instance Method Summary collapse
- #initialize(host:, port:, timeout:, connect_timeout:, ssl:) ⇒ LLM::Transport::PersistentHTTP constructor private
-
#request_owner ⇒ Object
private
Returns the current request owner.
- #interrupt_errors ⇒ Array<Class<Exception>> private
-
#interrupt!(owner) ⇒ nil
private
Interrupt an active request, if any.
-
#interrupted?(owner) ⇒ Boolean?
private
Returns whether an execution owner was interrupted.
-
#request(request, owner:, stream: nil) {|response| ... } ⇒ Object
private
Performs a request on the current HTTP transport.
Methods inherited from LLM::Transport
net_http, net_http_persistent, #set_body_stream
Constructor Details
#initialize(host:, port:, timeout:, connect_timeout:, ssl:) ⇒ LLM::Transport::PersistentHTTP
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
25 26 27 28 29 30 31 32 33 |
# File 'lib/llm/transport/persistent_http.rb', line 25 def initialize(host:, port:, timeout:, connect_timeout:, ssl:) @host = host @port = port @timeout = timeout @connect_timeout = connect_timeout @ssl = ssl @base_uri = URI("#{ssl ? "https" : "http"}://#{host}:#{port}/") @monitor = Monitor.new end |
Instance Method Details
#request_owner ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the current request owner.
38 39 40 41 |
# File 'lib/llm/transport/persistent_http.rb', line 38 def request_owner return Fiber.current unless defined?(::Async) Async::Task.current? ? Async::Task.current : Fiber.current end |
#interrupt_errors ⇒ Array<Class<Exception>>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
45 46 47 |
# File 'lib/llm/transport/persistent_http.rb', line 45 def interrupt_errors [*INTERRUPT_ERRORS, *optional_interrupt_errors] end |
#interrupt!(owner) ⇒ nil
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Interrupt an active request, if any.
53 54 55 56 57 58 59 60 61 |
# File 'lib/llm/transport/persistent_http.rb', line 53 def interrupt!(owner) req = request_for(owner) or return lock { (@interrupts ||= {})[owner] = true } close_socket(req.connection&.http) req.client.finish(req.connection) owner.stop if owner.respond_to?(:stop) rescue *interrupt_errors nil end |
#interrupted?(owner) ⇒ Boolean?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns whether an execution owner was interrupted.
67 68 69 |
# File 'lib/llm/transport/persistent_http.rb', line 67 def interrupted?(owner) lock { @interrupts&.delete(owner) } end |
#request(request, owner:, stream: nil) {|response| ... } ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Performs a request on the current HTTP
transport. Accepts both Net::HTTPRequest
and Request.
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/llm/transport/persistent_http.rb', line 81 def request(request, owner:, stream: nil, &b) req = resolve_request(request) uri = URI.join(base_uri, req.path) client.connection_for(uri) do |connection| set_request(ActiveRequest.new(client:, connection:), owner) perform_request(connection.http, req, stream, &b) end ensure clear_request(owner) end |