Skip to content

Доступ к id загруженных файлов + Исправление сохранения внутренних сообщений Spring AI в ChatResponseMetadata #19

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

Merged
merged 4 commits into from
Jun 20, 2025

Conversation

linarkou
Copy link
Collaborator

@linarkou linarkou commented Jun 20, 2025

linarkou added 2 commits June 19, 2025 23:48
…ледующего доступа к ним

Signed-off-by: Linar Abzaltdinov <abzaltdinov@gmail.com>
* Исправление сохранения внутренних сообзений Spring AI в ChatResponseMetadata

Signed-off-by: Linar Abzaltdinov <abzaltdinov@gmail.com>
@linarkou linarkou requested a review from a-simeshin June 20, 2025 09:48
@linarkou linarkou self-assigned this Jun 20, 2025
Signed-off-by: Linar Abzaltdinov <abzaltdinov@gmail.com>
*/
private List<Message> uploadMedia(List<Message> messages) {
return messages.stream()
.map(message -> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Смотрится страшненько, может вынесем в отдельный метод?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

исправил

return messages.stream()
.map(message -> {
if (message instanceof UserMessage userMessage
&& !CollectionUtils.isEmpty(userMessage.getMedia())) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

 Предлагаю разбить на два условия сразу с выходом return message;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

исправил

.map(message -> {
if (message instanceof UserMessage userMessage
&& !CollectionUtils.isEmpty(userMessage.getMedia())) {
var mediaWithIds = userMessage.getMedia().stream()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Также предлагаю вынести в отдельный метод

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

исправил


List<Message> messages = prompt.getInstructions();

// ищем индекс последнего пользовательского сообщения, т.к. здесь могут быть сообщения из ChatMemory
Copy link
Collaborator

Choose a reason for hiding this comment

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

Также лучше вынести в отдельный метод логику поиска и последнего сообщения также с условием типизации под UserMessage, так как ниже есть оптимистичный каст под него, что не очень хорошо

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

логику могу вынести, ок - но результатам метода будет индекс, int.
мне в одном месте нужен индекс, а в другом уже объект UserMessage, от каста не избавлюсь

Signed-off-by: Linar Abzaltdinov <abzaltdinov@gmail.com>
@linarkou linarkou merged commit f50bef5 into main Jun 20, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants