-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: new caller from interfaces & new service from its option (#883
) # Description 1. A new `Service` struct has been introduced, which is responsible for handling the main logic. The `Service` struct has two main methods: `GetChatCompletions()` and `GetInvoke()` that handle the main logic. 2. The `CallerProvider` struct has been removed. 3. The `Service` struct has an additional method called `LoadOrCreateCaller()`, which is responsible for managing the creation and caching of the `Caller` instances. 4. The `NewCaller` function, which is used to create a new `Caller` 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 a `Service` 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. The `service.LoadOrCreateCaller()` method will call the `ServiceOption.SourceBuilder()`, `ServiceOption.ReducerBuilder()`, `ServiceOption.MetadataExchanger() ` and then use the returned values as the parameters for the `NewCaller` function to create the `Caller` instance. the `ServiceOption` struct: ```go // ServiceOptions is the option for creating service type ServiceOptions struct { // Logger is the logger for the service Logger *slog.Logger // Tracer is the tracer for the service Tracer trace.Tracer // CredentialFunc is the function for getting the credential from the request CredentialFunc func(r *http.Request) (string, error) // CallerCacheSize is the size of the caller's cache CallerCacheSize int // CallerCacheTTL is the time to live of the callers cache CallerCacheTTL time.Duration // CallerCallTimeout is the timeout for awaiting the function response. CallerCallTimeout time.Duration // SourceBuilder should builds an unconnected source. SourceBuilder func(zipperAddr, credential string) yomo.Source // ReducerBuilder should builds an unconnected reducer. ReducerBuilder func(zipperAddr, credential string) yomo.StreamFunction // MetadataExchanger exchanges metadata from the credential. MetadataExchanger func(credential string) (metadata.M, error) } ``` 5. Besides,`ServiceOptions` also allows you to modify the default logger, tracer, and the method to get the credential, among other configuration parameters.
- Loading branch information
Showing
8 changed files
with
1,288 additions
and
1,228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.