fix: ensure unique instances for each Service subclass using Map
Previously, the Service base class used a single static instance, which caused all subclasses to share the same instance. This update replaces the static instance with a Map to manage unique instances for each subclass
Many of the services load up models and such and we probably only want one instance, ever, enforcing the singleton pattern, if we add a map won't we have several instances of each class? That's why I made it this service pattern.
Many of the services load up models and such and we probably only want one instance, ever, enforcing the singleton pattern, if we add a map won't we have several instances of each class? That's why I made it this service pattern.
I understand, but in the context of the Discord bot, we require two services: ISpeechService and ITranscriptionService. (Also, there are IVideoService and IBrowserService, but I'm not sure if these are necessary for the bot.) Would you prefer that I implement separate methods and instance variables for each of these services, or would you prefer a different approach? Let me know how you'd like to proceed :)
I want one class of each service shared across all running agents, imagine we are running 10 agents, we want them to share the transcription service
I agree with @lalalune we should close this PR as the singleton pattern would work best in this usecase.
I agree with @lalalune we should close this PR as the singleton pattern would work best in this usecase.
@monilpat thanks for the review but from my understanding, the current implementation ensures that each service type has its own singleton instance. This means only one instance of each subclass is created and reused. Could you clarify if the intent is different?
I agree with @lalalune we should close this PR as the singleton pattern would work best in this usecase.
@monilpat thanks for the review but from my understanding, the current implementation ensures that each service type has its own singleton instance. This means only one instance of each subclass is created and reused. Could you clarify if the intent is different?
Yeah of course anytime! The intent is not different. I just share @lalalune 's concern around multiple instances of service rather than a 1-> many from service -> agents. Happy to add more context, but will defer @lalalune as he has more context!