#github.com/xulang-org/packages/eval
Xu 0.16.0 API
import: eval #github.com/xulang-org/packages/eval
counts: 25 functions, 0 methods, 9 types, 0 constants, 0 method sets
External package `eval #github.com/xulang-org/packages/eval`, provided by github.com/xulang-org/packages.
github.com/xulang-org/packages · 1.17.2 · Install and use
struct JudgeResult
pub struct JudgeResult {
pub score f64
pub passed bool
pub reasoning string
}
Purpose
Structure encapsulating score, passed, reasoning.
Public fields
score f64- field (f64)
passed bool- field (bool)
reasoning string- field (string)
struct EvalCase
pub struct EvalCase {
pub id string
pub input string
pub expected string
}
Purpose
Structure encapsulating id, input, expected.
Public fields
id string- field (string)
input string- field (string)
expected string- field (string)
struct EvalSummary
pub struct EvalSummary {
pub total int
pub exact_match_avg f64
pub token_f1_avg f64
pub rouge_l_avg f64
}
Purpose
Structure encapsulating total, exact_match_avg, token_f1_avg, rouge_l_avg.
Public fields
total int- field (int)
exact_match_avg f64- field (f64)
token_f1_avg f64- field (f64)
rouge_l_avg f64- field (f64)
struct RagasReport
pub struct RagasReport {
pub context_precision f64
pub context_recall f64
pub faithfulness f64
pub answer_relevancy f64
pub overall f64
}
Purpose
Structure encapsulating context_precision, context_recall, faithfulness, answer_relevancy, overall.
Public fields
context_precision f64- field (f64)
context_recall f64- field (f64)
faithfulness f64- field (f64)
answer_relevancy f64- field (f64)
overall f64- field (f64)
exact_match
pub fn exact_match(pred &string, gold &string, normalize bool) f64
Purpose
Exact match.
Parameters
pred &string- pred (read-only borrow; caller keeps the original; type &string)
gold &string- gold (read-only borrow; caller keeps the original; type &string)
normalize bool- normalize (bool)
Returns
f64 — a value of this type
token_f1
pub fn token_f1(pred &string, gold &string) f64
Purpose
Token f1.
Parameters
pred &string- pred (read-only borrow; caller keeps the original; type &string)
gold &string- gold (read-only borrow; caller keeps the original; type &string)
Returns
f64 — a value of this type
rouge_n
pub fn rouge_n(pred &string, reference &string, n int) f64
Purpose
Rouge n.
Parameters
pred &string- pred (read-only borrow; caller keeps the original; type &string)
reference &string- reference (read-only borrow; caller keeps the original; type &string)
n int- count, length, or limit (int)
Returns
f64 — a value of this type
rouge_l
pub fn rouge_l(pred &string, reference &string) f64
Purpose
Rouge l.
Parameters
pred &string- pred (read-only borrow; caller keeps the original; type &string)
reference &string- reference (read-only borrow; caller keeps the original; type &string)
Returns
f64 — a value of this type
bleu_score
pub fn bleu_score(pred &string, reference &string, max_n int) f64
Purpose
Bleu score.
Parameters
pred &string- pred (read-only borrow; caller keeps the original; type &string)
reference &string- reference (read-only borrow; caller keeps the original; type &string)
max_n int- max_n (int)
Returns
f64 — a value of this type
json_valid_score
pub fn json_valid_score(output &string, required_keys &[]string) f64
Purpose
Json valid score.
Parameters
output &string- output (read-only borrow; caller keeps the original; type &string)
required_keys &[]string- required_keys (read-only borrow; caller keeps the original; type &[]string)
Returns
f64 — a value of this type
judge_openai
pub fn judge_openai(client &openai.Client, model string, question string, answer string, rubric string, pass_threshold f64) JudgeResult
Purpose
Judge openai. Throws on failure; handle the error or propagate it to the caller.
Parameters
client &openai.Client- client (read-only borrow; caller keeps the original; type &openai.Client)
model string- model (string)
question string- question (string)
answer string- answer (string)
rubric string- rubric (string)
pass_threshold f64- pass_threshold (f64)
Returns
JudgeResult — a value of this type
judge_anthropic
pub fn judge_anthropic(client &anthropic.Client, model string, question string, answer string, rubric string, pass_threshold f64) JudgeResult
Purpose
Judge anthropic. Throws on failure; handle the error or propagate it to the caller.
Parameters
client &anthropic.Client- client (read-only borrow; caller keeps the original; type &anthropic.Client)
model string- model (string)
question string- question (string)
answer string- answer (string)
rubric string- rubric (string)
pass_threshold f64- pass_threshold (f64)
Returns
JudgeResult — a value of this type
judge_gemini
pub fn judge_gemini(client &gemini.Client, model string, question string, answer string, rubric string, pass_threshold f64) JudgeResult
Purpose
Judge gemini. Throws on failure; handle the error or propagate it to the caller.
Parameters
client &gemini.Client- client (read-only borrow; caller keeps the original; type &gemini.Client)
model string- model (string)
question string- question (string)
answer string- answer (string)
rubric string- rubric (string)
pass_threshold f64- pass_threshold (f64)
Returns
JudgeResult — a value of this type
run_suite
pub fn run_suite(cases &[]EvalCase, predictor fn(&string) string) EvalSummary
Purpose
Run suite.
Parameters
cases &[]EvalCase- cases (read-only borrow; caller keeps the original; type &[]EvalCase)
predictor fn(&string) string- predictor (function value; type fn(&string) string)
Returns
EvalSummary — a value of this type
rag_context_precision
pub fn rag_context_precision(retrieved_texts &[]string, ground_truth &string) f64
Purpose
Rag context precision.
Parameters
retrieved_texts &[]string- retrieved_texts (read-only borrow; caller keeps the original; type &[]string)
ground_truth &string- ground_truth (read-only borrow; caller keeps the original; type &string)
Returns
f64 — a value of this type
rag_context_recall
pub fn rag_context_recall(retrieved_texts &[]string, ground_truth &string) f64
Purpose
Rag context recall.
Parameters
retrieved_texts &[]string- retrieved_texts (read-only borrow; caller keeps the original; type &[]string)
ground_truth &string- ground_truth (read-only borrow; caller keeps the original; type &string)
Returns
f64 — a value of this type
rag_faithfulness
pub fn rag_faithfulness(answer &string, retrieved_texts &[]string) f64
Purpose
Rag faithfulness.
Parameters
answer &string- answer (read-only borrow; caller keeps the original; type &string)
retrieved_texts &[]string- retrieved_texts (read-only borrow; caller keeps the original; type &[]string)
Returns
f64 — a value of this type
rag_answer_relevancy
pub fn rag_answer_relevancy(question &string, answer &string) f64
Purpose
Rag answer relevancy.
Parameters
question &string- question (read-only borrow; caller keeps the original; type &string)
answer &string- answer (read-only borrow; caller keeps the original; type &string)
Returns
f64 — a value of this type
evaluate_rag_triad
pub fn evaluate_rag_triad(question &string, answer &string, retrieved_texts &[]string, ground_truth &string) RagasReport
Purpose
Evaluate rag triad.
Parameters
question &string- question (read-only borrow; caller keeps the original; type &string)
answer &string- answer (read-only borrow; caller keeps the original; type &string)
retrieved_texts &[]string- retrieved_texts (read-only borrow; caller keeps the original; type &[]string)
ground_truth &string- ground_truth (read-only borrow; caller keeps the original; type &string)
Returns
RagasReport — a value of this type
evaluate_rag_judge_openai
pub fn evaluate_rag_judge_openai(client &openai.Client, model string, question string, answer string, retrieved_texts &[]string) RagasReport
Purpose
Evaluate rag judge openai. Throws on failure; handle the error or propagate it to the caller.
Parameters
client &openai.Client- client (read-only borrow; caller keeps the original; type &openai.Client)
model string- model (string)
question string- question (string)
answer string- answer (string)
retrieved_texts &[]string- retrieved_texts (read-only borrow; caller keeps the original; type &[]string)
Returns
RagasReport — a value of this type
struct PairwiseResult
pub struct PairwiseResult {
pub winner string
pub reasoning string
}
Purpose
Structure encapsulating winner, reasoning.
Public fields
winner string- field (string)
reasoning string- field (string)
pass_at_k
pub fn pass_at_k(n int, c int, k int) f64
Purpose
Pass at k.
Parameters
n int- count, length, or limit (int)
c int- byte or character code (int)
k int- key or index (int)
Returns
f64 — a value of this type
compare_openai
pub fn compare_openai(client &openai.Client, model string, question string, answer_a string, answer_b string, rubric string) PairwiseResult
Purpose
Compare openai. Throws on failure; handle the error or propagate it to the caller.
Parameters
client &openai.Client- client (read-only borrow; caller keeps the original; type &openai.Client)
model string- model (string)
question string- question (string)
answer_a string- answer_a (string)
answer_b string- answer_b (string)
rubric string- rubric (string)
Returns
PairwiseResult — a value of this type
load_cases_jsonl
pub fn load_cases_jsonl(path string) []EvalCase
Purpose
Load cases jsonl. Throws on failure; handle the error or propagate it to the caller.
Parameters
path string- filesystem path (string)
Returns
[]EvalCase — slice result
struct SchemaFieldRule
pub struct SchemaFieldRule {
pub name string
pub expected_type string
pub required bool
}
Purpose
Structure encapsulating name, expected_type, required.
Public fields
name string- name
expected_type string- field (string)
required bool- field (bool)
struct SchemaCheckResult
pub struct SchemaCheckResult {
pub valid bool
pub pass_rate f64
pub missing_fields []string
pub type_mismatches []string
}
Purpose
Structure encapsulating valid, pass_rate, missing_fields, type_mismatches.
Public fields
valid bool- field (bool)
pass_rate f64- field (f64)
missing_fields []string- field ([]string)
type_mismatches []string- field ([]string)
struct RawSchemaResult
pub struct RawSchemaResult {
pub valid bool
pub errors []string
}
Purpose
Structure encapsulating valid, errors.
Public fields
valid bool- field (bool)
errors []string- field ([]string)
evaluate_json_schema_raw
pub fn evaluate_json_schema_raw(output &string, schema_json &string) RawSchemaResult
Purpose
Evaluate json schema raw.
Parameters
output &string- output (read-only borrow; caller keeps the original; type &string)
schema_json &string- schema_json (read-only borrow; caller keeps the original; type &string)
Returns
RawSchemaResult — a value of this type
evaluate_json_schema
pub fn evaluate_json_schema(output &string, rules &[]SchemaFieldRule) SchemaCheckResult
Purpose
Evaluate json schema.
Parameters
output &string- output (read-only borrow; caller keeps the original; type &string)
rules &[]SchemaFieldRule- rules (read-only borrow; caller keeps the original; type &[]SchemaFieldRule)
Returns
SchemaCheckResult — a value of this type
expected_calibration_error
pub fn expected_calibration_error(confidences &[]f64, correctness &[]bool, num_bins int) f64
Purpose
Expected calibration error.
Parameters
confidences &[]f64- confidences (read-only borrow; caller keeps the original; type &[]f64)
correctness &[]bool- correctness (read-only borrow; caller keeps the original; type &[]bool)
num_bins int- num_bins (int)
Returns
f64 — a value of this type
struct RegressionGateResult
pub struct RegressionGateResult {
pub passed bool
pub em_delta f64
pub f1_delta f64
pub rouge_delta f64
pub summary string
}
Purpose
Structure encapsulating passed, em_delta, f1_delta, rouge_delta, summary.
Public fields
passed bool- field (bool)
em_delta f64- field (f64)
f1_delta f64- field (f64)
rouge_delta f64- field (f64)
summary string- field (string)
compare_summaries
pub fn compare_summaries(baseline &EvalSummary, candidate &EvalSummary, max_drop f64) RegressionGateResult
Purpose
Compare summaries.
Parameters
baseline &EvalSummary- baseline (read-only borrow; caller keeps the original; type &EvalSummary)
candidate &EvalSummary- candidate (read-only borrow; caller keeps the original; type &EvalSummary)
max_drop f64- max_drop (f64)
Returns
RegressionGateResult — a value of this type
format_summary_markdown
pub fn format_summary_markdown(name string, s &EvalSummary) string
Purpose
Format as summary markdown.
Parameters
name string- name (string)
s &EvalSummary- s (read-only borrow; caller keeps the original; type &EvalSummary)
Returns
string — result string
format_summary_json
pub fn format_summary_json(name string, s &EvalSummary) string
Purpose
Format as summary json.
Parameters
name string- name (string)
s &EvalSummary- s (read-only borrow; caller keeps the original; type &EvalSummary)
Returns
string — result string