Support caching of chat cogs
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 1.2k
- Forks
- 76
- PR merge metrics
- No merged PRs in 30d
Description
While developing a new workflow it is common to have to re-run it multiple times for testing.
Chat cogs result in both higher costs and slower iteration.
I'm currently using this short monkeypatch which can serve as example, but a real implementation would need to support sessions (and maybe other parameters I haven't considered) and should ideally be configurable per chat cog, instead of globally:
require 'digest'
module CachedChat
def execute(input)
cache_dir = '/tmp/roast_chat_cache'
chat_digest = Digest::SHA256.hexdigest(input.valid_prompt!)
cache_key = "#{config.valid_provider!}:#{config.valid_model}:#{chat_digest}"
cache_file = File.join(cache_dir, "chat_#{cache_key}.txt")
if File.exist?(cache_file)
cached_response = File.read(cache_file)
empty_session = Roast::Cogs::Chat::Session.new([])
return Roast::Cogs::Chat::Output.new(empty_session, cached_response)
end
result = super
FileUtils.mkdir_p(cache_dir)
File.write(cache_file, result.response)
result
end
end
Roast::Cogs::Chat.prepend(CachedChat)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names Roast::Cogs::Chat#execute and the Session, Output, and config objects used by the example; start there and trace how chat-cog inputs and results are represented. Define the supported cache inputs and per-cog configuration, including session behavior, then verify that repeated workflow runs reuse valid responses without breaking chat results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- ai
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100