Module: JSON

Defined in:
lib/kaba/json.rb

Class Method Summary collapse

Class Method Details

.parse_llm_response(response_text) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/kaba/json.rb', line 3

def self.parse_llm_response(response_text)
  start_index = response_text.index('{')
  end_index = response_text.rindex('}')

  unless start_index && end_index && end_index > start_index
    raise "Invalid JSON response: #{response_text}"
  end

  json_text = response_text[start_index..end_index]
  JSON.parse JSON.repair(json_text)
end