eliza icon indicating copy to clipboard operation
eliza copied to clipboard

fix: ensure unique instances for each Service subclass using Map

Open tcm390 opened this issue 1 year ago • 3 comments

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

tcm390 avatar Nov 15 '24 17:11 tcm390

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.

lalalune avatar Nov 15 '24 21:11 lalalune

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 :)

tcm390 avatar Nov 15 '24 21:11 tcm390

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

lalalune avatar Nov 15 '24 23:11 lalalune

I agree with @lalalune we should close this PR as the singleton pattern would work best in this usecase.

monilpat avatar Nov 18 '24 23:11 monilpat

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?

tcm390 avatar Nov 18 '24 23:11 tcm390

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!

monilpat avatar Nov 19 '24 00:11 monilpat