Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: new caller from interfaces & new service from its option #883

Merged
merged 4 commits into from
Aug 16, 2024

Conversation

woorui
Copy link
Collaborator

@woorui woorui commented Aug 13, 2024

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:

// 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)
}
  1. Besides,ServiceOptions also allows you to modify the default logger, tracer, and the method to get the credential, among other configuration parameters.

@woorui woorui requested a review from venjiang August 13, 2024 08:48
@woorui woorui self-assigned this Aug 13, 2024
Copy link

vercel bot commented Aug 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
yomo ⬜️ Ignored (Inspect) Visit Preview Aug 16, 2024 7:51am

Copy link

codecov bot commented Aug 13, 2024

Codecov Report

Attention: Patch coverage is 79.32584% with 92 lines in your changes missing coverage. Please review.

Project coverage is 79.87%. Comparing base (f438306) to head (e71f4aa).
Report is 1 commits behind head on master.

Files Patch % Lines
pkg/bridge/ai/service.go 81.69% 43 Missing and 26 partials ⚠️
pkg/bridge/ai/api_server.go 54.54% 13 Missing and 2 partials ⚠️
pkg/bridge/ai/caller.go 77.14% 6 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #883      +/-   ##
==========================================
+ Coverage   79.15%   79.87%   +0.72%     
==========================================
  Files          48       49       +1     
  Lines        2835     2847      +12     
==========================================
+ Hits         2244     2274      +30     
+ Misses        437      409      -28     
- Partials      154      164      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@woorui woorui changed the title refactor: new caller from interfaces refactor: new caller from interfaces & new service from its option Aug 13, 2024
pkg/bridge/ai/service.go Outdated Show resolved Hide resolved
@woorui woorui requested a review from venjiang August 14, 2024 07:35
Copy link
Contributor

@venjiang venjiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@woorui woorui merged commit c68e252 into master Aug 16, 2024
7 checks passed
@woorui woorui deleted the refactor/service branch August 16, 2024 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants