Class: LLM::Transport::Curb Private
- Inherits:
-
LLM::Transport
- Object
- LLM::Transport
- LLM::Transport::Curb
- Defined in:
- lib/llm/transport/curb.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::Curb transport is an optional adapter for libcurl via the [curb](github.com/taf2/curb) gem.
Curb is a C extension around libcurl. It releases the GVL during I/O so other Ruby threads can run while requests are in flight. Its timeout handling is built into libcurl itself — no thread-based timeout library required. It supports HTTP/2, connection reuse, and a wider range of network protocols out of the box.
Unlike the built-in Net::HTTP transports, this transport does not require any Ruby standard library HTTP client and can be used on platforms where Net::HTTP is not available or desired.
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:, ssl:) ⇒ LLM::Transport::Curb constructor private
- #inspect ⇒ String private
-
#interrupt!(owner) ⇒ nil
private
Interrupt an active request, if any.
- #interrupt_errors ⇒ Array<Class<Exception>> private
-
#interrupted?(owner) ⇒ Boolean?
private
Returns whether an execution owner was interrupted.
-
#request(request, owner:, stream: nil) {|response| ... } ⇒ Object
private
Performs a request through curb and returns a transport response wrapper so the provider layer can stay transport-agnostic.
-
#request_owner ⇒ Object
private
Returns the current request owner.
Methods inherited from LLM::Transport
curb, net_http, net_http_persistent, #set_body_stream
Constructor Details
#initialize(host:, port:, timeout:, ssl:) ⇒ LLM::Transport::Curb
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.
33 34 35 36 37 38 39 40 |
# File 'lib/llm/transport/curb.rb', line 33 def initialize(host:, port:, timeout:, ssl:) @host = host @port = port @timeout = timeout @ssl = ssl @base_uri = URI("#{ssl ? "https" : "http"}://#{host}:#{port}/") @monitor = Monitor.new end |
Instance Method Details
#inspect ⇒ String
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.
109 110 111 |
# File 'lib/llm/transport/curb.rb', line 109 def inspect "#<#{LLM::Utils.object_id(self)}>" 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.
Sets the interrupt flag so the on_body callback can raise LLM::Interrupt on the next chunk.
64 65 66 67 68 69 |
# File 'lib/llm/transport/curb.rb', line 64 def interrupt!(owner) request_for(owner) or return lock { (@interrupts ||= {})[owner] = true } rescue *interrupt_errors nil 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.
52 53 54 |
# File 'lib/llm/transport/curb.rb', line 52 def interrupt_errors [*INTERRUPT_ERRORS, *optional_interrupt_errors] 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.
75 76 77 |
# File 'lib/llm/transport/curb.rb', line 75 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 through curb and returns a transport response wrapper so the provider layer can stay transport-agnostic.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/llm/transport/curb.rb', line 88 def request(request, owner:, stream: nil, &b) easy = build_easy(request) set_request(ActiveRequest.new(easy:), owner) if stream perform_streaming(easy, owner, stream) elsif b res = perform_blocking(easy, owner) if LLM::Transport::Response === res res.success? ? b.call(res) : res else res end else perform_blocking(easy, owner) end ensure clear_request(owner) end |
#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.
45 46 47 48 |
# File 'lib/llm/transport/curb.rb', line 45 def request_owner return Fiber.current unless defined?(::Async) Async::Task.current? ? Async::Task.current : Fiber.current end |