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. rubocop:disable Metrics/ClassLength
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/search"] => :search_response, ["POST", "/v1/search/generate"] => :search_generate_response, ["POST", "/v1/agent"] => :agent_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, authorization: nil, request_context: nil, telemetry: nil, max_body_bytes: DEFAULT_MAX_BODY_BYTES) ⇒ void constructor
Constructor Details
#initialize(authentication: nil, authorization: nil, request_context: nil, telemetry: nil, max_body_bytes: DEFAULT_MAX_BODY_BYTES) ⇒ void
42 43 44 45 46 47 48 49 |
# File 'lib/prescient/api.rb', line 42 def initialize(authentication: nil, authorization: nil, request_context: nil, telemetry: nil, max_body_bytes: DEFAULT_MAX_BODY_BYTES) @authentication = authentication @authorization = @request_context = request_context @telemetry = telemetry @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.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/prescient/api.rb', line 54 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) authentication = authentication_result(env) unless authentication return response(401, error_payload("authentication_required", "authentication required", request_id)) end dispatch(env, request_id, principal: authentication == true ? nil : authentication) rescue StandardError => e handle_exception(e, request_id) end |