-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy patheval.rb
More file actions
57 lines (48 loc) · 1.86 KB
/
eval.rb
File metadata and controls
57 lines (48 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# frozen_string_literal: true
# Braintrust Rails Engine — mount example
#
# This file shows one conventional setup for the Braintrust eval server in Rails:
# 1. Define evaluator classes under app/evaluators/
# 2. Generate the initializer with:
# bin/rails generate braintrust:server
# 3. Mount the engine in config/routes.rb
#
# Requirements:
# gem 'actionpack', '~> 8.0'
# gem 'railties', '~> 8.0'
# gem 'activesupport', '~> 8.0'
# ---------------------------------------------------------------------------
# app/evaluators/my_classifier.rb
# ---------------------------------------------------------------------------
class MyClassifier < Braintrust::Eval::Evaluator
def task
->(input:) { classify(input) }
end
def scorers
[Braintrust::Scorer.new("accuracy") { |expected:, output:| (output == expected) ? 1.0 : 0.0 }]
end
end
# ---------------------------------------------------------------------------
# config/initializers/braintrust_server.rb
# ---------------------------------------------------------------------------
# Generated by: bin/rails generate braintrust:server
#
# require "braintrust/contrib/rails/server"
#
# Braintrust::Contrib::Rails::Server::Engine.configure do |config|
# config.evaluators = {
# "my-classifier" => MyClassifier.new
# }
#
# # Default is :clerk_token. Use :none only for local development without
# # incoming request authentication. Outgoing Braintrust API calls still need
# # normal Braintrust credentials.
# config.auth = :clerk_token
# end
# ---------------------------------------------------------------------------
# config/routes.rb
# ---------------------------------------------------------------------------
# Rails.application.routes.draw do
# mount Braintrust::Contrib::Rails::Server::Engine, at: "/braintrust"
# end
puts "Braintrust Rails Engine example — see comments for usage"