Skip to content

GH-3426 Fix Spring AI Advisor documentation #3428

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hyeonZIP
Copy link

@hyeonZIP hyeonZIP commented Jun 3, 2025

Fixes GH-3426 (#3426)

  • Fix outdated method names discovered while following documentation examples
  • Remove references to unsupported methods in current version
  • Update code examples to match current API implementation
  • Additional corrections needed for deprecated methods in updated API

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

  • Sign the contributor license agreement
  • 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

Fixes spring-projectsGH-3426 (spring-projects#3426)

* Fix outdated method names discovered while following documentation examples
* Remove references to unsupported methods in current version
* Update code examples to match current API implementation
* Additional corrections needed for deprecated methods in updated API

Signed-off-by: hyeonZIP <[email protected]>
@hyeonZIP
Copy link
Author

hyeonZIP commented Jun 3, 2025

deprecated methods in examples

in Logging Advisor

	@Override
	public Flux<AdvisedResponse> aroundStream(AdvisedRequest advisedRequest, StreamAroundAdvisorChain chain) {

		logger.debug("BEFORE: {}", advisedRequest);

		Flux<AdvisedResponse> advisedResponses = chain.nextAroundStream(advisedRequest);

        // aggregateAdvisedResponse() is deprecated
        return new MessageAggregator().aggregateAdvisedResponse(advisedResponses,
                    advisedResponse -> logger.debug("AFTER: {}", advisedResponse)); 
	}

Re-Reading (Re2) Advisor

public class ReReadingAdvisor implements CallAroundAdvisor, StreamAroundAdvisor {


	private AdvisedRequest before(AdvisedRequest advisedRequest) { 
               
                // advisedRequest.userParams() is deprecated
                // also, chatClientRequest.userParams() is not existing.
		Map<String, Object> advisedUserParams = new HashMap<>(advisedRequest.userParams());
		advisedUserParams.put("re2_input_query", advisedRequest.userText());

		return AdvisedRequest.from(advisedRequest)
			.userText("""
			    {re2_input_query}
			    Read the question again: {re2_input_query}
			    """)
			.userParams(advisedUserParams)
			.build();
	}

	@Override
	public AdvisedResponse aroundCall(AdvisedRequest advisedRequest, CallAroundAdvisorChain chain) { 
		return chain.nextAroundCall(this.before(advisedRequest));
	}

	@Override
	public Flux<AdvisedResponse> aroundStream(AdvisedRequest advisedRequest, StreamAroundAdvisorChain chain) { 
		return chain.nextAroundStream(this.before(advisedRequest));
	}

	@Override
	public int getOrder() { 
		return 0;
	}

    @Override
    public String getName() { 
		return this.getClass().getSimpleName();
	}
}


return Mono.just(advisedRequest)
return Mono.just(chatClientRequest)
Copy link
Contributor

@dev-jonghoonpark dev-jonghoonpark Jun 3, 2025

Choose a reason for hiding this comment

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

There are two spaces between return and Mono.


return new MessageAggregator().aggregateAdvisedResponse(advisedResponses,
advisedResponse -> logger.debug("AFTER: {}", advisedResponse)); // <3>
return new MessageAggregator().aggregate(chatClientResponses,
Copy link
Contributor

Choose a reason for hiding this comment

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

The indentation is incorrect.

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.

Missing Documentation for Removal of CallAroundAdvisor and StreamAroundAdvisor in v1.0.0-RC1
2 participants