lib/matheus/q.rb in matheus-0.5.0 vs lib/matheus/q.rb in matheus-0.6.0
- old
+ new
@@ -13,11 +13,11 @@
def call(question)
question = question.join(" ")
existing_entry = search_question_in_history(question)
if existing_entry && use_existing_answer?
- answer = existing_entry['answer']
+ answer = existing_entry["answer"]
else
answer = ask_llm(question)
save_qa(question, answer)
end
@@ -53,19 +53,19 @@
OpenAI::Client.new(access_token: ENV.fetch("OPENAI_API_KEY"))
end
def save_qa(question, answer)
history = load_history
- history << { question:, answer:, timestamp: Time.now.to_s }
+ history << {question:, answer:, timestamp: Time.now.to_s}
File.write(QUESTION_HISTORY_FILE, JSON.pretty_generate(history))
end
def load_history
File.exist?(QUESTION_HISTORY_FILE) ? JSON.parse(File.read(QUESTION_HISTORY_FILE)) : []
end
def search_question_in_history(question)
- load_history.reverse.find { |entry| entry['question'].downcase.strip == question.downcase.strip }
+ load_history.reverse.find { |entry| entry["question"].downcase.strip == question.downcase.strip }
end
def use_existing_answer?
prompt = TTY::Prompt.new
prompt.yes?("An existing answer was found. Do you want to use it?") do |q|