-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Simplify the implementation of ChatClient-based interfaces #1663
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
base: main
Are you sure you want to change the base?
Conversation
Provide sensible defaults for overloaded methods in PromptUserSpec, PromptSystemSpec, AdvisorSpec, CallResponseSpec, ChatClientRequestSpec, and Builder interfaces. Closes spring-projects#1663
I'd like to keep the interfaces without any defaults as in WebClient and other spring projects. This PR also introduces a conflict in that the single implementation of the existing spec classes have different behavior it seems at first glance. I took a look at
vs.
What is wrong with using the string as supplied i the current impl? In anycase, these impls are used in one place, so if there are changes to make in the impl, i'd do it there and not default method interfaces. |
Thank you for the feedback @markpollack. Keeping the interfaces inside I tend to provide defaults when:
Regarding...
Nothing, other than using the given Any implementation is free to still override a default implementation, necessarily based on internal data structure, performance, or all sorts of reasons. But the key is, implementations do not need to override and explicitly implement every overloaded variant, keeping the implementations focused on the singular function rather than form. A lot of the methods in the Finally, Spring is an excellent example of the Open/Closed principle, and making the task of implementation by downstream frameworks, libraries or tooling in addition to an application's occasional need for extension simpler is generally a good thing. Food for thought. |
FYI, in the process of writing my book, I have thought of many extensions and areas for improvement in Spring AI, while considering all angles: libraries, frameworks, applications and tooling implementations. |
I should probably add that, in several cases, Spring AI does use default methods on interfaces. For example, In fact, this is quite common throughout Spring AI's codebase.
|
1 last comment... Declaring default methods in interfaces does not change the default implementations/behavior already provided by Spring AI in the DefaultXyz classes, for example, In particular, the So, this PR changes nothing, and only provides convenience. |
Provide sensible defaults for overloaded methods in
PromptUserSpec
,PromptSystemSpec
,AdvisorSpec
,CallResponseSpec
,ChatClientRequestSpec
, andBuilder
interfaces.