Class: Collavre::AiClient

Inherits:
Object
  • Object
show all
Defined in:
app/services/collavre/ai_client.rb

Constant Summary collapse

SYSTEM_INSTRUCTIONS =
<<~PROMPT.freeze
  You are a senior expert teammate. Respond:
  - Be concise and focus on the essentials (avoid unnecessary verbosity).
  - Use short bullet points only when helpful.
  - State only what you're confident about; briefly note any uncertainty.
  - Respond in the asker's language (prefer the latest user message). Keep code and error messages in their original form.
PROMPT
BASE_VENDOR_OPTIONS =

Vendor option ([label, value]).

  • .registered_vendor_options ⇒ Object
  • .session_vendors ⇒ Object

    Vendors that use stateful/incremental sessions.

  • .vendor_options ⇒ Object
  • .vendor_supports_session?(vendor) ⇒ Boolean
  • Instance Method Summary collapse

    Constructor Details

    #initialize(vendor:, model:, system_prompt:, llm_api_key: nil, gateway_url: nil, context: {}, log_interactions: true) ⇒ AiClient

    log_interactions: persist each call to ActivityLog. Default true. Pass false for ephemeral, high-frequency calls on text the user has not submitted (e.g. inline typo correction on debounced typing) so private drafts are never written to server-side activity logs.

    
    
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    # File 'app/services/collavre/ai_client.rb', line 60
    
    def initialize(vendor:, model:, system_prompt:, llm_api_key: nil, gateway_url: nil, context: {}, log_interactions: true)
      @vendor = vendor
      @model = model
      @system_prompt = system_prompt
      @llm_api_key = llm_api_key
      @gateway_url = gateway_url
      @context = context
      @log_interactions = log_interactions
      @last_input_tokens = 0
      @last_output_tokens = 0
    end

    Instance Attribute Details

    #last_input_tokensObject (readonly)

    Returns the value of attribute last_input_tokens.

    
    
    11
    12
    13
    # File 'app/services/collavre/ai_client.rb', line 11
    
    def last_input_tokens
      @last_input_tokens
    end

    #last_output_tokensObject (readonly)

    Returns the value of attribute last_output_tokens.

    
    
    11
    12
    13
    # File 'app/services/collavre/ai_client.rb', line 11
    
    def last_output_tokens
      @last_output_tokens
    end

    Class Method Details

    .register_session_vendor(vendor) ⇒ Object

    
    
    47
    48
    49
    # File 'app/services/collavre/ai_client.rb', line 47
    
    def register_session_vendor(vendor)
      session_vendors << vendor.to_s.downcase
    end

    .register_vendor_option(label, value) ⇒ Object

    Append a vendor