You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
0 commit comments