cartertemm / AI-content-describer

NVDA add-on that provides descriptions for controls and images, powered by GPT4
GNU General Public License v2.0
43 stars 19 forks source link

Anthropic and LlamaCPP not caching #32

Open daniel-luper opened 1 week ago

daniel-luper commented 1 week ago

Hi! Love this project btw. I'm wanting to contribute, and while exploring the add-on I found this bug (maybe feature šŸ‘€?? I guess some people might want a unified cache across all models but it's not what I would expect).

Description

Root Cause

Possible Solution

To improve readability and cohesiveness while eliminating duplicate code, move the caching code out of the description services and into a new class (e.g. CachedDescriptionService). The new class is a DescriptionService that can wrap any other DescriptionService Y, and adds caching functionality to Y (see Decorator pattern).

Then, use separate files for seperate models instead of one unified cache across all models. This would have the added benefit of helping prevent the memory error in #26.


I can implement this and make a PR. What do you think? Do you have any questions?

cartertemm commented 1 week ago

Hey @daniel-luper,

Great catch, and your solution seems well thought out. I especially like the idea of a caching decorator for the sake of cleanliness. Ideally, the current cache would be preserved as a fallback so that users don't have to delete it upon upgrading to the new version. That said, I don't think it's mandatory based on the number of people using this feature.

Feel free to start working on this. If you'd like help along the way, don't hesitate to reach out!

daniel-luper commented 1 week ago

Thanks! I'll go ahead and get started on it.

daniel-luper commented 6 days ago

@cartertemm how would you recommend reading and writing logs? I tried using the logger from import logging and checked the %TMP%/nvda.log file, but my logs didn't get written. I already made sure to set the NVDA logging level from the General settings to "debug".

cartertemm commented 4 days ago

You can always use NVDA's logHandler, as such:

import logHandler

nvda_log = logHandler.log
nvda_log.info("Test msg")

HTH