refactor: new caller from interfaces & new service from its option #883
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
A new
Service
struct has been introduced, which is responsible for handling the main logic. TheService
struct has two main methods:GetChatCompletions()
andGetInvoke()
that handle the main logic.The
CallerProvider
struct has been removed.The
Service
struct has an additional method calledLoadOrCreateCaller()
, which is responsible for managing the creation and caching of theCaller
instances.The
NewCaller
function, which is used to create a newCaller
instance, has a new parameter signature:func (source yomo.Source, reducer yomo.StreamFunction, md metadata.M, callTimeout time.Duration) *Caller
. This means that when creating aService
instance, you need to inject the way to create the source, reducer, and how to exchange metadata.To facilitate this, a new struct called
ServiceOption
has been defined. Theservice.LoadOrCreateCaller()
method will call theServiceOption.SourceBuilder()
,ServiceOption.ReducerBuilder()
,ServiceOption.MetadataExchanger()
and then use the returned values as the parameters for theNewCaller
function to create theCaller
instance.the
ServiceOption
struct:ServiceOptions
also allows you to modify the default logger, tracer, and the method to get the credential, among other configuration parameters.