Class: Ace::Review::Molecules::LlmExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/review/molecules/llm_executor.rb

Overview

Executes LLM queries for code reviews using Ruby API

Constant Summary collapse

PROMPT_SIZE_WARNING_RATIO =

Warning ratio: warn when estimated tokens exceed 80% of model context limit

0.8

Instance Method Summary collapse

Constructor Details

#initializeLlmExecutor

Returns a new instance of LlmExecutor.



13
14
15
# File 'lib/ace/review/molecules/llm_executor.rb', line 13

def initialize
  @default_model = Ace::Review.get("defaults", "model") || "google:gemini-2.5-flash"
end

Instance Method Details

#execute(system_prompt:, user_prompt:, session_dir:, model: nil, output_file: nil, timeout: nil) ⇒ Hash

Execute an LLM query using Ruby API

Parameters:

  • system_prompt (String)

    system prompt

  • user_prompt (String)

    user prompt

  • model (String) (defaults to: nil)

    the model to use

  • session_dir (String)

    the session directory for output

  • output_file (String, nil) (defaults to: nil)

    optional custom output file path

Returns:

  • (Hash)

    result with success, response, output_file, metadata, and error keys



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
# File 'lib/ace/review/molecules/llm_executor.rb', line 24

def execute(system_prompt:, user_prompt:, session_dir:, model: nil, output_file: nil, timeout: nil)
  model ||= @default_model

  # Warn if prompt is large
  warn_if_prompt_large(system_prompt, user_prompt, model)

  # Check if ace-llm Ruby API is available
  unless ruby_api_available?
    return {
      success: false,
      response: nil,
      error: "ace-llm Ruby API not available. Please install ace-llm gem or use --dry-run"
    }
  end

  # Use Ruby API directly for v0.13.0 architecture
  execute_with_ruby_api(
    system_prompt,
    user_prompt,
    model,
    session_dir,
    output_file,
    timeout
  )
rescue => e
  {
    success: false,
    response: nil,
    error: "LLM execution failed: #{e.message}"
  }
end