Class: Sage::ReportProcessor

Inherits:
Object
  • Object
show all
Includes:
ActionView::RecordIdentifier
Defined in:
lib/sage/report_processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query:, prompt:, stream_target_id:) ⇒ ReportProcessor

Returns a new instance of ReportProcessor.



11
12
13
14
15
# File 'lib/sage/report_processor.rb', line 11

def initialize(query:, prompt:, stream_target_id:)
  @query = query
  @prompt = prompt
  @stream_target_id = stream_target_id
end

Instance Attribute Details

#promptObject (readonly)

Returns the value of attribute prompt.



9
10
11
# File 'lib/sage/report_processor.rb', line 9

def prompt
  @prompt
end

#queryObject (readonly)

Returns the value of attribute query.



9
10
11
# File 'lib/sage/report_processor.rb', line 9

def query
  @query
end

#raw_response_contentObject (readonly)

Returns the value of attribute raw_response_content.



9
10
11
# File 'lib/sage/report_processor.rb', line 9

def raw_response_content
  @raw_response_content
end

#stream_target_idObject (readonly)

Returns the value of attribute stream_target_id.



9
10
11
# File 'lib/sage/report_processor.rb', line 9

def stream_target_id
  @stream_target_id
end

Instance Method Details

#database_schema_contextObject



35
36
37
# File 'lib/sage/report_processor.rb', line 35

def database_schema_context
  Sage::DatabaseSchemaContext.new.build_context
end

#model_scopes_contextObject



39
40
41
# File 'lib/sage/report_processor.rb', line 39

def model_scopes_context
  Sage::ModelScopesContext.new.build_context
end

#processObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sage/report_processor.rb', line 17

def process
  response = generate_llm_response
  Rails.logger.info "LLM Response: #{response.inspect}"
  Rails.logger.info "LLM Response content: #{response.content.inspect}"
  @raw_response_content = response.content
  parsed_response = parse_response(response)
  Rails.logger.info "Parsed response: #{parsed_response.inspect}"

  {
    summary: parsed_response[:summary],
    sql: parsed_response[:sql]
  }
end

#system_promptObject



31
32
33
# File 'lib/sage/report_processor.rb', line 31

def system_prompt
  build_system_prompt
end