Class: Raif::Evals::CliJudges::Base
- Includes:
- Concerns::Llms::NativeJsonResponseValidation
- Defined in:
- app/models/raif/evals/cli_judges/base.rb
Overview
An LLM judge that runs through a coding-agent CLI the developer has signed in locally, rather than a provider API key. Registered only when Raif.config.evals_cli_judges_enabled is set.
Each call is one fresh, single-turn CLI process with no tools, run in an empty temporary directory so no project instructions, settings or hooks are picked up.
Defined Under Namespace
Classes: Result
Constant Summary collapse
- STRIPPED_ENV =
Provider keys would make a CLI bill an API account instead of using its own login, and the variables of a Claude Code session that starts an eval run would make the child join it.
/ \A(ANTHROPIC_|OPENAI_|XAI_|CODEX_API_KEY\z|GH_|GITHUB_|BUNDLE_|RUBYOPT\z|RUBYLIB\z| CLAUDECODE\z|CLAUDE_PID\z|CLAUDE_EFFORT\z|CLAUDE_CODE_)| (SECRET|TOKEN|PASSWORD|API_KEY|CREDENTIAL) /xi
Constants inherited from Llm
Llm::UNSENT_TEMPERATURE_WARNINGS, Llm::VALID_RESPONSE_FORMATS
Class Attribute Summary collapse
-
.version_checked ⇒ Object
Returns the value of attribute version_checked.
Attributes inherited from Llm
#api_name, #batch_max_completion_tokens, #capabilities, #default_max_completion_tokens, #default_temperature, #deprecated, #display_name, #input_token_cost, #key, #lifecycle, #migration_note, #non_streaming_max_completion_tokens, #output_token_cost, #pricing, #provider_settings, #replacement_key, #retirement_date, #supported_provider_managed_tools, #supports_native_tool_use
Class Method Summary collapse
- .eval_judge_only? ⇒ Boolean
- .executable ⇒ Object
-
.kept_env ⇒ Object
Variables STRIPPED_ENV would remove that this CLI needs, such as a login token.
- .llm_configs ⇒ Object
- .minimum_version ⇒ Object
-
.models ⇒ Object
Each entry is a model config for Raif.register_llm, plus the effort the CLI is run at.
- .reset_version_check! ⇒ Object
Instance Method Summary collapse
-
#format_messages(messages) ⇒ Object
Plain strings only: a judge sends text, and image or file inputs have no CLI equivalent here.
- #perform_model_completion!(model_completion) ⇒ Object
Methods inherited from Llm
#accepts_reasoning_effort?, #added_on, batch_inference_cost_multiplier, #build_forced_tool_choice, #build_pending_model_completion, #build_required_tool_choice, cache_creation_input_token_cost_multiplier, cache_read_input_token_cost_multiplier, #chat, #deprecated?, #deprecated_on, deprecation_details, #deprecation_message, #initialize, #lifecycle_status, #name, #pending_model_completion_attributes, prompt_tokens_include_cached_tokens?, #reasoning_effort_levels, #streaming_supported?, streaming_supported_for_key?, supports_batch_inference?, #supports_batch_inference?, #supports_encrypted_reasoning?, #supports_faithful_required_tool_choice?, #supports_forced_tool_choice?, #supports_parallel_tool_calls?, #supports_provider_managed_tool?, supports_reasoning_effort?, #supports_required_tool_choice?, #supports_strict_structured_outputs?, #supports_structured_outputs?, #supports_temperature?, valid_response_formats, #validate_provider_managed_tool_support!, #validate_tool_choice_support!
Constructor Details
This class inherits a constructor from Raif::Llm
Class Attribute Details
.version_checked ⇒ Object
Returns the value of attribute version_checked.
51 52 53 |
# File 'app/models/raif/evals/cli_judges/base.rb', line 51 def version_checked @version_checked end |
Class Method Details
.eval_judge_only? ⇒ Boolean
29 30 31 |
# File 'app/models/raif/evals/cli_judges/base.rb', line 29 def eval_judge_only? true end |
.executable ⇒ Object
38 39 40 |
# File 'app/models/raif/evals/cli_judges/base.rb', line 38 def executable raise NotImplementedError, "#{name} must define .executable" end |
.kept_env ⇒ Object
Variables STRIPPED_ENV would remove that this CLI needs, such as a login token.
47 48 49 |
# File 'app/models/raif/evals/cli_judges/base.rb', line 47 def kept_env [] end |
.llm_configs ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/models/raif/evals/cli_judges/base.rb', line 53 def llm_configs models.map do |model| { key: model.fetch(:key), api_name: model.fetch(:api_name), display_name: model.fetch(:display_name), input_token_cost: 0, output_token_cost: 0, supports_native_tool_use: false, model_provider_settings: { supports_temperature: false, effort: model.fetch(:effort) } } end end |
.minimum_version ⇒ Object
42 43 44 |
# File 'app/models/raif/evals/cli_judges/base.rb', line 42 def minimum_version raise NotImplementedError, "#{name} must define .minimum_version" end |
.models ⇒ Object
Each entry is a model config for Raif.register_llm, plus the effort the CLI is run at.
34 35 36 |
# File 'app/models/raif/evals/cli_judges/base.rb', line 34 def models raise NotImplementedError, "#{name} must define .models" end |
.reset_version_check! ⇒ Object
67 68 69 |
# File 'app/models/raif/evals/cli_judges/base.rb', line 67 def reset_version_check! self.version_checked = false end |
Instance Method Details
#format_messages(messages) ⇒ Object
Plain strings only: a judge sends text, and image or file inputs have no CLI equivalent here.
109 110 111 112 113 114 115 116 117 118 |
# File 'app/models/raif/evals/cli_judges/base.rb', line 109 def () .map do || content = ["content"] || [:content] unless content.is_a?(String) raise Raif::Errors::UnsupportedFeatureError, "#{key} accepts text message content only" end { "role" => (["role"] || [:role]).to_s, "content" => content } end end |
#perform_model_completion!(model_completion) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'app/models/raif/evals/cli_judges/base.rb', line 72 def perform_model_completion!(model_completion) unless model_completion.source.is_a?(Raif::Evals::LlmJudge) raise Raif::Errors::CliJudgeSourceError, "#{key} only serves Raif::Evals::LlmJudge tasks, not #{model_completion.source_type || "a call with no source"}" end schema = model_completion.json_response_schema unless model_completion.response_format_json? && schema.present? raise Raif::Errors::CliJudgeSourceError, "#{key} needs a JSON response format with a response schema" end result = Dir.mktmpdir("raif-cli-judge") do |dir| check_version!(dir) perform_cli_call(prompt: prompt_from(model_completion), system_prompt: model_completion.system_prompt.to_s, schema:, dir:) end unless result.data.is_a?(Hash) raise Raif::Errors::CliJudgeFailedError, "#{self.class.executable} returned no structured output" end model_completion.raw_response = JSON.generate(result.data) model_completion.response_finish_reason = "stop" model_completion.prompt_tokens = result.prompt_tokens model_completion.completion_tokens = result.completion_tokens model_completion.cache_read_input_tokens = result.cache_read_input_tokens model_completion.cache_creation_input_tokens = result.cache_creation_input_tokens # The CLIs take no temperature, so the judge's requested one was never sent. model_completion.temperature = nil if result.prompt_tokens || result.completion_tokens model_completion.total_tokens = result.prompt_tokens.to_i + result.completion_tokens.to_i end model_completion.save! validate_native_json_response!(model_completion) model_completion end |