Please do a quick search on GitHub issues first, there might be already a duplicate issue for the one you are about to create. If the bug is trivial, just go ahead and create the issue. Otherwise, please take a few moments and fill in the following sections:

Bug description Spring-ai OpenAiChatModel NullPointerException Spring-ai OpenAiChatModel NullPointerException org.springframework.ai.openai.OpenAiChatModel#stream

when roleMap is Empty throw NullPointerException

Comment From: devholic22

@chj9 I think it can be solve by ternary operator, and if roleMap has a key with id, we can put that value in it, and if not, we can save null. What do you think? If you think this is right, it would be nice for me to do it.

Comment From: chj9

@chj9 I think it can be solve by ternary operator, and if roleMap has a key with id, we can put that value in it, and if not, we can save null. What do you think? If you think this is right, it would be nice for me to do it.

yes, of course,but if you still use the Map.of function method can not save null ,this is my code inherited from the OpenAiChatModel class to make changes, and now it is running fine Spring-ai OpenAiChatModel NullPointerException

Comment From: devholic22

@chj9 thank you for sharing your code. Additionally, it looks like from Java 8 you can write getOrDefault on the Map interface. How about this?

Map.of("id", id, "role", roleMap.getOrDefault(id, ""), "finishReason", finish));

Comment From: devholic22

@chj9 thank you for sharing your code. Additionally, it looks like from Java 8 you can write getOrDefault on the Map interface. How about this?

java Map.of("id", id, "role", roleMap.getOrDefault(id, ""), "finishReason", finish));

if you agree, I'll make PR for fix this issue.

Comment From: chj9

Agreed. Very good

@chj9 thank you for sharing your code. Additionally, it looks like from Java 8 you can write getOrDefault on the Map interface. How about this? java Map.of("id", id, "role", roleMap.getOrDefault(id, ""), "finishReason", finish));

if you agree, I'll make PR for fix this issue.

agreed. very good!

Comment From: tzolov

@chj9 thank you for catching this issue