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
BuilderinSystemPromptTemplate, it returns aBuilderofPromptTemplate. This causes subsequent operations likecreateMessagebased on theBuilderclass to actually return aUserMessageinstead of aSystemMessage.The key point is that
SystemPromptTemplateinherits theBuilderfromPromptTemplate.I can think of two ways to address this problem, but in my opinion, neither is perfect:
Add a
Builderinner class inSystemPromptTemplatethat extends theBuilderclass ofPromptTemplate, and override all of its methods. However, this approach would require updating all subclasses'Builderclasses whenever any new properties are added toPromptTemplatein the future.Make the
Builderclass ofPromptTemplategeneric and use the “Simulated Self-Type Idiom” so that each subclass can return its ownBuildertype. However, this would involve significant changes to the currentBuilderclass 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:
BuilderofPromptTemplateto support inheritance in theBuilderofSystemPromptTemplate.BuilderforSystemPromptTemplate.Fixes #3526