Skip to content

Conversation

@ericbottard
Copy link
Member

Thank you for taking time to contribute this pull request!
You might have already read the contributor guide, but as a reminder, please make sure to:

  • Add a Signed-off-by line to each commit (git commit -s) per the DCO
  • Rebase your changes on the latest main branch and squash your commits
  • Add/Update unit tests as needed
  • Run a build and make sure all tests pass prior to submission

For more details, please check the contributor guide.
Thank you upfront!

Signed-off-by: Eric Bottard <eric.bottard@broadcom.com>
Copy link
Contributor

@sdeleuze sdeleuze left a comment

Choose a reason for hiding this comment

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

Mostly good, just a few things to refine from my POV.

See https://jspecify.dev/docs/user-guide/#declaring-generics for my comments about generic types.

public ChatResponse(List<Generation> generations, ChatResponseMetadata chatResponseMetadata) {
this.chatResponseMetadata = chatResponseMetadata;
Assert.notNull(generations, "'generations' must not be null");
this.chatResponseMetadata = Objects.requireNonNullElse(chatResponseMetadata, new ChatResponseMetadata());
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it a defensive check because we want to be lenient if chatResponseMetadata is forced to null?

return List.of();
}

if (!StringUtils.hasText(context.getResponse().getResult().getOutput().getText())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please share more details about why this check can be safely removed?


targetMap.putAll(sourceMap.entrySet()
.stream()
.filter(e -> e.getValue() != null)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we kept a similar defensive filtering in a previous PR, is this one fine to remove?

}

var nullableAnnotation = parameter.getAnnotation(Nullable.class);
var nullableAnnotation = parameter.getAnnotation(org.springframework.lang.Nullable.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

Here you should probably use org.springframework.core.Nullness that I have introduced for this kind of use case.


@Override
public String apply(String template, Map<String, Object> variables) {
public String apply(String template, Map<String, @Nullable Object> variables) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably be Map<String, ? extends @Nullable Object> to allow both Map<String, @Nullable Object> and Map<String, Object> (flexible nullability).


@Override
public String apply(String template, Map<String, Object> variables) {
public String apply(String template, Map<String, @Nullable Object> variables) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably be Map<String, ? extends @Nullable Object> to allow both Map<String, @Nullable Object> and Map<String, Object> (flexible nullability).

* @since 1.0.0
*/
public interface TemplateRenderer extends BiFunction<String, Map<String, Object>, String> {
public interface TemplateRenderer extends BiFunction<String, Map<String, @Nullable Object>, String> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably be Map<String, ? extends @Nullable Object> to allow both Map<String, @Nullable Object> and Map<String, Object> (flexible nullability).

Same below.

@SuppressWarnings("unchecked")
public static BiFunction<?, ToolContext, ?> wrapKotlinBiFunction(Object bean) {
return (t, u) -> ((Function2<Object, ToolContext, Object>) bean).invoke(t, u);
public static BiFunction<?, @Nullable ToolContext, ?> wrapKotlinBiFunction(Object bean) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably be ? extends @Nullable ToolContext (flexible nullability).

Same below and above.

private final Type toolInputType;

private final BiFunction<I, ToolContext, O> toolFunction;
private final BiFunction<I, @Nullable ToolContext, O> toolFunction;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably be ? extends @Nullable ToolContext (flexible nullability).

Same below.

private @Nullable ToolMetadata toolMetadata;

private BiFunction<I, ToolContext, O> toolFunction;
private final BiFunction<I, @Nullable ToolContext, O> toolFunction;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably be ? extends @Nullable ToolContext (flexible nullability).

Same below.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants