mirror of
https://github.com/openai/codex.git
synced 2026-09-14 11:57:03 +00:00
docstrings and other cleanup
This commit is contained in:
@@ -207,12 +207,11 @@ fn policy_builtins(builder: &mut GlobalsBuilder) {
|
||||
let rules: Vec<Rule> = first_token
|
||||
.alternatives()
|
||||
.iter()
|
||||
.zip(std::iter::repeat(rest.clone()))
|
||||
.map(|(head, rest)| {
|
||||
.map(|head| {
|
||||
Rule::Prefix(PrefixRule {
|
||||
pattern: PrefixPattern {
|
||||
first: Arc::from(head.as_str()),
|
||||
rest,
|
||||
rest: rest.clone(),
|
||||
},
|
||||
decision,
|
||||
})
|
||||
|
||||
@@ -59,6 +59,7 @@ impl Evaluation {
|
||||
}
|
||||
}
|
||||
|
||||
/// Count how many rules match each provided example and error if any example is unmatched.
|
||||
pub(crate) fn validate_match_examples(rules: &[Rule], matches: &[Vec<String>]) -> Result<()> {
|
||||
let match_counts = rules.iter().fold(vec![0; matches.len()], |counts, rule| {
|
||||
counts
|
||||
@@ -71,10 +72,15 @@ pub(crate) fn validate_match_examples(rules: &[Rule], matches: &[Vec<String>]) -
|
||||
let unmatched_examples: Vec<String> = matches
|
||||
.iter()
|
||||
.zip(&match_counts)
|
||||
.filter(|(_, count)| **count == 0)
|
||||
.map(|(example, _)| {
|
||||
try_join(example.iter().map(String::as_str))
|
||||
.unwrap_or_else(|_| "unable to render example".to_string())
|
||||
.filter_map(|(example, count)| {
|
||||
if *count == 0 {
|
||||
Some(
|
||||
try_join(example.iter().map(String::as_str))
|
||||
.unwrap_or_else(|_| "unable to render example".to_string()),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
||||
@@ -139,6 +139,7 @@ impl Rule {
|
||||
}
|
||||
}
|
||||
|
||||
/// Return a boolean for each example indicating whether this rule matches it.
|
||||
pub fn validate_matches(&self, matches: &[Vec<String>]) -> Vec<bool> {
|
||||
match self {
|
||||
Self::Prefix(rule) => rule.validate_matches(matches),
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use codex_execpolicy2::Decision;
|
||||
use codex_execpolicy2::Error;
|
||||
use codex_execpolicy2::Evaluation;
|
||||
use codex_execpolicy2::PolicyParser;
|
||||
use codex_execpolicy2::Rule;
|
||||
|
||||
Reference in New Issue
Block a user