Class: Braintrust::Server::Handlers::Eval
- Inherits:
-
Object
- Object
- Braintrust::Server::Handlers::Eval
- Defined in:
- lib/braintrust/server/handlers/eval.rb
Overview
POST /eval — adapter that maps HTTP request to Evaluator#run and streams SSE results. Handles auth passthrough, datasets, remote scorers, project_id, and parent.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(evaluators) ⇒ Eval
constructor
A new instance of Eval.
Constructor Details
Instance Method Details
#call(env) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/braintrust/server/handlers/eval.rb', line 16 def call(env) body = parse_body(env) return error_response(400, "Invalid JSON body") unless body result = @service.validate(body) return error_response(result[:status], result[:error]) if result[:error] # The protocol-rack adapter (used by Falcon and any server built on # protocol-http) buffers `each`-based bodies through an Enumerable path. # Detect it via the "protocol.http.request" env key it injects, and use # SSEStreamBody (call-only) so it dispatches through the Streaming path. body_class = env.key?("protocol.http.request") ? SSEStreamBody : SSEBody sse_body = body_class.new do |sse| @service.stream(result, auth: env["braintrust.auth"], sse: sse) end [200, {"content-type" => "text/event-stream", "cache-control" => "no-cache", "connection" => "keep-alive"}, sse_body] end |