Class: Prescient::API
- Inherits:
-
Object
- Object
- Prescient::API
- Defined in:
- lib/prescient/api.rb
Overview
Dependency-free Rack-compatible HTTP application for Prescient operations.
The application exposes only generic Prescient operations. It does not expose provider-specific methods, credentials, or raw provider responses.
Constant Summary collapse
- DEFAULT_MAX_BODY_BYTES =
Returns Default maximum request body size in bytes.
1_048_576- MAX_BATCH_SIZE =
Returns Maximum number of inputs accepted by batch embeddings.
32- API_VERSION =
Returns HTTP API version.
'1'- ROUTES =
Returns Generic HTTP route handlers.
{ ['GET', '/healthz'] => :healthz_response, ['GET', '/readyz'] => :readiness_response, ['GET', '/v1/version'] => :version_response, ['GET', '/v1/providers'] => :providers_response, ['GET', '/v1/models'] => :models_response, ['GET', '/v1/capabilities'] => :capabilities_response, ['GET', '/v1/health'] => :health_response, ['POST', '/v1/generate'] => :generate_response, ['POST', '/v1/embeddings'] => :embeddings_response, ['POST', '/v1/embeddings/batch'] => :batch_embeddings_response, }.freeze
Instance Method Summary collapse
-
#call(env) ⇒ Array(Integer, Hash, Array<String>)
Handle a Rack-style environment and return a Rack response tuple.
- #initialize(authentication: nil, max_body_bytes: DEFAULT_MAX_BODY_BYTES) ⇒ void constructor
Constructor Details
#initialize(authentication: nil, max_body_bytes: DEFAULT_MAX_BODY_BYTES) ⇒ void
37 38 39 40 |
# File 'lib/prescient/api.rb', line 37 def initialize(authentication: nil, max_body_bytes: DEFAULT_MAX_BODY_BYTES) @authentication = authentication @max_body_bytes = validate_body_limit(max_body_bytes) end |
Instance Method Details
#call(env) ⇒ Array(Integer, Hash, Array<String>)
Handle a Rack-style environment and return a Rack response tuple.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/prescient/api.rb', line 45 def call(env) request_id = request_id_for(env) public_path = request_target(env).first return dispatch(env, request_id) if ['/healthz', '/readyz'].include?(public_path) unless authenticated?(env) return response(401, error_payload('authentication_required', 'authentication required', request_id)) end dispatch(env, request_id) rescue StandardError => e handle_exception(e, request_id) end |