Class: LLM::Transport
- Inherits:
-
Object
- Object
- LLM::Transport
- Defined in:
- lib/llm/transport.rb,
lib/llm/transport/curb.rb,
lib/llm/transport/http.rb,
lib/llm/transport/utils.rb,
lib/llm/transport/request.rb,
lib/llm/transport/response.rb,
lib/llm/transport/execution.rb,
lib/llm/transport/stream_decoder.rb,
lib/llm/transport/persistent_http.rb,
lib/llm/transport/net_http_adapter.rb
Overview
The LLM::Transport class defines the execution interface used by Provider.
Custom transports can subclass this class and override #request to execute provider requests without changing request adapters or response adapters.
Providers should construct Request objects before delegating to a transport. Custom transports can execute those requests directly, or transform them into backend-specific request objects before execution.
Only #request is required. The remaining methods are optional hooks for features such as interruption, request ownership, or persistence, and only need to be implemented when the underlying adapter can support them.
Returned responses should implement the LLM::Transport::Response interface. In practice this can mean adapting another client’s response object so existing provider execution, response adapters, and error handlers can rely on one normalized response contract instead of transport-specific classes.
Direct Known Subclasses
Defined Under Namespace
Modules: Execution, NetHTTPAdapter, Utils Classes: Curb, HTTP, PersistentHTTP, Request, Response, StreamDecoder
Class Method Summary collapse
-
.curb ⇒ Class
Returns the optional libcurl (curb) transport class.
-
.net_http ⇒ Class
Returns the built-in Net::HTTP transport class.
-
.net_http_persistent ⇒ Class
Returns the built-in Net::HTTP::Persistent transport class.
Instance Method Summary collapse
-
#interrupt!(owner) ⇒ nil
Interrupt an active request, if any.
-
#interrupt_errors ⇒ Array<Class<Exception>>
Returns the exception classes that indicate an interrupted request.
-
#interrupted?(owner) ⇒ Boolean?
Returns whether an execution owner was interrupted.
-
#request(request, owner:, stream: nil) {|response| ... } ⇒ Object
Performs a request through the transport.
-
#request_owner ⇒ Object
Returns the current request owner.
- #set_body_stream(request, io) ⇒ void
Class Method Details
.curb ⇒ Class
Returns the optional libcurl (curb) transport class. Requires the ‘curb` gem.
57 58 59 |
# File 'lib/llm/transport.rb', line 57 def self.curb Curb end |
.net_http ⇒ Class
Returns the built-in Net::HTTP transport class.
42 43 44 |
# File 'lib/llm/transport.rb', line 42 def self.net_http HTTP end |
.net_http_persistent ⇒ Class
Returns the built-in Net::HTTP::Persistent transport class.
49 50 51 |
# File 'lib/llm/transport.rb', line 49 def self.net_http_persistent PersistentHTTP end |
Instance Method Details
#interrupt!(owner) ⇒ nil
Interrupt an active request, if any.
91 92 93 |
# File 'lib/llm/transport.rb', line 91 def interrupt!(owner) raise NotImplementedError end |
#interrupt_errors ⇒ Array<Class<Exception>>
Returns the exception classes that indicate an interrupted request.
83 84 85 |
# File 'lib/llm/transport.rb', line 83 def interrupt_errors [] end |
#interrupted?(owner) ⇒ Boolean?
Returns whether an execution owner was interrupted.
99 100 101 |
# File 'lib/llm/transport.rb', line 99 def interrupted?(owner) nil end |
#request(request, owner:, stream: nil) {|response| ... } ⇒ Object
Performs a request through the transport.
68 69 70 |
# File 'lib/llm/transport.rb', line 68 def request(request, owner:, stream: nil, &) raise NotImplementedError end |
#request_owner ⇒ Object
Returns the current request owner.
75 76 77 78 |
# File 'lib/llm/transport.rb', line 75 def request_owner return Fiber.current unless defined?(::Async) Async::Task.current? ? Async::Task.current : Fiber.current end |
#set_body_stream(request, io) ⇒ void
This method returns an undefined value.
107 108 109 110 |
# File 'lib/llm/transport.rb', line 107 def set_body_stream(request, io) request.body_stream = io request["transfer-encoding"] = "chunked" unless request["content-length"] end |