Add cache when translating to commands
This commit is contained in:
@@ -8,12 +8,16 @@ class Command::Ai::Translator
|
||||
end
|
||||
|
||||
def as_normalized_json(query)
|
||||
response = chat.ask query
|
||||
response = Rails.cache.fetch(cache_key_for(query)) { chat.ask query }
|
||||
Rails.logger.info "*** Commands: #{response.content}"
|
||||
compact JSON.parse(response.content)
|
||||
end
|
||||
|
||||
private
|
||||
def cache_key_for(query)
|
||||
"command_translator:#{user.id}:#{query}:#{context_description}"
|
||||
end
|
||||
|
||||
def chat
|
||||
chat = ::RubyLLM.chat
|
||||
chat.with_instructions(prompt)
|
||||
|
||||
Reference in New Issue
Block a user