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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//! Automatic eval registration.
//!
//! Instead of hand-building a `Vec<Eval>`, annotate factory functions and let
//! the study collect them. This is Mira's `cargo test`-style discovery: write
//! the eval, register it, and `Study::registered()` exposes it.
//!
//! ```no_run
//! use mira::{register_eval, Eval, Transcript};
//! use mira::subject::subject_fn;
//! use mira::scorer::contains;
//!
//! fn greet() -> Eval {
//! Eval::new("greet")
//! .sample("hi", "say hi")
//! .subject(subject_fn(|_, _| async { Transcript::response("hi there") }))
//! .scorer(contains("hi"))
//! .build()
//! }
//! register_eval!(greet);
//!
//! #[tokio::main]
//! async fn main() -> std::io::Result<()> {
//! mira::Study::registered().serve().await
//! }
//! ```
//!
//! Registration is collected at link time via [`inventory`], so evals can be
//! spread across modules and files with no central list to maintain.
use crateEval;
/// A registered eval factory. Built by [`register_eval!`](crate::register_eval);
/// iterated by [`registered_evals`].
);
collect!;
/// Register a zero-argument `fn() -> Eval` so it is picked up by
/// [`registered_evals`] / [`Study::registered`](crate::Study::registered).
///
/// ```
/// # use mira::{register_eval, Eval, Transcript};
/// # use mira::subject::subject_fn;
/// fn my_eval() -> Eval {
/// Eval::new("e")
/// .sample("a", "x")
/// .subject(subject_fn(|_, _| async { Transcript::default() }))
/// .build()
/// }
/// register_eval!(my_eval);
/// ```
/// Build every registered eval, in registration order within each compilation
/// unit (order across units is unspecified, like inventory generally).
// `register_eval!` is re-exported at the crate root by `#[macro_export]`; the
// doctest above exercises it. A unit test here would register into the same
// global inventory and perturb other tests, so registration is covered by the
// `registration` integration test instead.