Fixed GH-3526, Fixed the error in using the Builder in SystemPromptTemplate. #3529
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.
As mentioned in the issue, currently when using the
Builder
inSystemPromptTemplate
, it returns aBuilder
ofPromptTemplate
. This causes subsequent operations likecreateMessage
based on theBuilder
class to actually return aUserMessage
instead of aSystemMessage
.The key point is that
SystemPromptTemplate
inherits theBuilder
fromPromptTemplate
.I can think of two ways to address this problem, but in my opinion, neither is perfect:
Add a
Builder
inner class inSystemPromptTemplate
that extends theBuilder
class ofPromptTemplate
, and override all of its methods. However, this approach would require updating all subclasses'Builder
classes whenever any new properties are added toPromptTemplate
in the future.Make the
Builder
class ofPromptTemplate
generic and use the “Simulated Self-Type Idiom” so that each subclass can return its ownBuilder
type. However, this would involve significant changes to the currentBuilder
class ofPromptTemplate
, and all existing code that uses it would also need to support generics.Currently, I have adopted the first approach because it has a smaller impact scope compared to the second one.
This PR includes the following changes:
Builder
ofPromptTemplate
to support inheritance in theBuilder
ofSystemPromptTemplate
.Builder
forSystemPromptTemplate
.Fixes #3526